opencv: Python bindings: ORB is broken
Following code fails:
import cv2
img = cv2.imread('some_image.jpg')
orb = cv2.ORB_create(nfeatures=5000)
ps, descs = orb.detectAndCompute(img, None)
Error output:
OpenCV Error: Assertion failed (The data should normally be NULL!) in allocate, file /home/polarnick/coding/forks/opencv_3.1/modules/python/src2/cv2.cpp, line 163
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-4-03ae3bc0ea38> in <module>()
----> 1 ps, descs = orb.detectAndCompute(img, None)
error: /home/polarnick/coding/forks/opencv_3.1/modules/python/src2/cv2.cpp:163: error: (-215) The data should normally be NULL! in function allocate
Environment: Python 3.4, Ubuntu
Affects master and 3.1.0.
Workaround: if passing cv2.UMat(img)
(see https://github.com/Itseez/opencv/pull/6078) - everything works
Can I pull-request this test case?
UPD:
The better workaround is cv2.ocl.setUseOpenCL(False)
before ORB execution
The bug was introduced in commit 190d00ea3e46feedd38a7417c0a5ab08b900a56b (Pull request: https://github.com/Itseez/opencv/pull/5317)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (8 by maintainers)
As a temporary working stop-gap till the UMat / T-API issue is resolved, just disabling OpenCL support in run-time works for me: cv2.ocl.setUseOpenCL(False)
Same problem with OpenCV 3.1, Python 2.7, Windows 10. This seems to be a general problem with the Python bindings. I have seen other chatter on the internet about a similar type of error message when using Python, but unrelated to usage of ORB.
In the IPython console I get:
I followed tzickel’s suggestion (above). I added the following line of code to the top of my script and it fixed the problem.
@Rajashalini , It’s ‘oc1’ not ‘ocl’ . Replace ‘L’ by ‘ONE’ 1 .
hi. im very new to image processing. When i execute the below line,
cv2.ocl.setUseOpenCL(False)
it shows ‘module’ object has no attribute ‘ocl’ . could anyone please help me…thank you…
Ok, what happens here (when OpenCL is enabled), the code flow is:
Now someone who understands UMat and Python bindings should figure out how to fix this 😃
iirc #6078 is supposed to fix this issues.