node-opencv
node-opencv copied to clipboard
OpenCV Error: Null pointer (Hidden cascade has not been created. Use cvSetImagesForHaarClassifierCascade)
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
I get this when running
cv = require 'opencv'
buf = (some png buffer)
cv.readImage buf, (err, im) ->
return cb err if err?
im.detectObject "./haarcascade_frontalface_alt.xml", {}, (err, faces) ->
return cb err if err?
return cb null, faces
I'm trying to repro this - can you try running temp.js in the test directory in the issue-20 branch? This seems to work for me - not sure if there's issues with your opencv install?
I forgot to elaborate - this only happens when running that code a bunch of times. I have roughly 5-10 PNG video frames per second coming in that I'm running the code on and after a few seconds of it that error will get thrown. You might want to add a dummy dataset to loop over for a while
Is there any way you can get me the buffer it fails on? Or failing that, can you show me some of your code?
Looks like this is the error, but without a repro it's hard to debug:
https://code.ros.org/trac/opencv/browser/trunk/opencv/src/cv/cvhaar.cpp?rev=3009#L672
Test: https://github.com/Contra/drone/blob/master/test.coffee
Running it will output
(more data for a few seconds)
[ { x: 6, y: 328, width: 90, height: 90 },
{ x: 444, y: 116, width: 233, height: 233 } ]
[ { x: 3, y: 326, width: 94, height: 94 },
{ x: 439, y: 109, width: 240, height: 240 } ]
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
[ { x: 3, y: 328, width: 92, height: 92 },
{ x: 756, y: 111, width: 148, height: 148 },
{ x: 442, y: 114, width: 232, height: 232 } ]
libc++abi.dylib: libc++abi.dylib: libc++abi.dylib: terminate called throwing an exceptionterminate called throwing an exceptionterminate called throwing an exception
Abort trap: 6
The image buffers are also coming from the opencv lib (capturing the webcam via VideoCapture) - I wrapped it in a module to expose it as a stream
OSX 10.8 - OpenCV 2.4.2 installed using brew
might be related: I found using detectObject() to be quite unstable. I ended up creating the face cascade once, and then use readImage and cascade.detectMultiScale for every new image: hackish example This gave me no more errors.
Switching to new cv.CascadeClassifier(path).detectMultiScale bring up some new issues
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/core/src/array.cpp, line 2482
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/imgproc/src/color.cpp, line 3256
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
These errors only seem to happen when I process an image every process.nextTick - If i do it via setTimeout every 100ms it doesn't happen
This is awesome, thanks, I'm on vacation this week, but I'll try and get this fixed next week.
Sent from my iPhone
On Oct 31, 2012, at 7:23 AM, Eric Schoffstall [email protected] wrote:
Switching to new cv.CascadeClassifier(path).detectMultiScale bring up some new issues
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/core/src/array.cpp, line 2482 libc++abi.dylib: terminate called throwing an exception Abort trap: 6 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/imgproc/src/color.cpp, line 3256 libc++abi.dylib: terminate called throwing an exception Abort trap: 6 — Reply to this email directly or view it on GitHub.
So this is weird - I'm running your code and it's working fine. Hmm. I'm guessing there's a race condition somewhere in the loading of the haar cascade file. This is actually being run by opencv, so there's no way for us to guard against it being loaded concurrently.
This would explain why creating a single classifier and detecting from it multiple times still works.
I'm still kind of shooting in the dark here. Not sure the best way to attack this.
Is there a way to detect when the file is done loading if they do it in parallel? I don't see how it would be that because the first few seconds of frames work unless the file is being loaded each time then that makes sense but in that case just stop it from loading each time
I think I may have fixed this, but without a solid unit test it's hard to know for sure - can you confirm if this is fixed in master?
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
OpenCV Error: Unspecified error (header of the stage classifier #0 is invalid (has null pointers or non-positive classfier count)) in icvCreateHidHaarClassifierCascade, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 219
libc++abi.dylib: libc++abi.dylib: terminate called throwing an exceptionterminate called throwing an exception
On most recent npm
OpenCV Error: Null pointer (Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-pKns/OpenCV-2.4.2/modules/objdetect/src/haar.cpp, line 671
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
On master
var express = require("express"),
http = require("http"),
url = require("url"),
app = express(),
server = http.createServer(app);
server.listen(8000);
var cv = require('opencv');
app.get('/feed', function(request, response){
var camera = new cv.VideoCapture(0);
setInterval(function() {
camera.read(function(im) {
im.detectObject("./haarcascade_frontalface_alt.xml", {}, function(err, faces){
for (var i=0;i<faces.length; i++){
var x = faces[i];
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
}
var newBuffer = im.toBuffer();
response.write('--daboundary\nContent-Type: image/png\nContent-length: ' + newBuffer.length + '\n\n');
response.write(newBuffer);
});
});
}, 10);
});
Here this should reproduce this error.
I can confirm we're getting this error as well. It looks like there's a synchronization issue, which we're going to investigate further.
Yeah, this is a totally valid, but hard to fix bug. My hunch is that it's a race condition or some corruption in the haard cascade.
Some people have got success by replacing the image.detectObject with
"new cv.CascadeClassifier(path).detectMultiScale"
I'm still working on this, but it's a hard one.
Also seeing this issue occasionally. It has been hard to track down and provide a repeatable scenario. We are processing images coming from a work queue and have 5 to 20 workers consuming the queue. At random times workers will die with this error. If we run only a single worker everything is very stable. Happy to try and provide more debugging info but not quite sure where to start.
Did anybody solve this issue? Experiencing it when running via Docker on GKE.
OpenCV Error: Bad argument (Invalid cascade pointer) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-2.4.11/modules/objdetect/src/haar.cpp, line 838 OpenCV Error: Bad argument (Invalid cascade pointer) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-2.4.11/modules/objdetect/src/haar.cpp, line 838 OpenCV Error: Null pointer (Hidden cascade has not been created. Use cvSetImagesForHaarClassifierCascade) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-2.4.11/modules/objdetect/src/haar.cpp, line 843 OpenCV Error: Bad argument (Invalid cascade pointer) in cvRunHaarClassifierCascadeSum, file /tmp/opencv-2.4.11/modules/objdetect/src/haar.cpp, line 838 terminate called after throwing an instance of 'tbb::captured_exception' what(): /tmp/opencv-2.4.11/modules/objdetect/src/haar.cpp:838: error: (-5) Invalid cascade pointer in function cvRunHaarClassifierCascadeSum
I get a similar issue.
Use cvSetImagesForHaarClassifierCascade in function cvRunHaarClassifierCascadeSum
terminating with uncaught exception of type cv::Exception: /tmp/opencv-20161020-7399-1yrk4nm/opencv-2.4.13.1/modules/objdetect/src/haar.cpp:843: error: (-27) Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade in function cvRunHaarClassifierCascadeSum
terminating with uncaught exception of type cv::Exception: /tmp/opencv-20161020-7399-1yrk4nm/opencv-2.4.13.1/modules/objdetect/src/haar.cpp:843: error: (-27) Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade in function cvRunHaarClassifierCascadeSum
terminating with uncaught exception of type cv::Exception: /tmp/opencv-20161020-7399-1yrk4nm/opencv-2.4.13.1/modules/objdetect/src/haar.cpp:843: error: (-27) Hidden cascade has not been created.
Use cvSetImagesForHaarClassifierCascade in function cvRunHaarClassifierCascadeSum