0

私は顔認識プロジェクトに取り組んでいました。データベースをトレーニングして EigenObjectRecognizer を呼び出すと、認識されないラベルが付いた黒い画像が生成されます。コードを実行すると、次のようになりますhttp://www.mediafire.com/view/?ewns4iqvd51adsc。画像ボックスで検出され、認識され、抽出されたはずの顔は完全に黒です。そして、認識のための入力画像は、データベースが訓練されたものとまったく同じです.それで、なぜそれは不明または認識されない結果を出し続けたのですか. コードの一部が見える

としてロードされたトレーニング セットからの画像

    public FaceRecognizer()
    {
        InitializeComponent();

        //Load faces from the dataset
        try
        {

           ContTrain = ContTrain + 1;
            //Load previous trained and labels for each image from the database Here
            string NameLabelsinfo = File.ReadAllText(Application.StartupPath +
         "/TrainedFaces/TrainedNameLables.txt");
            string[] NameLabels = NameLabelsinfo.Split('%');
            NumNameLabels = Convert.ToInt16(NameLabels[0]);
            string IDLabelsinfo = File.ReadAllText(Application.StartupPath +
        "/TrainedFaces/TrainedNameLables.txt");
            string[] IDLables = IDLabelsinfo.Split('%');
            NumIDLabels = Convert.ToInt16(IDLables[0]);


            if (NumNameLabels == NumIDLabels)
            {
                ContTrain = NumNameLabels;
                string LoadFaces;
                // Converting the master image to a bitmap

                for (int tf = 1; tf < NumNameLabels + 1; tf++)
                {
                    LoadFaces = String.Format("face{0}.bmp", tf);
                    trainingImages.Add(new Image<Gray, byte>(String.Format("
       {0}/TrainedFaces/{1}", Application.StartupPath, LoadFaces)));
                    IDLabless.Add(IDLables[tf]);
                    NameLabless.Add(NameLabels[tf]);

                }
            }
        }
        catch (Exception e)
        {
             //Returns the following message if nothing saved in the training set
            MessageBox.Show("Nothing in binary database, please add at least a
              face(Simply train the prototype with the Add Face Button).", "Triained
                 faces load",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }

顔認識メソッドは次のようになります

      private void RecognizeFaces()
             {
        //detect faces from the gray-scale image and store into an array of type
         //    'var',i.e 'MCvAvgComp[]'
             Image<Gray, byte> grayframe = GetGrayframe();
              stringOutput.Add("");
           //Assign user-defined Values to parameter variables:
             MinNeighbors = int.Parse(comboBoxMinNeigh.Text);  // the 3rd parameter
            WindowsSize = int.Parse(textBoxWinSiz.Text);   // the 5th parameter
            ScaleIncreaseRate = Double.Parse(comboBoxScIncRte.Text); //the 2nd 
                                                                      //parameter
             //Detect faces from an image and save it to var i.t MCvAcgComp[][]
           var faces = grayframe.DetectHaarCascade(haar, ScaleIncreaseRate,
                                MinNeighbors,
                                HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                new Size(WindowsSize, WindowsSize))[0];

        if (faces.Length > 0 && trainingImages.ToArray().Length != 0)
        {
            Bitmap ExtractedFace;   //empty
            ExtFaces = new Image<Gray, byte>[faces.Length];
            faceNo = 0;
            foreach (var face in faces)
            {
                // ImageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
                //set the size of the empty box(ExtractedFace) which will later
            //contain the detected face
                ExtractedFace = new Bitmap(face.rect.Width, face.rect.Height);

                ExtFaces[faceNo] = new Image<Gray, byte>(ExtractedFace); 
                ExtFaces[faceNo] = ExtFaces[faceNo].Resize(100, 100,
                  Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                //TermCriteria for face recognition with numbers of trained images
                //    like maxIteration
                MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);

                    //Eigen face recognizer
                        EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
                         trainingImages.ToArray(),
                         NameLabless.ToArray(),
                         700,
                         ref termCrit);
               stringOutput[faceNo] = recognizer.Recognize(ExtFaces[faceNo]);
               stringOutput.Add("");
               faceNo++;
            }

            pbExtractedFaces.Image = ExtFaces[0].ToBitmap(); //draw the face detected
                  // in the 0th (gray) channel with blue color

            if (stringOutput[0] == "")
                {
                    label1.Text = "Unknown";
                    label9.Text = "";
                }
                //Draw the label for each face detected and recognized
            else
             {
                    //string[] label = stringOutput[faceNo].Split(',');
                    label1.Text = "Known";
                   // for (int i = 0; i < 2; i++)
                    //{
                    label9.Text = stringOutput[0];
                        //label7.Text = label[1];
                    //}
             }
        }
        if (faceNo == 0)
            {
                MessageBox.Show("No face detected");
            }
        else
        {
            btnNextRec.Enabled = true;
            btnPreviousRec.Enabled = true;
        }
    }

トレーニング セットは、次のように検出された顔でトレーニングされます。

           private void saveFaceToDB_Click(object sender, EventArgs e)
            {
               abd = (Bitmap) pbExtractedFaces.Image;
               TrainedFaces = new Image<Gray, byte>(abd);
               trainingImages.Add(TrainedFaces);
              NameLabless.Add(StudentName.Text);
               IDLabless.Add(StudentID.Text);

               //Write the number of trained faces in a file text for further load
              File.WriteAllText(Application.StartupPath + "/TrainedFaces
              /TrainedNameLables.txt", trainingImages.ToArray().Length + "%");
              File.WriteAllText(Application.StartupPath + "/TrainedFaces
               /TrainedIDLables.txt", trainingImages.ToArray().Length + "%");

              //Write the labels of trained faces in a file text for further load
              for (int i = 1; i < trainingImages.ToArray().Length + 1; i++)
                {
                 trainingImages.ToArray()[i - 1].Save(String.Format("{0}/TrainedFaces
                   /face{1}.bmp", Application.StartupPath, i));
                  File.AppendAllText(Application.StartupPath + "/TrainedFaces
             /TrainedIDLables.txt", NameLabless.ToArray()[i - 1] + "%");
              File.AppendAllText(Application.StartupPath + "/TrainedFaces
             /TrainedNameLables.txt", IDLabless.ToArray()[i - 1] + "%");

            }

          MessageBox.Show(StudentName.Text + "´s face detected and added :)", "Training
              OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
          }

ありがとう

4

0 に答える 0