我想从相机输入中检测到脸部。我首先尝试使用图像检测脸部。我尝试了博客中提供的文档和面部检测代码中的代码,但它们都不适用于我。我正在使用OpenCV 2.4.7和Visual Studio 2010。
我收到以下错误:
错误LNK2019:函数_main中引用的未解析的外部符号_cvReleaseHaarClassifierCascade D:\ opencv_projects \ @@@@ HandDetect \ faces \ faces \ faces.obj faces
错误LNK2019:未解析的外部符号_cvHaarDetectObjects在函数“void __cdecl detectFaces(void)”中引用(?detectFaces @@ YAXXZ)D:\ opencv_projects \ @@@@ HandDetect \ faces \ faces \ faces.obj faces
错误LNK2019:未解析的外部符号“void __cdecl detectFaces(struct _IplImage *)”(?detectFaces @@ YAXPAU_IplImage @@@ Z)在函数_main D中引用:D:\ opencv_projects \ @@@@ HandDetect \ faces \ faces \ faces .obj面对
错误LNK1120:3个未解析的外部D:\ opencv_projects \ @@@@ HandDetect \ faces \ Debug \ faces.exe 1 1个面孔
我的代码:
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: %s\n",
(!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: %s\n",
(!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.bmp\n", 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
答案 0 :(得分:2)
请确认OpenCV 已正确安装并链接到您的项目。当库未与您的项目链接时,会发生此错误。尝试使用其他PC / OS。