Answer the question
In order to leave comments, you need to log in
How to find the rotation angle of an object (computer graphics)?
Task:
Given two pictures img1 and img2 , which depict the object under study.
The object on img1 was rotated by an arbitrary angle around an arbitrary point belonging to this object.
The result is an img2 image .
The boundaries of objects (before and after) we can calculate and they will be given by a set of points (x, y).
Question:
Is it possible to find the point around which the rotation was made and the angle of rotation?
The pivot point always belongs to the object in the img1 image.
There is no translation and scaling, only rotation.
Inside the investigated object, the information is minimal, so it is possible to explore only the boundaries.
Example:
Img1 - before
Img2 - after
Result
Answer the question
In order to leave comments, you need to log in
1) build boundaries G1, G2.
2) count for each:
- center of mass (x0,y0)
- three integrals: a11=int((x-x0)^2), a12=a21=int((x-x0)*(y-y0)), a22=int((y-y0)^2)
- eigenvalues m1,m2 (m1 < m2) and eigenvectors v1,v2 of the matrix ((a11 a12) (a21 a22)).
Let this be calculated for G1, and for G2 it turns out m1', m2', v1', v2'.
If there is no distortion during rotation, then m1=m1', m2=m2'. The angle of rotation is determined by the angle z between v1 and v1' (but you have to figure out which way). Unfortunately, it is defined with an accuracy of 180 degrees - so you will have to somehow compare the options for turning to z and to z + 180, and choose the best one. Let's say it's z.
It remains to find a point, when turning around it through the angle z the point (x0,y0) passes into (x0',y0'). The easiest way to write this is in complex numbers: p0=x0+i*y0, p1=x0'+i*y0', f=exp(i*z). If the desired center is c, then f*(p0-c)=p1-c, whence c=(p1-f*p0)/(1-f).
And that's it. Nothing complicated, the first course of anhem...
If you can find the coordinates of a pair of points on the specified axes - you can try to calculate through the scalar product of vectors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question