【问题标题】:C# and EMgu CV in image data accessing & image matching‏图像数据访问和图像匹配中的 C# 和 EMgu CV
【发布时间】:2013-12-21 01:37:01
【问题描述】:

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

我的问题如下:

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

非常欢迎任何有关解决此问题的建议。

感谢和问候,

蔡崇信

【问题讨论】:

    标签: c# opencv sqldatasource emgucv face-recognition


    【解决方案1】:

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

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

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

    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

    【讨论】:

      【解决方案2】:
         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());
              }
          }
      

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

      【讨论】:

        猜你喜欢
        • 2012-04-02
        • 1970-01-01
        • 2012-11-18
        • 2017-12-21
        • 1970-01-01
        • 2017-12-24
        • 2015-03-08
        • 1970-01-01
        • 2011-06-25
        相关资源
        最近更新 更多