How to find the orientation of an object (shape)? - Python Opencv

后端 未结 2 1554
庸人自扰
庸人自扰 2021-01-03 09:05

My images are always like this:

But I need to rotate them to be like this:

But to do that, I need to find the orientation of the object, knowing

2条回答
  •  忘掉有多难
    2021-01-03 09:25

    You have to compute the main axis (it is based on PCA). It will give you a good idea of the main orientation, then you can rotate your image accordingly.

    As it was pointed as a comment, you now have to test that the thin part is on the right side of the image, and for that you use the centroid/barycenter: if the centroid is on the left of the bounding box, then the wing is well oriented.

    Here is the complete algorithm:

    • Compute the main orientation (main axis, computed with PCA)
    • Rotate your image according to the main axis orientation.
    • Compute the bounding box and centroid/barycenter
    • If the centroid is on the left, then your image is well oriented, else rotate it about 180°.

    Here are the results...

提交回复
热议问题