Crop The Largest Rectangle Using Opencv
Solution 1:
So what you want to do at this point is sort the squares list for area.
If you are not worried about the efficiency or complexity of your algorithm (though you probably should be), you can simply add a line before you add the aprox to squares that calculates the contour area for your current approx. Then, have a loop that checks the contour area of an index in squares until it reaches either the end of squares or an element in squares where the area of your current contour is greater than the area in the contour at that index. This is called a selection sort, and while it is simple and slow, it does work.
If you are interested in earning further, sorting is a very interesting concept in computer science. For more efficient ways to sort your squares array, do some reading on heapsort, mergesort, and quicksort. You can learn the basics of sorting here
Good Luck!
Post a Comment for "Crop The Largest Rectangle Using Opencv"