Reputation: 49
I am trying to find the convex hull of a contour with emgu 3.1
It seems to be the case that FindContours only accepts a vectorOfVectorOfPoints (not pointsF). But then, convexhull requires a vectorOfPointF. Am I wrong? If I change contours to VectorOfVectorOfPointF I get a runtime error in the call to FindContours.
How do you convert a VectorOfPoint to VectorOfPointF? Is there a better way to do it?
Thanks!
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);
}
Upvotes: 1
Views: 3417
Reputation: 52
A slighty updated version of @Atresmo's answer. We can just cast the Point to a 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);
}
Upvotes: 0
Reputation: 43
It seems that the only way is to construct your VectorOfPointF from each of the VectorOfPoint in the contours object:
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);
}
Upvotes: 2