Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

FaceDetection Using OpenCv-3.0.0-alpha

I am using Visual Studio 2012 with Open Cv-3.0.0 alpha. I want to detect faces from Image in MFC dialog based application. Code I am Using Is:- void CFaceDetectionDlg::OnBnClickedOk() {

  CvHaarClassifierCascade* cascade;
  CvMemStorage* storage;
  IplImage *image;
  CvSeq* faces;
  const char* file_name;
  int i;

CFileDialog dlg(TRUE, _T(".bmp"), NULL, OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,_T("image files (.bmp; .jpg) |.bmp;.jpg|All Files (.)|.*||"),NULL); dlg.m_ofn.lpstrTitle= _T("Open Image"); if (dlg.DoModal() == IDOK) {

CString path= dlg.GetPathName();
CStringA filename(path);
storage=cvCreateMemStorage(0);

cvFirstType();
file_name="E:/OpenCv/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml"; cascade = (CvHaarClassifierCascade*)cvLoad(file_name,NULL, NULL, NULL);

image = cvLoadImage(filename, 1 );

faces=cvHaarDetectObjects( image, cascade, storage, 1.1, 1,CV_HAAR_DO_CANNY_PRUNING,cvSize(10, 10));

//draw rectangles

for(i=0;i<(faces ? faces->total:0); i++ ) { CvRect* r; r = (CvRect*)cvGetSeqElem( faces, i ); CvPoint pt1= cvPoint (r->x, r->y) ; CvPoint pt2 = cvPoint (r->x + r->width, r->y + r->height) ;

cvRectangle( image, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 ); } // create window and show the image with outlined faces cvNamedWindow("faces", 1 ); cvShowImage( "faces", image ); cvSaveImage("Result.bmp", image);

 cvWaitKey();
 cvReleaseImage( &image );      // after a key pressed, release data
 cvReleaseHaarClassifierCascade( &cascade );
 cvReleaseMemStorage( &storage );
 }

}

But i am getting Exception in this line as given below:

cascade = (CvHaarClassifierCascade*)cvLoad(file_name,NULL, NULL, NULL);

Please do reply with a valid Solution.

Thanks and regaeds Shelly Rani

FaceDetection Using OpenCv-3.0.0-alpha

I am using Visual Studio 2012 with Open Cv-3.0.0 alpha. I want to detect faces from Image in MFC dialog based application. Code I am Using Is:- void CFaceDetectionDlg::OnBnClickedOk() {

  CvHaarClassifierCascade* cascade;
  CvMemStorage* storage;
  IplImage *image;
  CvSeq* faces;
  const char* file_name;
  int i;

CFileDialog dlg(TRUE, _T(".bmp"), NULL, OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,_T("image files (.bmp; .jpg) |.bmp;.jpg|All Files (.)|.*||"),NULL); dlg.m_ofn.lpstrTitle= _T("Open Image"); if (dlg.DoModal() == IDOK) {

CString path= dlg.GetPathName();
CStringA filename(path);
storage=cvCreateMemStorage(0);

cvFirstType();
file_name="E:/OpenCv/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml"; cascade = (CvHaarClassifierCascade*)cvLoad(file_name,NULL, NULL, NULL);

image = cvLoadImage(filename, 1 );

faces=cvHaarDetectObjects( image, cascade, storage, 1.1, 1,CV_HAAR_DO_CANNY_PRUNING,cvSize(10, 10));

//draw rectangles

for(i=0;i<(faces ? faces->total:0); i++ ) { CvRect* r; r = (CvRect*)cvGetSeqElem( faces, i ); CvPoint pt1= cvPoint (r->x, r->y) ; CvPoint pt2 = cvPoint (r->x + r->width, r->y + r->height) ;

cvRectangle( image, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 ); } // create window and show the image with outlined faces cvNamedWindow("faces", 1 ); cvShowImage( "faces", image ); cvSaveImage("Result.bmp", image);

 cvWaitKey();
 cvReleaseImage( &image );      // after a key pressed, release data
 cvReleaseHaarClassifierCascade( &cascade );
 cvReleaseMemStorage( &storage );
 }

}

But i am getting Exception in this line as given below:

cascade = (CvHaarClassifierCascade*)cvLoad(file_name,NULL, NULL, NULL);

Please do reply with a valid Solution.

Thanks and regaeds Regards Shelly Rani