简体   繁体   English

opencv,python和RaspberryPi

[英]opencv, python and RaspberryPi

I have implemented this code on Raspberry-Pi module to read png images from a folder and convert it to gray, the code is as follows: 我已经在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)

but I get the following error: 但我收到以下错误:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp, line 3205 Traceback (most recent call last): File in gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.error: /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || OpenCV错误:在cvtColor,文件/home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp,第3205行回溯中,断言失败(scn == 3 || scn == 4) ):灰色文件= cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)cv2.error:/home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp:3739:error:(-215)scn == 3 || scn == 4 in function cvtColor scn == 4在函数cvtColor中

Generally this assertion happens if the image is None . 通常,如果图像为None则会发生此断言。 Try checking the image is being read properly first. 尝试先检查图像是否正确读取。

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)

If you find it doesn't do anything because img is None , check your directory and check that it's looking for the correct images 如果您发现它由于img为None ,请检查您的目录并检查它是否在寻找正确的图像

Have a look here as well: Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\\..\\..\\modules\\imgproc\\src\\color.cpp 也可以在这里查看: Python-OpenCV cv2 OpenCV错误:在未知函数,文件.. \\ .. \\ .. \\ modules \\ imgproc \\ src \\ color中,断言失败(scn == 3 || scn == 4)。 CPP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM