首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像数据访问和图像匹配‏中的C#和EMgu CV

图像数据访问和图像匹配‏中的C#和EMgu CV
EN

Stack Overflow用户
提问于 2013-12-04 22:07:53
回答 2查看 2.1K关注 0票数 0

我目前正在使用C#和Emgu CV在学生注册系统中创建一个实时的人脸识别程序。在开发它的过程中,我发现了几个关于访问图像数据和对其赋值的问题。

我的问题如下:

我可以知道如何从网络摄像头捕获的图像中直接访问图像数据吗?或者,如何将网络摄像头的“实时图像”连接到我的图像数据,以处理人脸图像匹配?

任何关于解决这个问题的建议都是非常受欢迎的。

感谢和问候,

Caulson Chua

EN

回答 2

Stack Overflow用户

发布于 2013-12-11 20:24:36

要在EmguCV中捕获图像,您必须使用capture对象。

代码语言:javascript
复制
Capture capture = new Capture(); //create a camera capture

然后,您可以添加一个类似这样的事件处理程序,以便在应用程序空闲时捕获新帧。

代码语言:javascript
复制
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{  

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

}); 

现在,这个latestFrame变量将包含从网络摄像头捕获的当前帧,您可以对其应用各种类型的图像处理。

PS:要了解更多关于EmguCV和如何构建人脸识别系统的信息,我建议您查看此link

票数 0
EN

Stack Overflow用户

发布于 2014-10-03 17:14:13

代码语言:javascript
复制
   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());
        }
    }

这是我的代码,可能会对你有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20377532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档