我想检测来自摄像头输入的人脸。我首先尝试用图像来检测人脸。我尝试了文档中的代码和博客中提供的面部检测代码,但它们都不适合我。我使用的是OpenCV 2.4.7和Visual Studio 2010。
得到以下错误:
我代码:错误LNK2019:在函数_main中引用的未解析的外部符号_cvReleaseHaarClassifierCascade D:opencv_projects@@@@HandDetectfacesfacesfaces。obj面临
错误LNK2019:在函数"void __cdecl detectFaces(void)"中引用的未解析的外部符号_cvHaarDetectObjects(? detectFaces@@YAXXZ) D: opencv_projects @@@@HandDetect 脸。obj面临
错误LNK2019:无法解析的外部符号"void __cdecl detectFaces(struct _IplImage *)"(? detectfaces@yaxpau_iplimage@@z)在函数_main中引用D:opencv_projects@@@@HandDetectfacesfacesfaces。obj面临
D:opencv_projects@@@@HandDetectfacesDebugfaces.exe 11 faces
void detectFaces();
IplImage *inImage;
CvHaarClassifierCascade *cascade;
CvMemStorage *storage;
CvMemStorage *facesstorage=cvCreateMemStorage(0);;
CvSeq* faces = cvCreateSeq(CV_SEQ_ELTYPE_POINT,sizeof(CvSeq),sizeof(CvPoint),facesstorage);
void detectFaces (IplImage *newframe);
int key;
int iImg;
int N_Images=20;
int main(int argc, const char** argv)
{
// (1) Defining the path and Loading the Classifier (C format)
cascade = ( CvHaarClassifierCascade* )cvLoad( "D:/opencv_projects/@@@@HandDetect/faces/MyCascade/haarcascade_frontalface_alt2.xml");
//cascade =cvLoadHaarClassifierCascade( "D:\opencv_projects\@@@@HandDetect\faces\MyCascade\haarcascade_frontalface_alt2.xml",cvSize(100,100));
//cascade = ( CvHaarClassifierCascade* )cvLoad("haarcascade_frontalface_alt2.xml");
// (3) Creating Buffer
storage = cvCreateMemStorage(0) ;
// (4) Loads a single Image into
inImage = cvLoadImage("D:\Opencv\test\camera\A.jpg",1);
// (5) Check for proper initialization
if( !cascade || !storage || !inImage)
{
printf("Initialization Failed: %sn",
(!cascade)? " Cascade file not found !n":
(!storage)? " Not memmory allocated or not enough memory !n":
" The input file can not be found!n");
system("pause");
return 0;
}
// (6) face detection
detectFaces( inImage ); // Calling the face detection function for the input image-inImage
cvShowImage("Face Detection",inImage); // Shows the final image after Face detection, in Window "Face Detection"
cvReleaseImage( &inImage); // Release the current image from memory
cvWaitKey(0);
//cascade = ( CvHaarClassifierCascade* )cvLoad("D:\opencv_projects\@@@@HandDetect\faces\MyCascade\haarcascade_frontalface_alt2.xml");
// (5) Check for proper initialization
if( !cascade || !storage || !inImage)
{
printf("Initialization Failed: %sn",
(!cascade)? " Cascade file not found !n":
(!storage)? " Not memmory allocated or not enough memory !n":
" The input file can not be found!n");
system("pause");
return 0;
}
// (7) Load a set of multiple images
char buf[22];
for(iImg=0; iImg<=N_Images; iImg++) // WHOLE DATABASE LOAD
{
sprintf(buf, "MyImages/P%04d.bmp", iImg);
printf("n");
inImage = cvLoadImage(buf, CV_LOAD_IMAGE_UNCHANGED);
printf("Input Image = P%04d.bmpn", iImg);
detectFaces( inImage );
cvShowImage("Face Detection",inImage);
cvReleaseImage( &inImage);
key= cvWaitKey(0); // Exit if the key q or Q is pressed
if ( key == 'q' || key == 'Q' )
return(0);
}
//(8) Releasing the resources (Cascade and Buffer)
cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
return 0;
}
void detectFaces( )
{
CvSeq *faces = cvHaarDetectObjects( inImage, cascade, storage,1.4, 1, 0, cvSize( 100, 100 ) );
// Looking for better detection?! Try these parameters:
// 1.15, 5, 0, cvSize(30 x 30)
for( int i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ )
{
CvRect *r = ( CvRect *)cvGetSeqElem( faces, i );
cvRectangle(inImage,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),CV_RGB( 0, 255, 0 ), 2, 8, 0 );
}
}
//END OF CODE
请确认OpenCV 已正确安装并链接到您的项目。当库没有很好地链接到项目时,会发生此错误。