Face recognition segmentation fault
pirakleous opened this issue · 8 comments
Hello i use this code to run the face recognition with nodejs and display img in a window and i get a segmentation fault. If i remove the line with m.detectObject (no detection) and show the img then is ok.
var cv = require('opencv');
// camera properties
var camWidth = 320;
var camHeight = 240;
var camFps = 30;
var camInterval = 100 / camFps;
var window = new cv.NamedWindow('Video', 0)
// face detection properties
var rectColor = [0, 255, 0];
var rectThickness = 2;
// initialize camera
var camera = new cv.VideoCapture(0);
camera.setWidth(camWidth);
camera.setHeight(camHeight);
setInterval(function() {
camera.read(function(err, im) {
if (err) console.log(err);
im.detectObject('./node_modules/opencv/data/haarcascade_frontalface_alt2.xml', {}, function(err, faces) {
if (err) console.log(err);
if (im.size()[0] > 0 && im.size()[1] > 0){
window.show(im);
}
window.blockingWaitKey(0, 50);
});
});
}, camInterval);
can you paste in the error you're getting?
Hi,
I'm getting this error too when using the PngStream from ar-drone. The err message in my case is
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/opencv/src/opencv-3.1.0/modules/core/src/array.cpp, line 2494
[1] 31285 segmentation fault (core dumped) npm start
I also get segmentation faults often when streaming from h264 sources.
I'm 99% certain that the reason for the segfault is not h264. I'm now convinced that it is the thread safety of detectMultiscale
. Looking at this issue I'm sure that the function (the CascadeClassifier
object in fact) is not thread safe.
What happens to me is that the rate of incoming frames is too fast for the face detection to keep up, causing multiple calls to the asynchronized wrapper of detectMultiscale
and eventually causing an access violation within OpenCV.
I'm observing the same issue and I'm not using h264. I use image.detectObject(cv.FACE_CASCADE) on images for doing smart crops and given a few hours and decent load the process will segfault (in libopencv_objdetect.so). I'll try to serialize all detectObject calls to see if this helps.
i get Segmentation fault (core dumped)
. Opencv 2.4.9, and 2.4.13 do this.
my sample code is
process.on('uncaughtException', function (err) {
console.error('uncaughtException',err);
});
var fs = require('fs');
var spawn = require('child_process').spawn;
var cv=require('opencv');
var ffmpeg = spawn('ffmpeg',('-loglevel warning -i /dev/video0 -f singlejpeg pipe:1').replace(/\s+/g,' ').trim().split(' '));
ffmpeg.stderr.on('data',function(d){
console.log('FFMPEG',d.toString('utf8'))
})
ffmpeg.stdout.on('data',function(d){
console.log(d.length)
if(d.length>3000){
cv.readImage(d,function(err,im){
// console.log(im)
if(err){return console.log(err)}
const width = im.width();
const height = im.height();
if (width < 1 || height < 1) {
throw new Error('Image has no size');
}
im.detectObject('../node_modules/opencv/data/haarcascade_frontalface_alt2.xml', {}, function(err, faces){
if(err){return false;}
if(faces){
for (var i=0;i<faces.length; i++){
var x = faces[i];
console.log(x)
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
}
fs.writeFile('out'+new Date().getTime()+'.jpg',im.toBuffer(),function(){
});
}
});
})
}
})
EDIT:
it turns out i can stop the error from happening if i set the video feed to 1 fps.
Hi,
Im also getting the segmentation fault while trying to do cap.read((err, frame) => {});
I do that in intervals of 40ms.
Can anybody tell me if the issue is because of above mentioned similar case?