我只想知道如何从轮廓点列表中提取一些元素。
基本上,我有这样的想法:
List<Contour<Point>> contoursList = new List<Contour<Point>>;
contourList.Add(contours); //that contours variable is a Contour<Point> that i receive in a .FindContour method.然后,我需要选择/提取/这个列表中的任何一个特定元素,并找到它的坐标。那么我该怎么做呢?
还有,有什么想法吗?
发布于 2014-06-30 18:55:24
你推荐过this post了吗?
使用特性过滤器,如面积、等高线长度和每条等高线的中心来过滤所需的等高线坐标。
发布于 2014-07-12 15:46:54
下面是你应该做的:
参见下面的示例代码:
//variable to hold the contour
Contour<Point> contours = null;
for (var contour = binaryImage.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
RETR_TYPE.CV_RETR_CCOMP, mem);
contour != null;
contour = contour.HNext)
{
if (contours == null)
{
//this is to ensure contours is not null
contours = contour;
}
//push/add the sequence of points to contours
contours.PushMulti(contour.ToArray(), BACK_OR_FRONT.BACK);
}
//do what you want with it
var ch = contours.GetConvexHull(ORIENTATION.CV_CLOCKWISE, mem);
//for example, convert these points to type PointF
PointF[] pointfs = Array.ConvertAll(contours.ToArray(), input => new PointF(input.X, input.Y));
//or detect the bounding rectangle
var roi = PointCollection.BoundingRectangle(pointfs);https://stackoverflow.com/questions/24478831
复制相似问题