cgf
cgf

Reputation: 3509

Failed to load OpenCL runtime in OpenCV for Python

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?

Upvotes: 4

Views: 12713

Answers (3)

ClessA
ClessA

Reputation: 25

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

Upvotes: 2

a-Jays
a-Jays

Reputation: 1212

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.

Upvotes: 14

Abid Rahman K
Abid Rahman K

Reputation: 52646

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.

Upvotes: 1

Related Questions