从VectorOfPoint转换为VectorOfPointF以获取Emgu中的轮廓

时间:2016-12-21 21:46:17

标签: c# emgucv

我试图用emgu 3.1

找到轮廓的凸包

似乎FindContours只接受vectorOfVectorOfPoints(不是pointsF)。但是,convexhull需要vectorOfPointF。我错了吗?如果我将轮廓更改为VectorOfVectorOfPointF,则在调用FindContours时会出现运行时错误。

如何将VectorOfPoint转换为VectorOfPointF? 有没有更好的方法呢?

谢谢!

using (var contours = new VectorOfVectorOfPoint())
using (Mat hierachy = new Mat())
{

    CvInvoke.FindContours(img, contours, hierachy, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple, new Point());
            for (int i = 0; i < contours.Size; i++)
            {
                var contour = contours[i];
                var c = new VectorOfPointF();
                CvInvoke.ConvexHull(contour, c, false, true);
            }

2 个答案:

答案 0 :(得分:2)

似乎唯一的方法是从contours对象中的每个VectorOfPoint构造VectorOfPointF:

for (int i = 0; i < contours.Size; i++)
{
    var contour = contours[i];
    var vf = new PointF[vp.Size];
    for (int ii = 0; ii < contour.Size; ii++) vf[i] = new PointF(contour[ii].X, contour[ii].Y);
    VectorOfPointF vvf = new VectorOfPointF(vf);
    var c = new VectorOfPointF();
    CvInvoke.ConvexHull(vvf, c, false, true);
}

答案 1 :(得分:0)

@Atresmo的答案的最新版本。我们可以将Point投射到PointF:

for (int i = 0; i < contours.Size; i++)
{
    var contour = contours[i];
    var vf = new PointF[contour.Size];
    for (int ii = 0; ii < contour.Size; ii++) vf[i] = contour[ii];
    VectorOfPointF vvf = new VectorOfPointF(vf);
    var c = new VectorOfPointF();
    CvInvoke.ConvexHull(vvf, c, false, true);
}