# Revision history [back]

### Trying to detect faces in linux, done it in windows

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++.

Thanks

#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include "cvaux.h"
CvMemStorage            *storage;

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;
CvMemStorage* storage=cvCreateMemStorage(0);
cvClearMemStorage( storage );
faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));
else
printf("\n no of faces detected are %d",faces->total);
int i=0;
while(i<faces->total)
{
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);
cvResetImageROI(img);
i++;
}
if(faces->total>0)
{
sprintf(image,"face_output%d.jpg");
cvSaveImage( image, img ,0);
}
}

int main( int argc, char *argv[])
{
char *dea;
char *image;
char *temp_img;
dea=argv[1];
printf("%c",argv[1]);
image=argv[1];
IplImage  *img,*temp_img;
int       key;
storage = cvCreateMemStorage( 0 );
{
return -1;
}
sprintf("%c",argv[1]);
if(!img)
{
printf("Could not load image file and trying once again: %s\n",image);
}
printf("\n curr_image = %s",image);
detectFacialFeatures(img,temp_img);
cvReleaseMemStorage( &storage );
cvReleaseImage(&img);
cvReleaseImage(&temp_img);
return 0;
}


### Trying to detect faces in linux, done it in windows

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++.

Thanks

#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include "cvaux.h"
CvMemStorage            *storage;

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;
CvMemStorage* storage=cvCreateMemStorage(0);
cvClearMemStorage( storage );
faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));
else
printf("\n no of faces detected are %d",faces->total);
int i=0;
while(i<faces->total)
{
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);
cvResetImageROI(img);
i++;
}
if(faces->total>0)
{
sprintf(image,"face_output%d.jpg");
cvSaveImage( image, img ,0);
}
}

int main( int argc, char *argv[])
{
char *dea;
char *image;
char *temp_img;
dea=argv[1];
printf("%c",argv[1]);
image=argv[1];
IplImage  *img,*temp_img;
int       key;
storage = cvCreateMemStorage( 0 );
{
return -1;
}
sprintf("%c",argv[1]);
if(!img)
{
printf("Could not load image file and trying once again: %s\n",image);
}
printf("\n curr_image = %s",image);
detectFacialFeatures(img,temp_img);

faces = cvHaarDetectObjects(img,cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));