Improve recognition performance for EigenFaces and FisherFaces models 87/64587/1
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 4 Apr 2016 03:02:11 +0000 (12:02 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Mon, 4 Apr 2016 03:04:15 +0000 (12:04 +0900)
1. Change confidence calculation
2. Add error check routine for FisherFaces model when the number of face classes is less than 2

Change-Id: If848ecd48a2b53eb8c0a4b02ac060755c3b30e20
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
mv_face/face/src/FaceRecognitionModel.cpp
packaging/capi-media-vision.spec

index 7a42cff..3686342 100644 (file)
@@ -372,6 +372,17 @@ const std::set<int>& FaceRecognitionModel::getFaceLabels(void) const
 
 int FaceRecognitionModel::learn(const FaceRecognitionModelConfig& config)
 {
+       /* Check number of classes collected for learning, some algorithms
+        * require specific class number constraints. For example, Fisherfaces
+        * requires more that 1 class in training set */
+       if (MEDIA_VISION_FACE_MODEL_TYPE_FISHERFACES == config.mModelType &&
+                       m_faceSamples.size() < 2) {
+               LOGE("Can't apply Fisherfaces learning algorithm. It requires at "
+                               "least two classes (face labes) to learn on.");
+
+               return MEDIA_VISION_ERROR_INVALID_OPERATION;
+       }
+
        bool isIncremental = false;
        bool isUnisize = false;
 
@@ -456,30 +467,38 @@ int FaceRecognitionModel::recognize(const cv::Mat& image, FaceRecognitionResults
 {
        if (!m_recognizer.empty() && m_canRecognize) {
                double absConf = 0.0;
+               cv::Mat predictionImg(m_learnAlgorithmConfig.mImgWidth,
+                               m_learnAlgorithmConfig.mImgHeight, CV_8UC1);
+
                if ((MEDIA_VISION_FACE_MODEL_TYPE_EIGENFACES == m_learnAlgorithmConfig.mModelType ||
-                        MEDIA_VISION_FACE_MODEL_TYPE_FISHERFACES == m_learnAlgorithmConfig.mModelType) &&
-                       (image.cols != m_learnAlgorithmConfig.mImgWidth ||
-                        image.rows != m_learnAlgorithmConfig.mImgHeight)) {
-                       cv::Mat predictionImg(
-                                               m_learnAlgorithmConfig.mImgWidth,
-                                               m_learnAlgorithmConfig.mImgHeight,
-                                               CV_8UC1);
+                               MEDIA_VISION_FACE_MODEL_TYPE_FISHERFACES == m_learnAlgorithmConfig.mModelType) &&
+                               (image.cols != m_learnAlgorithmConfig.mImgWidth ||
+                               image.rows != m_learnAlgorithmConfig.mImgHeight))
                        cv::resize(image, predictionImg, predictionImg.size());
-                       m_recognizer->predict(predictionImg, results.mFaceLabel, absConf);
-
-                       if (-1 != results.mFaceLabel) {
-                               results.mConfidence = 1.0;
-                               results.mIsRecognized = true;
-                       } else {
-                               results.mConfidence = 0.0;
-                               results.mIsRecognized = false;
+               else
+                       predictionImg = image;
+
+               m_recognizer->predict(predictionImg, results.mFaceLabel, absConf);
+
+               if (-1 != results.mFaceLabel) {
+                       double normShift = 7.5;
+                       double normSmooth = 0.05;
+
+                       if (MEDIA_VISION_FACE_MODEL_TYPE_EIGENFACES == m_learnAlgorithmConfig.mModelType) {
+                               normShift = 5.0;
+                               normSmooth = 0.0015;
+                       } else if (MEDIA_VISION_FACE_MODEL_TYPE_FISHERFACES == m_learnAlgorithmConfig.mModelType) {
+                               normShift = 5.0;
+                               normSmooth = 0.01;
                        }
-               } else {
-                       m_recognizer->predict(image, results.mFaceLabel, absConf);
+
                        /* Normalize the absolute value of the confidence */
-                       absConf = exp(7.5 - (0.05 * absConf));
+                       absConf = exp(normShift - (normSmooth * absConf));
                        results.mConfidence = absConf / (1 + absConf);
                        results.mIsRecognized = true;
+               } else {
+                       results.mConfidence = 0.0;
+                       results.mIsRecognized = false;
                }
 
                results.mFaceLocation = cv::Rect(0, 0, image.cols, image.rows);
index 2e40b49..dab5a12 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.3.11
+Version:     0.3.12
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-2.0