0

I have a problem looking forward to people to help when i detect and face recognition using Emgu Library,before face detection i draw a rectangle on the picturebox, the purpose is i want to face detection and recognition are located inside this rectangle if the face is outside the rectangle will not detect and identification, how can I do this?Please help me. My email : giangnamnam@gmail.com,thank you very much.

Descriptions:

Step 1: Detection and recognition

Step 2: I want the result will look like this

Here's my code:

  • Draw rectangle on picturebox :

     private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
       Rectangle rect = new Rectangle(90, 80, 160, 160);
        using (Pen pen = new Pen(Color.Red, 2))
        {
            e.Graphics.DrawRectangle(pen, rect);
        }
    }
    
    • Code for face detection :

      private void btn_FaceDetection_Click(object sender, EventArgs e)
      {
      
          Image<Bgr, byte>   imgOriginal = new Image<Bgr, byte>(new Bitmap(pictureBox1.Image));
          Image<Gray, Byte> grayFrame = imgOriginal.Convert<Gray, Byte>();
          Rectangle[] facesDetected = haar.DetectMultiScale(grayFrame, 1.2, 5, new Size(50, 50), Size.Empty);
      
          if (facesDetected.Length > 0)
          {
              for (int i = 0; i < facesDetected.Length; i++)
              {
                  facesDetected[i].X += (int)(facesDetected[i].Height * 0.1);
                  facesDetected[i].Y += (int)(facesDetected[i].Width * 0.15);
                  facesDetected[i].Height -= (int)(facesDetected[i].Height * 0.2);
                  facesDetected[i].Width -= (int)(facesDetected[i].Width * 0.2);
      
                  // print face to view
                  Image<Gray, Byte> result = grayFrame.Copy(facesDetected[i]).Convert<Gray, Byte>().Resize(150, 150, INTER.CV_INTER_CUBIC);
                  result._EqualizeHist();
                  picb_ViewFace.Image = result.ToBitmap();
      
                  // draw rectangle for face
                  imgOriginal.Draw(facesDetected[i], new Bgr(Color.Green), 2);
              }
          }
      
          pictureBox1.Image = imgOriginal.ToBitmap();
      
      }
      
sowjanya attaluri
  • 903
  • 2
  • 9
  • 27
  • if the coordinates of each point of the inner rectangle is inside the points of outer rectangle? – Anonymous Duck Jul 15 '16 at 07:09
  • 1
    [See here](http://stackoverflow.com/questions/38319092/i-made-a-rectangle-how-do-i-check-if-the-mouse-clicked-on-it/38322668?s=1|0.0000#38322668) Rectangle.Contains(Rectangle) is one more nice function in the Rectangle class. – TaW Jul 15 '16 at 07:12

0 Answers0