Question

I want to time-smooth a simple shape contour, as outputted from cv::findContours, over several frames. The easiest way to do that is to motion filter each point individually. However, there is no guaranteed correspondence from points in the contour from frame to frame, so averaging would make the points jump around.

The approach I think I want is to simplify the contour to N evenly-spaced points, and then I can motion filter each point frame-to-frame properly. However, I can't find an opencv contour simplification method that targets a fixed-size contour as output.

I see cv::approxPolyDP, as suggested in other questions, but it does not target a fixed size.

Was it helpful?

Solution 2

Sebastian, thank you for your points. I realized my approach was flawed, and then took an approach based on implicit surfaces.

Video here: https://www.youtube.com/watch?v=RKrylKFUceY

Code here: https://github.com/dustinfreeman/smootour/

OTHER TIPS

First of all such a function doesn't exist in OpenCV.

Secondly it's not as easy done as said. Suppose you would approximate a perfect circle with a "normalized contour" with 4 Point: Where should your algorithm put the points? enter image description here

Granted: In reality you will probably not see such idealized Problems, but you have to be aware of them. (If you would for example always take the first point at the top of the contour, you would have a problem with a star like structure. Your starting point could occiliate between the two top corners of your star.)

tl;dr It's not implemented in OpenCV, probably also because there is no (easy/"correct") way to place the Points consistently

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top