【问题标题】:Converting contours found using EMGU.CV转换使用 EMGU.CV 找到的轮廓
【发布时间】:2013-05-24 11:18:18
【问题描述】:

我是 EMGU.CV 的新手,我有点挣扎。让我从项目的一些背景开始,我正在尝试跟踪用户的手指,即计算用户的指尖,但我有点挣扎。我创建了一组代码,将深度信息过滤到某个范围内,然后生成位图图像 tempBitmap,然后使用 EMGU.CV 将此图像转换为灰度图像,cvCanny 可以使用该图像。完成此操作后,我将扩张滤镜应用于 canny 图像以加厚手部的轮廓,以更好地提高生成成功轮廓的机会,然后我尝试获取手部的轮廓。现在我设法在手周围画了一个框,但我正在努力寻找一种方法将 FindContours 生成的轮廓转换为一组我可以用来绘制轮廓的点。变量 depthImage2 是我用来绘制的位图图像变量,然后将其分配给基于 C# 表单的应用程序上的图片框变量。您可以为我提供的任何信息或指导将不胜感激,如果我的代码不正确,可能会引导我朝我可以计算指尖的方向前进。我想我快到了,我只是缺少一些东西,所以任何形式的帮助都将不胜感激。

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);
    }

【问题讨论】:

    标签: emgucv


    【解决方案1】:

    Contour contours = 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

    的签名

    ....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      相关资源
      最近更新 更多