FaceDetection Using OpenCv-3.0.0-alpha

asked 2014-09-23 23:43:26 -0600

Shelly30 gravatar image

updated 2014-09-23 23:43:58 -0600

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 Regards Shelly Rani

edit retag flag offensive close merge delete

Comments

1

that code is opencv1.0, not opencv3.0.

please do not use the arcane c-api, see here for a more modern version.

berak gravatar imageberak ( 2014-09-24 01:44:30 -0600 )edit

I am Using MFC Dialog Based Application, not Win32 Console Application. Please Help me out as these functions are not working in VC++.

Shelly30 gravatar imageShelly30 ( 2014-09-24 02:20:29 -0600 )edit

please change your opencv code first, so it's using the c++ api.

berak gravatar imageberak ( 2014-09-24 02:24:56 -0600 )edit

I have Changed the code As you suggested before.

Shelly30 gravatar imageShelly30 ( 2014-09-24 02:29:02 -0600 )edit

did you ? as long as you're using IplImages, and CvHaarClassifierCascade* , you're doing the wrong thing.

berak gravatar imageberak ( 2014-09-24 02:32:16 -0600 )edit

Please Specify me the right code, so that i can implement that in my application.

Thanks

Shelly30 gravatar imageShelly30 ( 2014-09-24 02:36:03 -0600 )edit

please read the tutorial link in the 1st comment.

berak gravatar imageberak ( 2014-09-24 02:37:23 -0600 )edit

Ok Thanks alot

Shelly30 gravatar imageShelly30 ( 2014-09-24 02:38:17 -0600 )edit