Reputation: 189464
I'm using the Python OpenCV bindings to find the contours in an Image. I'm know looking for the possibility to sort this sequence.
It seems the usual python ways for list sorting don't apply here because of the linked list structure generated from OpenCV.
Do you know a good way to sort the Contours by Size (Area/BoundingRectangle) in python? Is it possible to give some example code?
Upvotes: 1
Views: 1735
Reputation: 26271
You have to be able to look at an entire sequence in order to sort it (easily). Thus you should copy it to sort it.
I would do something like
contourList = list(<your linked list>)
def sizeKey(countour):
<get size from contour>
contourList.sort(key = sizeKey)
If everything is not being stored in memory already you can also look at external sorting algorithms.
Upvotes: 2