I have the situation that I have a small binary image that has one shape, around which I want to find the best fitting rotated rectangle (not b
If understand the problem correctly, you're saying the method of using findContours
and minAreaRect
suffers from jitter/wobbling due to the noisy input data. PCA is not more robust against this noise, so I don't see why you think finding the orientation of the pattern this way won't be as bad as your current code.
If you need temporal smoothness a commonly used and simple solution is to use a filter, even a very simple filter like an alpha-beta filter probably gives you the smoothness you want. Say at frame n
you estimate the parameters of the rotated rectangle A
, and in frame n+1
you have the rectangle with the estimated parameters B
. Instead of drawing the rectangle with B
you find C
which is between A
and B
, and then draw a rectangle with C
in frame n+1
.