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

Face recognition segmentation fault #415

Closed
pirakleous opened this issue May 31, 2016 · 8 comments
Closed

Face recognition segmentation fault #415

pirakleous opened this issue May 31, 2016 · 8 comments

Comments

@pirakleous
Copy link

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);

@acinader
Copy link

can you paste in the error you're getting?

@JanKoppe
Copy link

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

@Climax777
Copy link

I also get segmentation faults often when streaming from h264 sources.

@Climax777
Copy link

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.

@jwagner
Copy link
Contributor

jwagner commented Sep 16, 2016

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.

@moeiscool
Copy link

moeiscool commented Feb 2, 2017

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.

@WebMaestroFr
Copy link

I think that #156, #159 and #223 are about the same problem.

It seems that .detectObject( can only be run once at a time, and that the problem comes from OpenCv itself.

@komalpharate
Copy link

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?

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

No branches or pull requests

8 participants