Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to obtain the scale and rotation angle from LogPolar transform
    primarykey
    data
    text
    <p>I'm trying to use LogPolar transform to obtain the scale and the rotation angle from two images. Below are two 300x300 sample images. The first rectangle is 100x100, and the second rectangle is 150x150, rotated by 45 degree. </p> <p><img src="https://i.stack.imgur.com/i5Es6.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/w3Kmx.png" alt="enter image description here"></p> <p>The algorithm:</p> <ol> <li>Convert both images to LogPolar.</li> <li>Find the translational shift using Phase Correlation.</li> <li>Convert the translational shift to scale and rotation angle (how to do this?).</li> </ol> <p>My code:</p> <pre><code>#include &lt;opencv2/imgproc/imgproc.hpp&gt; #include &lt;opencv2/imgproc/imgproc_c.h&gt; #include &lt;opencv2/highgui/highgui.hpp&gt; #include &lt;iostream&gt; int main() { cv::Mat a = cv::imread("rect1.png", 0); cv::Mat b = cv::imread("rect2.png", 0); if (a.empty() || b.empty()) return -1; cv::imshow("a", a); cv::imshow("b", b); cv::Mat pa = cv::Mat::zeros(a.size(), CV_8UC1); cv::Mat pb = cv::Mat::zeros(b.size(), CV_8UC1); IplImage ipl_a = a, ipl_pa = pa; IplImage ipl_b = b, ipl_pb = pb; cvLogPolar(&amp;ipl_a, &amp;ipl_pa, cvPoint2D32f(a.cols &gt;&gt; 1, a.rows &gt;&gt; 1), 40); cvLogPolar(&amp;ipl_b, &amp;ipl_pb, cvPoint2D32f(b.cols &gt;&gt; 1, b.rows &gt;&gt; 1), 40); cv::imshow("logpolar a", pa); cv::imshow("logpolar b", pb); cv::Mat pa_64f, pb_64f; pa.convertTo(pa_64f, CV_64F); pb.convertTo(pb_64f, CV_64F); cv::Point2d pt = cv::phaseCorrelate(pa_64f, pb_64f); std::cout &lt;&lt; "Shift = " &lt;&lt; pt &lt;&lt; "Rotation = " &lt;&lt; cv::format("%.2f", pt.y*180/(a.cols &gt;&gt; 1)) &lt;&lt; std::endl; cv::waitKey(0); return 0; } </code></pre> <p>The log polar images:</p> <p><img src="https://i.stack.imgur.com/WNgUH.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/cScXx.png" alt="enter image description here"></p> <p>For the sample image images above, the translational shift is <code>(16.2986, 36.9105)</code>. I have successfully obtain the rotation angle, which is <code>44.29</code>. But I have difficulty in calculating the scale. How to convert the given translational shift to obtain the scale?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload