Ask Your Question

Trying to detect faces in linux, done it in windows

asked 2013-03-05 05:44:36 -0500

lovelf gravatar image

updated 2013-03-05 06:33:51 -0500

I am trying to detect faces in still photos. I am using the following which gets to compile, using Open CV 2.2.0 installed from a rpm for Cent OS.

What I get is

Failed to initialize libdc1394 Segmentation fault

I read that libdc1394 has to do with it not initializing the camera or something similar and that it can be ignored, this is holding in a server therefore it won't initialize the server's camera.

But segmentation fault does not allow me to execute the code like it should. Right now the code below doesn't print in a way that php can access it, I have that functioning with C++ for Windows but it's been running on a project on localhost for sometime now and I want to host it online but for that I need to have opencv working with Linux.

Segmentation fault could come from any "stupid" error the below code might have but I'm just not very much proficient with c or c++.


#include <stdio.h>
 #include "cv.h"
 #include "highgui.h"
 #include "cvaux.h"
 CvHaarClassifierCascade *cascade;
 CvMemStorage            *storage;
 char *face_cascade="/usr/include/opencv/haarcascade_frontalface_default.xml";

 void detectFacialFeatures( IplImage *img,IplImage *temp_img)
 char image[100],msg[100],temp_image[100];
 float m[6];
 double factor = 1;
 CvMat M = cvMat( 2, 3, CV_32F, m );
 int w = (img)->width;
 int h = (img)->height;
 CvSeq* faces;
 CvRect *r;
 m[0] = (float)(factor*cos(0.0));
 m[1] = (float)(factor*sin(0.0));
 m[2] = w*0.5f;
 m[3] = -m[1];
 m[4] = m[0];
 m[5] = h*0.5f;
 cvGetQuadrangleSubPix(img, temp_img, &M);
 CvMemStorage* storage=cvCreateMemStorage(0);
 cvClearMemStorage( storage );
 if( cascade )
 faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));
 printf("\nFrontal face cascade not loaded\n");
 printf("\n no of faces detected are %d",faces->total);
 int i=0;
 r = ( CvRect* )cvGetSeqElem( faces, i );
 cvRectangle( img,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),
 CV_RGB( 255, 0, 0 ), 1, 8, 0 );    
 printf("\n face_x=%d face_y=%d wd=%d ht=%d",r->x,r->y,r->width,r->height);
 cvSaveImage( image, img ,0);

 int main( int argc, char *argv[])
 char *dea;
 char *image;

 IplImage  *img,*temp_img;
 int       key;
 storage = cvCreateMemStorage( 0 );
 cascade = ( CvHaarClassifierCascade* )cvLoad( face_cascade, 0, 0, 0 );
 if( !(cascade) )
 fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
 return -1;
 printf("Could not load image file and trying once again: %s\n",image);
 printf("\n curr_image = %s",image);
 cvReleaseHaarClassifierCascade( &cascade );
 cvReleaseMemStorage( &storage );
 return 0;

the segmentation fault comes in this line:

faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));
edit retag flag offensive close merge delete



It would be better if you could run it with a debugger and print the whole traceback of the error. Also indentation would make this much more readable...

awknaust gravatar imageawknaust ( 2013-03-05 08:16:58 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-05 13:19:18 -0500

xaffeine gravatar image

It's hard to tell what's wrong, since you are not trying to do any camera capture. If you don't mind building your own OpenCV libraries, one workaround would be to build without dc1394 support. Alternatively, you could avoid linking your application with highgui.

edit flag offensive delete link more

Question Tools


Asked: 2013-03-05 05:44:36 -0500

Seen: 425 times

Last updated: Mar 05 '13