F
F
Father42021-06-12 00:50:36
OpenCV
Father4, 2021-06-12 00:50:36

How to determine the angle of the image?

Hello. There are several images with such objects.
60c3da130b031483084680.png
Task: determine the angle of inclination. I've read a bunch of manuals but nothing works.
Maybe someone has experience?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
U235U235, 2021-06-29
@U235U235

Outlines are not needed. Simply convert the image to black and white so that the object is white and the background is black. Next, call the cv2.fitLine function, take the arc tangent from its results, and that's it, the angle is obtained.

R
rPman, 2021-06-12
@rPman

What is an angle of inclination?
To answer this question, you need to understand where is the top / bottom and where is the side, and this, as you understand, depends on what exactly is depicted.
If the images are exactly the same as in the question, then the zero position can be determined by the length (length) of the object. We are looking for the findContours contour and find two points of the contour, the distance between which is maximum, this segment can be considered a line, the angle of which is considered.
You can also calculate the linear regression of all points of the object (no need to calculate its contour) to the line, and already calculate its angle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question