|
MFC APPLICATION If you're working with an MFC application, follow these steps to get your Haar Facial Detector working: Step 1 Install Intel OpenCV. I will assume it's installed in the default directory : c:\program files\opencv Step 2 Create a standard MFC application using the AppWizard. Step 3 In Project Settings (Alt+F7), go to the C/C++ tab, then select Category Preprocessor, and for Additional Include directories, add the following: C:\Program Files\opencv\cv\include,C:\Program Files\opencv\otherlibs\highgui,C:\Program Files\opencv\cxcore\include,C:\Program Files\opencv\cvaux\include Step 4 In Project Settings (Alt+F7), go to the Link tab, then select Category "Input", and for "Object/library modules:", add the following: cxcored.lib cvd.lib highguid.lib (see that there are no commas like in Step 3 above) Step 5 While staying in the Link tab, and Category "Input", for the "Additional Library path:", add the following: C:\Program Files\opencv\lib Step 6 In your main application file, eg Simple.cpp, include the following files: #include "cv.h" #include "highgui.h" Step 7 In the same file, go to the InitInstance() function. Right after you see the lines: m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); and before the line return TRUE; add the following lines of code //declarations CvHaarClassifierCascade* cascade; CvMemStorage* storage; IplImage *image; CvSeq* faces; const char* file_name; int i; //initializations storage=cvCreateMemStorage(0); cvFirstType(); file_name="haarcascade_frontalface_alt.xml"; cascade = (CvHaarClassifierCascade*)cvLoad(file_name,NULL, NULL, NULL); image = cvLoadImage("lena.jpg", 1 ); faces = cvHaarDetectObjects( image, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING,cvSize(0, 0)); //draw rectangles for(i=0;i<(faces ? faces->total:0); i++ ) { CvRect* r = (CvRect*)cvGetSeqElem( faces, i ); CvPoint pt1 = { r->x, r->y }; CvPoint pt2 = { 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.jpg", image); cvWaitKey(); cvReleaseImage( &image ); // after a key pressed, release data cvReleaseHaarClassifierCascade( &cascade ); cvReleaseMemStorage( &storage ); Step 8 Now go to c:\program files\opencv\bin, and copy the following files to the folder where your MFC files reside: cv097d.dll cxcore097d.dll highgui097d.dll Step 9 Now go to c:\program files\opencv\samples\c and copy lena.jpg to the folder where your MFC files reside. Step 10 Run your application.
|