Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackgroundSubtractorMOG2 apply calls from python causes allocation error #6055

Open
anthonyk91 opened this issue Feb 3, 2016 · 11 comments
Open

Comments

@anthonyk91
Copy link

Error message:

  File "(myfile.py)", line 1500, in (some function)
    bgsub.apply(frame)
error: /tmp/opencv-3.1.0/modules/python/src2/cv2.cpp:163: error: (-215) The data should normally be NULL! in function allocate

This appears to be a similar bug as #5667 for knnMatch, however the fix for that bug doesn't apply here

The bug seems to be related to an allocate call. It seems to be avoided for python3 and some people just disable the warning link, however it would be better to identify the problem (eg for python 2) and prevent it occurring.

@patricksnape
Copy link
Contributor

Please provide a short script using the data shipped with OpenCV that replicates your error so that it can be debugged.

@anthonyk91
Copy link
Author

The following code produces the error on my system:

Python 2.7.5 (default, Jul 10 2014, 16:10:08) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2

import cv2
vc = cv2.VideoCapture("768x576.avi")
bgsegm = cv2.createBackgroundSubtractorMOG2()
r,f = vc.read()
bgsegm.apply(f)

OpenCV Error: Assertion failed (The data should normally be NULL!) in allocate, file /tmp/opencv-3.1.0/modules/python/src2/cv2.cpp, line 163
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: /tmp/opencv-3.1.0/modules/python/src2/cv2.cpp:163: error: (-215) The data should normally be NULL! in function allocate

I'm running it on CentOS 6, when I run it on a separate CentOS 7 system the error isn't produced. (The CentOS 7 system is also using python 2.7.5, with GCC 4.8.5 (i'm not sure if this is used)). The error first appeared after changing to OpenCV-3.1 and does not occur with OpenCV-3.0.0 (with either system).

@patricksnape
Copy link
Contributor

I can't replicate this error on my Ubuntu, Windows or OSX machines for either Python 2.7.11 or 3.5. Did you compile OpenCV 3.1 yourself?

@anatolix
Copy link
Contributor

anatolix commented Feb 7, 2016

I have same error. I compiled opencv 3.1 myself, OSX, Python 3.5. cmake output attached.
cmake.txt

@patricksnape
Copy link
Contributor

Thanks @anatolix your cmake helped a lot - it seems like the issue is related to OpenCL support. I can't replicate the error with OpenCL off, but with OpenCL on I get a segmentation fault (on OSX). Given the other error I fixed, I feel like it has to do with this line, which I'm guessing should be looking for a UMat in the case of OpenCV support.

@anthonyk91
Copy link
Author

I can confirm that after editing CMakeCache.txt to set WITH_OPENCL.. flags to OFF and rebuilding, the error disappears.

@bw4sz
Copy link

bw4sz commented Feb 18, 2016

Same error here. Python 2.7, most recent opencv windows (10) binary. Anyway to get around this without recompiling with cmake? Just want to check before i head down that road. I can't comment out a line (other offered solution) without recompiling, correct? Would going to python 3 and redownloading latest opencv windows binary be worth a shot?

@patricksnape
Copy link
Contributor

@bw4sz Seems like binaries compiled with OpenCL support are broken - so if the latest Windows binaries have OpenCL support you will still see this error (it is independent of Python version it seems).

@Dikay900
Copy link
Contributor

No you have to build OpenCV yourself since all releases are built with OPENCL ON in favor of the T-API.
There is currently no support for the T-API in python at all as far as i know.
Maybe we will see T-API support in the near future but for now this is the way to go for the python bindings.
edit: rather use workaround below #6055 (comment)

@bw4sz
Copy link

bw4sz commented Feb 20, 2016

Confirming building from source worked. Thanks.

@PolarNick239
Copy link
Contributor

The simpler workaround that could work is to disable OpenCL in runtime by cv2.ocl.setUseOpenCL(False) (#6081 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants