C# and EMgu CV in image data accessing & image matching‏

2.7k views Asked by At

I'm currently using C# with Emgu CV to create a real-time face recognition programme in student registration system. Upon the process in developing it, I have several problems been spotted in accessing image data and assigning value on it.

My question is given as below:

May I know how to have a direct access to image data from the image i captured from web cam? Or perhaps how is the 'live image' from web cam can be connected to my image data to process the face image matching?

Any advice on getting this problem done are much welcome.

Thanks & regards,

Caulson Chua

2

There are 2 answers

0
Shiva On

To capture Image in EmguCV you have to use the capture object.

Capture capture = new Capture(); //create a camera capture

then you can add an event handler like this to capture a new frame whenever the application in idle.

Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{  

 Image<Bgr,Byte> latestFrame = capture.QueryFrame(); //draw the image obtained from camera

}); 

Now this latestFrame variable will contain the current frame that was captured from the web cam and you can apply various types of image processing on it.

PS: For learning more about EmguCV and how to build a face recognition system,I would suggest you to check this link

0
radhe12 On
   private void DetectFaces()
    {
        try
        {
            Image<Gray, byte> grayframe = TestImage.Convert<Gray, byte>();

            //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 the gray-scale image and store into an array of type 'var',i.e 'MCvAvgComp[]'
            var faces = grayframe.DetectHaarCascade(haar, ScaleIncreaseRate, MinNeighbors,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(WindowsSize, WindowsSize))[0];
            if (faces.Length > 0)
            {
                MessageBox.Show("Total Faces Detected: " + faces.Length.ToString());

                Bitmap BmpInput = grayframe.ToBitmap();
                Bitmap ExtractedFace;  // an empty "box"/"image" to hold the extracted face.

                Graphics FaceCanvas;

                //Set The Face Number
                //FaceCollection = Directory.GetFiles(@"Face Collection\", "*.bmp");
                //int FaceNo = FaceCollection.Length;

                //A Bitmap Array to hold the extracted faces
                EXfaces = new Bitmap[faces.Length];
                int i = 0;

                //draw a green rectangle on each detected face in image
                foreach (var face in faces)
                {
                    //locate the detected face & mark with a rectangle
                    TestImage.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);

                    //set empty image as FaceCanvas, for painting
                    FaceCanvas = Graphics.FromImage(ExtractedFace);

                    //graphics draws the located face on the faceCancas, thus filling the empty ExtractedFace 
                    //image with exact pixels of the face to be extracted from input image
                    FaceCanvas.DrawImage(BmpInput, 0, 0, face.rect, GraphicsUnit.Pixel);

                    //save this extracted face to hard disk
                    //ExtractedFace.Save(@"Face Collection\" + "Face_" + (FaceNo++) + ".bmp");//save images in folder

                    //Save this extracted face to array
                    EXfaces[i] = ExtractedFace;
                    i++;

                }
                //Display the detected faces in imagebox
                imageBox1.Image = TestImage;

                MessageBox.Show(faces.Length.ToString() + " Face(s) Extracted sucessfully!");
                imageBox2.Image = new Emgu.CV.Image<Bgr, Byte>(EXfaces[0]);
                button3.Enabled = true;
                textBox1.Enabled = true;

            }
            else
                MessageBox.Show("NO faces Detected!");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
            MessageBox.Show(ex.StackTrace.ToString());
        }
    }

this is my code this might help you