I am trying to run the first example here, but I am getting this error. I am using Ubuntu 13.10.
Failed to load OpenCL runtime
OpenCV Error: Unknown error code -220 (OpenCL function is not available: [clGetPlatformIDs]) in opencl_check_fn, file /home/cristi/opencv/modules/core/src/opencl/runtime/opencl_core.cpp, line 204
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/cristi/opencv/modules/imgproc/src/color.cpp, line 3159
Traceback (most recent call last):
File "/home/cristi/opencv1/src/video.py", line 11, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/cristi/opencv/modules/imgproc/src/color.cpp:3159: error: (-215) scn == 3 || scn == 4 in function cvtColor
Process finished with exit code 1
Also, this is the line that is causing the trouble (line 11 in my code):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
What should I do?
3 Answers 3
As for the OpenCL failure, try installing required packages:
sudo apt-get install ocl-icd-opencl-dev
Worked for me. My guess is that OCL is a part of the opencv_core module, and if it failed to initialise, then many other components might behave strange.
2 Comments
cvtColor() of the sort mentioned in the OP.You might want to install/update the driver: http://streamcomputing.eu/blog/2011-12-29/opencl-hardware-support/
Updating the driver help to solve my problem with OpenCL
Comments
Failed to load OpenCL runtime
Most probably there is some problem with your installation. If you are not working with GPU, then I recommend you to turn off all CUDA/OpenCL modules in OpenCV during compilation.
error: (-215) scn == 3 || scn == 4 in function cvtColor
This error says your input image should have 3 channel (BGR/color image) or 4 channel(RGBA image). So please check number of channels in frame by executing print frame.shape.
Since you are working with video, there is a high chance that your camera is not opened for capture, so that frame is not captured. In that case, print frame.shape will say it is NoneType data.
I recommend you to run the same code with an image instead of video. Even then if the error of OpenCL shows up, it is most likely a problem with your installation. If it works fine, problem may be with VideoCapture. You can check it as mentioned in the same tutorial:
Sometimes, cap may not have initialized the capture. In that case, this code shows error. You can check whether it is initialized or not by the method cap.isOpened(). If it is True, OK.
4 Comments
NoneType, what should I do next? However, the error in my original post happens with a video as well, not just when my laptop's camera is involved. Just mentioning it in case it is relevant.print cap.isOpened() ? If it is False, it means your are OpenCV cannot initialize your camera. You may need to check your installation.print cv2.getBuildInformation() in pastebin.com and provide the link here, please?