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 Regards Shelly Rani
that code is opencv1.0, not opencv3.0.
please do not use the arcane c-api, see here for a more modern version.
I am Using MFC Dialog Based Application, not Win32 Console Application. Please Help me out as these functions are not working in VC++.
please change your opencv code first, so it's using the c++ api.
I have Changed the code As you suggested before.
did you ? as long as you're using IplImages, and CvHaarClassifierCascade* , you're doing the wrong thing.
Please Specify me the right code, so that i can implement that in my application.
Thanks
please read the tutorial link in the 1st comment.
Ok Thanks alot