Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted

1 solution

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:

C#
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
 
Share this answer
 
v2
Comments
Abhishrek 29-Jul-15 0:02am    
Hello Artem, I am very very thankful for your quick reply. You are the best !!
Another thanks for introducing me the Lambda Operator. I didn't know about it.
спасибо

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900