我已经在Raspberry-Pi模块上实现了这段代码,以便从文件夹中读取png图像并将其转换为灰色,代码如下:
x = glob.glob("/home/pi/pngimages/ss*png")
for imagefile in x[0300:0302]:
img = cv2.imread(imagefile)
gray = cvt.cvtColor(img,cv2.COLOR_BGR2GRAY)但我得到以下错误:
帧错误:在函数中断言失败(scn /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp,3 || scn == 4),文件OpenCV行3205回溯(最近一次调用):文件格式为灰色=cv2.cvtColor( ==,cv2.COLOR_BGR2GRAY) cv2。错误: /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp:3739:错误:(-215) scn cvtColor 3 || scn == 4 in function cvtColor
发布于 2015-07-24 10:13:45
通常,如果图像为None,则会出现此断言。请先尝试检查图像是否被正确读取。
x = glob.glob("/home/pi/pngimages/ss*png")
for imagefile in x[0300:0302]:
img = cv2.imread(imagefile)
# You can do a print img.shape here if you want to see what's going on
# If it returns NULL, something's wrong with your image or the path or something else
if img:
gray = cvt.cvtColor(img,cv2.COLOR_BGR2GRAY)如果您发现由于img为None而没有执行任何操作,请检查您的目录并检查它是否正在查找正确的图像
https://stackoverflow.com/questions/31600859
复制相似问题