-1

I want to detect the face from the camera input. I first tried to detect the face using images. I tried the codes in the documentation and face detection codes available in the blogs, but none of them work for me. I am using OpenCV 2.4.7 and Visual Studio 2010.

I get the following errors:

error LNK2019: unresolved external symbol _cvReleaseHaarClassifierCascade referenced in function _main D:\opencv_projects\@@@@HandDetect\faces\faces\faces.obj faces

error LNK2019: unresolved external symbol _cvHaarDetectObjects referenced in function "void __cdecl detectFaces(void)" (?detectFaces@@YAXXZ) D:\opencv_projects\@@@@HandDetect\faces\faces\faces.obj faces

error LNK2019: unresolved external symbol "void __cdecl detectFaces(struct _IplImage *)" (?detectFaces@@YAXPAU_IplImage@@@Z) referenced in function _main D:\opencv_projects\@@@@HandDetect\faces\faces\faces.obj faces

error LNK1120: 3 unresolved externals D:\opencv_projects\@@@@HandDetect\faces\Debug\faces.exe 1 1 faces

My code:

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
Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
  • 3
    please **never** use the deprecated c-api, but [the c++ one](http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html#cascade-classifier) . also link to opencv_objdetect.lib – berak May 30 '15 at 12:44
  • @berak : I have forgotten to link the lib ..it works now thank you !! – Kasuni Nanayakkara May 31 '15 at 07:16

1 Answers1

2

Please verify that OpenCV is installed correctly and linked to your project. This error occurs when a library is well not linked to your project. Try with another PC/OS.

kguest
  • 3,804
  • 3
  • 29
  • 31
  • Thanks for posting your answer! Please note that you should post the essential parts of the answer here, on this site, or your post risks being deleted [See the FAQ where it mentions answers that are 'barely more than a link'.](http://stackoverflow.com/faq#deletion) You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Taryn May 30 '15 at 14:49