转换使用EMGU.CV找到的轮廓

时间:2013-05-24 11:18:18

标签: emgucv

我是EMGU.CV的新手,我有点挣扎。让我首先给出一些项目背景,我试图跟踪用户的手指,即计算用户的指尖,但我有点挣扎。我创建了一组代码,将深度信息过滤到一定范围,然后生成一个Bitmap图像tempBitmap,然后使用EMGU.CV将此图像转换为灰度图像,cvCanny可以使用它。完成后,我将扩张滤镜应用于canny图像,以增加手的轮廓,以更好地提高生成成功轮廓的机会,然后尝试获得手的轮廓。现在我设法做的是在手上画一个方框,但我很难找到一种方法将FindContours生成的轮廓转换为一组我可以用来绘制轮廓的点。变量depthImage2是一个Bitmap图像变量,用于在将其添加到基于C#form的应用程序上的picturebox变量之前进行绘制。如果我的代码不正确可能指导我指导我可以计算指尖的方向,那么您可以提供给我的任何信息或指导将非常感激。我想我几乎就在那里,我只是错过了什么,所以任何形式的帮助都会受到赞赏。

Image<Bgr, Byte> currentFrame = new Image<Bgr, Byte>(tempBitmap);

Image<Gray, Byte> grayImage = currentFrame.Convert<Gray, Byte>().PyrDown().PyrUp();
Image<Gray, Byte> cannyImage = new Image<Gray, Byte>(grayImage.Size);
CvInvoke.cvCanny(grayImage, cannyImage, 10, 60, 3);

StructuringElementEx kernel = new StructuringElementEx(
    3, 3, 1, 1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);

CvInvoke.cvDilate(cannyImage, cannyImage, kernel, 1);

IntPtr cont = IntPtr.Zero;

Graphics graphicsBitmap = Graphics.FromImage(depthImage2);

using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation
    for (Contour<Point> contours =
        cannyImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,                               
            Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL); 
                contours != null; contours = contours.HNext)
    {                                
        IntPtr seq = CvInvoke.cvConvexHull2(contours, storage.Ptr, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE, 0);
        IntPtr defects = CvInvoke.cvConvexityDefects(contours, seq, storage);
        Seq<Point> tr = contours.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

        Seq<Emgu.CV.Structure.MCvConvexityDefect> te = contours.GetConvexityDefacts(
            storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE);

        graphicsBitmap.DrawRectangle(
            new Pen(new SolidBrush(Color.Red)), tr.BoundingRectangle);
    }

1 个答案:

答案 0 :(得分:1)

轮廓轮廓= cannyImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE)//返回所有点

然后:

List<Point[]> convertedContours = new List<Point[]>();
while(cotours!=null)
{
  var contourPoints = contours.ToArray(); //put Seq<Point> to Point[], ToList() is also available ?
  convertedContours.Add(contourpoints);

  contours = contours.HNext;
}

你可以通过图像绘制轮廓绘制功能过载。 只需找到包含参数Seq&lt;&gt;

的签名

...

相关问题