Online Face Recognition using OpenCV

后端 未结 2 997
难免孤独
难免孤独 2021-02-06 18:55

I am trying to implement online face recognition using the webcam. I am using this two websites as references

shervinemami.co.cc
cognotics.com

I have few que

相关标签:
2条回答
  • 2021-02-06 19:29

    I just read

    int _tmain(int argc, _TCHAR* argv[]) 
    {
    .......
    }
    

    part of your code. This code is used for detecting the face in the image. Lets say it is Face_x. Now extract features from Face_x, call it as F_x. In your database, you should store features {F_1, F_2,..., F_N} extracted from n different faces {Face_1, Face_2,..Face_N}.

    Simple algorithm to recognize Face_x is to calculate Euclidean distances between F_x and n features. The minimum distance (below threshold) gives corresponding face. If the minimum distance is not below threshold then Face_x is a new face. Add feature F_x to database. This way you can increase your database. You can begin your algorithm with no features in database. With each new face, database grows.
    I hope the method suggested by me will lead you to the solution

    0 讨论(0)
  • 2021-02-06 19:33

    My answer may came late but it might be useful for pals if i answer it.I am working on a similar project and i have faced the same problem.I solved it by writing a function the saves or write the detected,cropped and preprocessed image on to the hard disk of my computer(Using CvWrite).And feeding the parameter of the saved images to the recognition part of the code. It has made my life easier.It has been a bit harder for me to to pass the parameters of the rect of the region of interest. If you or someone else did this it might be great sharing the code with us. You can use the following code to save the image after resizing it to a constant value using the resizeimage function on you code.

        void saveCroppedFaces(CvSeq* tempon,IplImage* DetectedImage)
    {
    
            char* name;
            int nFaces;
            CvRect rect;
            nFaces=tempon->total;
            name =new char[nFaces];
            IplImage* cropped = 0;
            IplImage* croppedResized=0;
            Mat croped;
            for(int k=0;k<nFaces;k++)
            {
                itoa(k,(name+k),10);
                rect = *(CvRect*)cvGetSeqElem( tempon, k );
                cropped= cropImage(DetectedImage,rect);
                //i can resize the cropped faces in to a fixed size here
    
                //i can write a function to save images and call it so
                      //that it will save it in to hard drive 
                //cvNamedWindow((name+k),CV_WINDOW_AUTOSIZE);
    
                //cvShowImage((name+k),cropped);
                croppedResized=resizeImage(cropped,60,60);
                croped=IplToMatConverter(croppedResized);
                saveROI(croped,itoa(k,(name+k),10));
                cvReleaseImage(&cropped);
            }
        name=NULL;
        delete[] name;
    
    }
    
    void saveROI(Mat mat,String outputFileName)
    {
        string store_path("C://Users/sizusuzu/Desktop/Images/FaceDetection2
                                                        /"+outputFileName+".jpg");
        bool write_success = imwrite(store_path,mat);
    
    }
    

    After this you can change the IplImage* to Mat using

          Mat IplToMatConverter(IplImage* imageToMat)
         {
        Mat mat = cvarrToMat(imageToMat);
        return mat;
         }
    

    And use the Mat in FaceRecognizer API.Or just do the other/harder way. Thanks

    0 讨论(0)
提交回复
热议问题