如何使用“keySelector” for“OrderBy()”函数用于在openCV中对轮廓进行排序 [英] How to use "keySelector" for "OrderBy()"function for sorting contours in openCV
本文介绍了如何使用“keySelector” for“OrderBy()”函数用于在openCV中对轮廓进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要在二进制图像中找到N个最大区域轮廓
。 br />
我想尝试 OrderBy()
函数按区域排序轮廓。
但是,我无法理解 keySelector
的语法用作中的参数OrderBy()
虽然我使用的是EmguCV,但C ++语法也很有帮助。
Hello all,
I need to find N largest area contours
available in a binary image.
I wanted to try the OrderBy()
function to sort the contours by Area.
However, I am unable to understand the the syntax for keySelector
used as a parameter in OrderBy()
Although I am using EmguCV, but a C++ syntax will also be helpful.
Contour<Point> contours = inputImage.FindContours();
contours.Orderby( ???? ); // OrderBy(Func<Point,TKey> keySelector)
非常感谢任何帮助。
Any help is much appreciated.
推荐答案
您好。
您应该注意,在您的代码中 - 您将只获得一个轮廓。
为了您的目的,您应该握紧所有轮廓,然后命令它们。
检查此代码:
Hello.
You should notice, that in your code - you will get only one contour.
For your purpose you should fistly get all contours, and after that order them.
Check this code:
var allContours = new List<Contour<Point>>();
for (var contours = image.FindContours(); contours != null; contours = contours.HNext)
allContours.Add(contours);
allContours.OrderBy(x => x.Area); // by ascending
allContours.OrderByDescending(x => x.Area); // by descending
这篇关于如何使用“keySelector” for“OrderBy()”函数用于在openCV中对轮廓进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文