公告

非常抱歉,由于我们的服务器提供商硬盘出错,数据丢失,网站重建中...
I am so sorry, because of our server's hard disk error, data lost, the website reconstructioning
QQ:512000523
MSN : funchip@hotmail.com

 
首页 arrow 技术文章 arrow setp arrow OpenCV在MFC下使用
OpenCV在MFC下使用 Recommend to my friend via E-mail(推荐给朋友)
作者: Administrator   
2007-11-14

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.

评论 (0)Add Comment

输入评论内容
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security code
输入验证码


busy
最近更新 ( 2007-11-18 )
 
< 上一篇   下一篇 >

© 2008 杭州福芯电子 浙ICP备05040812号
Joomla!是基于GNU/GPL许可发行的免费软件.