Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp numpy numpy

Python-OpenCV cv2 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ..\..\..\modules\imgproc\src\color.cpp


It says your input image should have 3 or 4 channels before applying the function cv2.cvtColor.

so check your image shape before applying the function by print im.shape. if the result is None type (most of the times, this is the problem), your image is not loaded correctly, most probably because your path is not correct.

The point is that your image should have 3 dimensions, rows, columns and depth.


If you are getting this error on a raspberry PI with PI camera, try running this command first:

sudo modprobe bcm2835-v4l2


1st print ret.If it is showing false then your image is not taken properly.If it is showing True Try this command - sudo modprobe bcm2835-v4l2Or in your /etc/modules file add bcm2835-v4l2 at the bottom.