title: Face Recognition with FisherFace always predict a person.How to return -1(unknown person) when not have trained person to face the camera?
body: <p>I have a data set consisting of 2 people (<code>PERSON A</code> and <code>PERSON B</code>). </p>
  
  <p>My code works perfectly when <code>PERSON A</code> or <code>PERSON B</code> go to the camera(real time). But I test again with <code>PERSON C</code> (not have training images of <code>PERSON C</code> in .csv file ) when <code>PERSON C</code> goes to the camera; program predicts again <code>A</code> or <code>B</code>.</p>
  
  <p>I want to return -1(unknown person). How to do this? I use this code;</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/contrib/contrib.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/objdetect/objdetect.hpp&gt;
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  
  using namespace cv;
  using namespace std;
  
  string person_name_1, person_name_2;
  string haar_cascade_file = "C:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml";
  CascadeClassifier detectFace;
  string filename;
  int filenumber;
  VideoCapture video;
  
  static void csvFile_read(const string&amp; filename, vector&lt;Mat&gt;&amp; images, vector&lt;int&gt;&amp; labels, char seperator = ';'){
      std::ifstream file(filename.c_str(), ifstream::in);
      if (!file){
          string error_message = "File not found";
          CV_Error(CV_StsBadArg, error_message);
      }
      string line, file_path, file_label;
      while (getline(file, line)){
          stringstream lines(line);
          getline(lines, file_path, seperator);
          getline(lines, file_label);
          if (!file_path.empty() &amp;&amp; !file_label.empty()){
              images.push_back(imread(file_path, 0));
              labels.push_back(atoi(file_label.c_str()));
          }
  
      }
  
  
  }
  int main(int argc, const char *argv[]){
  
      double const threshold = DBL_MAX;
      string csv_file = "C:\\Users\\user\\Desktop\\Tutorialss\\important books\\final year\\DetectsAndRecognizeFaces\\DetectsAndRecognizeFaces\\DetectsAndRecognizeFaces\\csv.ext";
      int cameraNo = 0;
  
      vector&lt;Mat&gt; images; 
      vector&lt;int&gt; labels; 
  
      try{
          csvFile_read(csv_file, images, labels);
      }
      catch (cv::Exception&amp; e){
          cerr &lt;&lt; "Error " &lt;&lt; csv_file &lt;&lt; "\..." &lt;&lt; " Reason: " &lt;&lt; e.msg &lt;&lt; endl;
          exit(1);
      }
  
  
      int image_width = images[0].cols;
      int image_height = images[0].rows;
  
  
  
      Ptr&lt;FaceRecognizer&gt; face_recog_model = createFisherFaceRecognizer(0,DBL_MAX);
      face_recog_model-&gt;train(images, labels);
  
  
  
  
      detectFace.load(haar_cascade_file);
  
      VideoCapture video(cameraNo); 
  
  
      if (!video.isOpened()){
          cerr &lt;&lt; cameraNo &lt;&lt; " camera error" &lt;&lt; endl;
          return -1;
      }
  
      string person_list[] =
      {
          "PERSON A",
          "PERSON B"
      };
  
  
      Mat live_video;
      while (1){
          video &gt;&gt; live_video;
          Mat original = live_video.clone();
          Mat grey;
          cvtColor(original,grey, CV_BGR2GRAY); 
  
          vector&lt; Rect_&lt;int&gt; &gt; faces;
          detectFace.detectMultiScale(grey, faces);
  
  
  
          for (int i = 0; i &lt; faces.size(); i++){
  
              Rect face_i = faces[i];
              Mat face = grey(face_i);
  
              Mat face_resize;
              resize(face, face_resize, Size(image_width, image_height), 1.0, 1.0, INTER_CUBIC);
  
              int predict = face_recog_model-&gt;predict(face_resize);
              rectangle(original, face_i, CV_RGB(0, 255, 0), 1);
              string text_box;
              text_box = format("Predict= ");
              if ( predict &gt;= 0 &amp;&amp; predict &lt;= 1){
  
                  text_box.append(person_list[predict]);
              }
              else{
                  text_box.append("Unknown...");
              }
  
  
              int horizontal = std::max(face_i.tl().x - 10, 0);
              int vertical = std::max(face_i.tl().y - 10, 0);
              putText(original, text_box, Point(horizontal, vertical), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 255, 0), 2.0);
  
  
          }
          imshow("Face Detector", original);
          char key = (char)waitKey(20);
          if (key == 27)
              break;
      }
      return 0;
  
  }
  </code></pre>
  
  <p>and my csv file:</p>
  
  <pre><code>path\personA_01.jpg;0
  path\personA_02.jpg;0
  path\personA_03.jpg;0
  path\personA_04.jpg;0
  path\personA_05.jpg;0
  path\personA_06.jpg;0
  path\personA_07.jpg;0
  path\personA_08.jpg;0
  path\personA_09.jpg;0
  path\personA_10.jpg;0
  path\personB_01.jpg;1
  path\personB_02.jpg;1
  path\personB_03.jpg;1
  path\personB_04.jpg;1
  path\personB_05.jpg;1
  path\personB_06.jpg;1
  path\personB_07.jpg;1
  path\personB_08.jpg;1
  path\personB_09.jpg;1
  path\personB_10.jpg;1
  </code></pre>
  
  <p>How to solve this problem ?</p>