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:
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 || scn == 4 in function cvtColor
imagefile
before theimread
? Your glob call could return files of the formsstextpng
. Probably best to make itss*.png
and retest. – Martin Evans