Are there a limited rotating rectangle suitable for the case when the orientation of the contour differs, for example, by 180 degrees?
Another way to solve your problem is to calculate the moments of the contours (I suppose you use the contours in cvMatchShapes, you can also calculate the moments of the image in the same way) OpenCV contour moments? , and then calculates the principal angle of the axes using the formula:
atan2((float)(-2)*Ixy,Ix - Iy)/2
. : http://farside.ph.utexas.edu/teaching/336k/newton/node67.html