【发布时间】:2022-09-24 21:55:13
【问题描述】:
我们如何在 EMGUCV 4.5 中从左到右对轮廓进行排序?库中没有定义排序函数。
有没有人尝试在新版本的 EMGUCV 中对轮廓进行排序?
标签: c# image-processing emgucv
我们如何在 EMGUCV 4.5 中从左到右对轮廓进行排序?库中没有定义排序函数。
有没有人尝试在新版本的 EMGUCV 中对轮廓进行排序?
标签: c# image-processing emgucv
已提取边界矩形并使用 linq 进行排序。见下文
static void Sort(Mat img, VectorOfVectorOfPoint contours)
{
List<Rectangle> rects= new List<Rectangle>();
for (int i = 0; i < contours.Size; i++)
{
var rect = CvInvoke.BoundingRectangle(contours[i]);
rects.Add(rect);
CvInvoke.Rectangle(img, rect, new MCvScalar(0, 0, 0), 3);
CvInvoke.Imshow("img", img);
CvInvoke.WaitKey();
}
var rectList = rects.Distinct().OrderBy(r => r.Left).ThenBy(r
=> r.Top).ToList();
}
【讨论】: