Answer the question
In order to leave comments, you need to log in
Finding the shift of one image relative to another?
Two photographs are given, one was taken from a shifted and rotated angle (the displacement vector and the rotation angle are assumed not to be too large). It is required to find the displacement vector and rotation angles.
The answer for the case when there is no rotation is also interesting.
Which way to look, what to read? Whether it is possible to implement through search of special points on images?
Answer the question
In order to leave comments, you need to log in
I won’t tell you about OpenCV, but I would write it manually. The idea is simple: We set a function that checks the truth (more precisely, its inverse value, such as "falsity") of the hypothesis that the second image is the first image, shifted along the axes exactly by the X, Y values. This function is calculated (for example) as the sum of the squared differences of the values of the corresponding pixels the first image and the second one shifted by -X, -Y. Having such a function, then we simply find its minimum using the gradient descent method (initial values X=0, Y=0), the obtained X, Y will be the calculated offset values of the second image from the first.
With rotation, everything is similar, only one more variable is added - the degree of rotation. But the hypothesis testing function becomes much more computationally difficult: at least one trigonometric function will go to each pixel (relatively heavy for the CPU), plus this breaks off the SIMD optimization, which gives a multiple speedup for the first variant without rotation.
In OpenCV there is a phaseCorrelate output to get the offset direction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question