Description
Project deals with face recognition and verification of person. It processes set of images on wich it trains eigenface and fisher face recognizer. Source of images can be csv file or web camera. When images are loaded program tries to recognize faces from set of test images and from web camera. Confidance is computed from detection which is used to verify owner of the face.
OpenCV function used
detectMultiScale, equalizeHist, createEigenFaceRecognizer, createFisherFaceRecognizer
The process
- Selecting and sorting images according to people (optional)
- Wrintting appropriate csv file (optional)
- Histogram equalization
- Face detection
- Add face and its label to vectors
- Train recognizer on saved images
- Predict from csv or camera
Detection phases
- Preprocessing (improve contrast in order to the intensity range- better illumination handling)
- Filtration and keypoints detection (nose holes, lips ends), available detectors: SIFT, SURF, FAST
- Used 2 recognizers
- Eigenfaces recognizer
- Fisher face recognizer
Sample
- Input image
- Haar face detection
- Conversion to grayscale
- Histogram equalization
- Recognizer training
=> RECOGNIZER - Face verification
bool calculateMetrics( cv::Mat &face, bool drawToFrame ) { std::vector<cv::Rect> eyes; std::vector<cv::Rect> nose; std::vector<cv::Rect> mouth; cv::Mat canvas = faceFrameColor.clone(); // Detect eyes eyes_cascade.detectMultiScale ( face, eyes, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30) ); if ( eyes.size() >; 1 && abs(eyes[0].y - eyes[1].y) < faceSize/5 && abs(eyes[0].x - eyes[1].x) > eyes[0].width) { if (eyes[0].x < eyes[1].x) { leftEyeRect = eyes[0]; rightEyeRect = eyes[1]; } else { leftEyeRect = eyes[1]; rightEyeRect = eyes[0]; } if ( drawToFrame ) { rectangle(canvas, eyes[0], cv::Scalar(128,255,255), 2 ); rectangle(canvas, eyes[1], cv::Scalar(128,255,255), 2 ); } // Detect nose nose_cascade.detectMultiScale ( face, nose, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30) ); if ( nose.size() > 0 && nose[0].y > eyes[0].y && ARE_ORDERED( eyes[0].x, nose[0].x, eyes[1].x ) ) { noseRect = nose[0]; if ( drawToFrame ) rectangle(canvas, nose[0], cv::Scalar(255,128,128), 2, 8 ); // Detect mouth mouth_cascade.detectMultiScale( face, mouth, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30) ); if ( mouth.size() > 0 && mouth[0].y + mouth[0].height > nose[0].y + nose[0].height && ARE_ORDERED( eyes[0].x, mouth[0].x, eyes[1].x )) { mouthRect = mouth[0]; if ( drawToFrame ) { rectangle(canvas, mouth[0], cv::Scalar(64,255,64), 2, 4 ); cv::imshow( "Face parts", canvas ); cv::waitKey(33); } return true; } } } return false; }