Python ModuleNotFoundError:没有名为';预处理器&x27;
执行程序时出现模块未找到错误Python ModuleNotFoundError:没有名为';预处理器&x27;,python,python-3.x,Python,Python 3.x,执行程序时出现模块未找到错误 import numpy as np import cv2 from preprocessors import x_cord_contour, makeSquare, resize_to_pixel 我很确定你正在学习Rajeev D的深度学习课程。我进一步猜测你没有按照视频中的建议下载VM映像 在自定义模块中定义了功能x\u cord\u contour、makeSquare和resize\u to\u pixel。如果您在没有虚拟机的情况下学习本课程,只需将下
import numpy as np
import cv2
from preprocessors import x_cord_contour, makeSquare, resize_to_pixel
我很确定你正在学习Rajeev D的深度学习课程。我进一步猜测你没有按照视频中的建议下载VM映像 在自定义模块中定义了功能
x\u cord\u contour
、makeSquare
和resize\u to\u pixel
。如果您在没有虚拟机的情况下学习本课程,只需将下面的函数复制并粘贴到代码中,然后删除import语句
import numpy as np
import cv2
def x_cord_contour(contour):
# This function take a contour from findContours
# it then outputs the x centroid coordinates
M = cv2.moments(contour)
return (int(M['m10']/M['m00']))
def makeSquare(not_square):
# This function takes an image and makes the dimenions square
# It adds black pixels as the padding where needed
BLACK = [0,0,0]
img_dim = not_square.shape
height = img_dim[0]
width = img_dim[1]
#print("Height = ", height, "Width = ", width)
if (height == width):
square = not_square
return square
else:
doublesize = cv2.resize(not_square,(2*width, 2*height), interpolation = cv2.INTER_CUBIC)
height = height * 2
width = width * 2
#print("New Height = ", height, "New Width = ", width)
if (height > width):
pad = int((height - width)/2)
#print("Padding = ", pad)
doublesize_square = cv2.copyMakeBorder(doublesize,0,0,pad,pad,cv2.BORDER_CONSTANT,value=BLACK)
else:
pad = (width - height)/2
#print("Padding = ", pad)
doublesize_square = cv2.copyMakeBorder(doublesize,pad,pad,0,0,\
cv2.BORDER_CONSTANT,value=BLACK)
doublesize_square_dim = doublesize_square.shape
#print("Sq Height = ", doublesize_square_dim[0], "Sq Width = ", doublesize_square_dim[1])
return doublesize_square
def resize_to_pixel(dimensions, image):
# This function then re-sizes an image to the specificied dimenions
buffer_pix = 4
dimensions = dimensions - buffer_pix
squared = image
r = float(dimensions) / squared.shape[1]
dim = (dimensions, int(squared.shape[0] * r))
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
img_dim2 = resized.shape
height_r = img_dim2[0]
width_r = img_dim2[1]
BLACK = [0,0,0]
if (height_r > width_r):
resized = cv2.copyMakeBorder(resized,0,0,0,1,cv2.BORDER_CONSTANT,value=BLACK)
if (height_r < width_r):
resized = cv2.copyMakeBorder(resized,1,0,0,0,cv2.BORDER_CONSTANT,value=BLACK)
p = 2
ReSizedImg = cv2.copyMakeBorder(resized,p,p,p,p,cv2.BORDER_CONSTANT,value=BLACK)
img_dim = ReSizedImg.shape
height = img_dim[0]
width = img_dim[1]
#print("Padded Height = ", height, "Width = ", width)
return ReSizedImg
将numpy导入为np
进口cv2
def x_线缆_轮廓(轮廓):
#此函数从findContours获取轮廓
#然后输出x形心坐标
M=cv2.力矩(轮廓)
返回值(int(M['m10']/M['m00']))
def makeSquare(非_square):
#此函数用于拍摄图像,并使二维数为正方形
#它在需要的地方添加黑色像素作为填充
黑色=[0,0,0]
img\u dim=非方形形状
高度=仪表组尺寸[0]
宽度=img_尺寸[1]
#打印(“Height=,Height,”,Width=,Width)
如果(高度=宽度):
正方形=非正方形
返回广场
其他:
doublesize=cv2.调整大小(非正方形,(2*宽度,2*高度),插值=cv2.内部立方)
高度=高度*2
宽度=宽度*2
#打印(“新高度=”,高度,“新宽度=”,宽度)
如果(高度>宽度):
pad=int((高度-宽度)/2)
#打印(“Padding=”,pad)
doublesize_square=cv2.copyMakeBorder(doublesize,0,0,pad,pad,cv2.BORDER_常量,值=黑色)
其他:
焊盘=(宽度-高度)/2
#打印(“Padding=”,pad)
doublesize_square=cv2.copyMakeBorder(doublesize,pad,pad,0,0\
cv2.边界(U常数,值=黑色)
doublesize\u square\u dim=doublesize\u square.shape
#打印(“Sq-Height=,doublesize\u-square\u-dim[0],“Sq-Width=,doublesize\u-square\u-dim[1])
返回双尺寸方格
def将大小调整为像素(尺寸、图像):
#然后,此函数将图像的大小重新调整为特定的尺寸
缓冲区_pix=4
尺寸=尺寸-缓冲区
平方=图像
r=浮动(尺寸)/平方形状[1]
尺寸=(尺寸,整数(平方形状[0]*r))
调整大小=cv2.调整大小(图像、尺寸、插值=cv2.内部区域)
img_dim2=已调整大小的.shape
高度=img\U dim2[0]
宽度=img\U dim2[1]
黑色=[0,0,0]
如果(高度>宽度):
调整大小=cv2.copyMakeBorder(调整大小,0,0,1,cv2.BORDER_常量,值=黑色)
如果(高度<宽度):
resized=cv2.copyMakeBorder(已调整大小,1,0,0,cv2.BORDER_常量,值=黑色)
p=2
ReSizedImg=cv2.copyMakeBorder(已调整大小,p,p,p,p,cv2.BORDER_常量,值=黑色)
img_dim=尺寸dimg.shape
高度=仪表组尺寸[0]
宽度=img_尺寸[1]
#打印(“填充高度=,高度,,”宽度=,宽度)
返回ReSizedImg
我很确定您正在学习Rajeev D的深度学习课程。我进一步猜测您没有按照视频中的建议下载VM映像
在自定义模块中定义了功能x\u cord\u contour
、makeSquare
和resize\u to\u pixel
。如果您在没有虚拟机的情况下学习本课程,只需将下面的函数复制并粘贴到代码中,然后删除import语句
import numpy as np
import cv2
def x_cord_contour(contour):
# This function take a contour from findContours
# it then outputs the x centroid coordinates
M = cv2.moments(contour)
return (int(M['m10']/M['m00']))
def makeSquare(not_square):
# This function takes an image and makes the dimenions square
# It adds black pixels as the padding where needed
BLACK = [0,0,0]
img_dim = not_square.shape
height = img_dim[0]
width = img_dim[1]
#print("Height = ", height, "Width = ", width)
if (height == width):
square = not_square
return square
else:
doublesize = cv2.resize(not_square,(2*width, 2*height), interpolation = cv2.INTER_CUBIC)
height = height * 2
width = width * 2
#print("New Height = ", height, "New Width = ", width)
if (height > width):
pad = int((height - width)/2)
#print("Padding = ", pad)
doublesize_square = cv2.copyMakeBorder(doublesize,0,0,pad,pad,cv2.BORDER_CONSTANT,value=BLACK)
else:
pad = (width - height)/2
#print("Padding = ", pad)
doublesize_square = cv2.copyMakeBorder(doublesize,pad,pad,0,0,\
cv2.BORDER_CONSTANT,value=BLACK)
doublesize_square_dim = doublesize_square.shape
#print("Sq Height = ", doublesize_square_dim[0], "Sq Width = ", doublesize_square_dim[1])
return doublesize_square
def resize_to_pixel(dimensions, image):
# This function then re-sizes an image to the specificied dimenions
buffer_pix = 4
dimensions = dimensions - buffer_pix
squared = image
r = float(dimensions) / squared.shape[1]
dim = (dimensions, int(squared.shape[0] * r))
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
img_dim2 = resized.shape
height_r = img_dim2[0]
width_r = img_dim2[1]
BLACK = [0,0,0]
if (height_r > width_r):
resized = cv2.copyMakeBorder(resized,0,0,0,1,cv2.BORDER_CONSTANT,value=BLACK)
if (height_r < width_r):
resized = cv2.copyMakeBorder(resized,1,0,0,0,cv2.BORDER_CONSTANT,value=BLACK)
p = 2
ReSizedImg = cv2.copyMakeBorder(resized,p,p,p,p,cv2.BORDER_CONSTANT,value=BLACK)
img_dim = ReSizedImg.shape
height = img_dim[0]
width = img_dim[1]
#print("Padded Height = ", height, "Width = ", width)
return ReSizedImg
将numpy导入为np
进口cv2
def x_线缆_轮廓(轮廓):
#此函数从findContours获取轮廓
#然后输出x形心坐标
M=cv2.力矩(轮廓)
返回值(int(M['m10']/M['m00']))
def makeSquare(非_square):
#此函数用于拍摄图像,并使二维数为正方形
#它在需要的地方添加黑色像素作为填充
黑色=[0,0,0]
img\u dim=非方形形状
高度=仪表组尺寸[0]
宽度=img_尺寸[1]
#打印(“Height=,Height,”,Width=,Width)
如果(高度=宽度):
正方形=非正方形
返回广场
其他:
doublesize=cv2.调整大小(非正方形,(2*宽度,2*高度),插值=cv2.内部立方)
高度=高度*2
宽度=宽度*2
#打印(“新高度=”,高度,“新宽度=”,宽度)
如果(高度>宽度):
pad=int((高度-宽度)/2)
#打印(“Padding=”,pad)
doublesize_square=cv2.copyMakeBorder(doublesize,0,0,pad,pad,cv2.BORDER_常量,值=黑色)
其他:
焊盘=(宽度-高度)/2
#打印(“Padding=”,pad)
doublesize_square=cv2.copyMakeBorder(doublesize,pad,pad,0,0\
cv2.边界(U常数,值=黑色)
doublesize\u square\u dim=doublesize\u square.shape
#打印(“Sq-Height=,doublesize\u-square\u-dim[0],“Sq-Width=,doublesize\u-square\u-dim[1])
返回双尺寸方格
def将大小调整为像素(尺寸、图像):
#然后,此函数将图像的大小重新调整为特定的尺寸
缓冲区_pix=4
尺寸=尺寸-缓冲区
平方=图像
r=浮动(尺寸)/平方形状[1]
尺寸=(尺寸,整数(平方形状[0]*r))
调整大小=cv2.调整大小(图像、尺寸、插值=cv2.内部区域)
img_dim2=已调整大小的.shape
高度=img\U dim2[0]
宽度=img\U dim2[1]
黑色=[0,0,0]
如果(高度>宽度):
调整大小=cv2.copyMakeBorder(调整大小,0,0,1,cv2.BORDER_常量,值=黑色)
如果(高度<宽度):
resized=cv2.copyMakeBorder(已调整大小,1,0,0,cv2.BORDER_常量,值=黑色)
p=2
ReSizedImg=cv2.copyMakeBorder(已调整大小,p,p,p,p,cv2.BORDER_常量,值=黑色)
img_dim=尺寸dimg.shape
高度=仪表组尺寸[0]
宽度=img_尺寸[1]
#打印(“填充高度=,高度,,”宽度=,宽度)
返回ReSizedImg
什么是预处理器
?你认为它为什么会存在?你认为它是预处理器吗