本文介绍了如何从LogPolar变换获取比例和旋转角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图使用LogPolar变换来从两个图像获得比例和旋转角度。以下是两个300x300样本图片。第一个矩形是100x100,第二个矩形是150x150,旋转45度。 算法: 将两张图片转换为LogPolar。 使用相位相关查找平移。 将平移转换转换为比例和旋转角度(如何操作。) 我的代码: p> #include< opencv2 / imgproc / imgproc.hpp> #include< opencv2 / imgproc / imgproc_c.h> #include< opencv2 / highgui / highgui.hpp> #include< iostream> 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(& ipl_a,& ipl_pa,cvPoint2D32f(a.cols>> 1,a.rows>> 1),40); cvLogPolar(& ipl_b,& ipl_pb,cvPoint2D32f(b.cols>> 1,b.rows>> 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<< Shift =<< pt < Rotation =< cv :: format(%。2f,pt.y * 180 /(a.cols>> 1))< std :: endl; cv :: waitKey(0); return 0; } 日志极性图片: > 对于上面的示例图像图像,平移位移是 (16.2986,36.9105)。我已经成功获得旋转角度,这是 44.29 。但我在计算比例时有困难。如何转换给定的平移以获得量表?解决方案 这里是python版本 它告诉 ir = abs(ifft2((f0 * f1.conjugate())/ r0)) i0,i1 = numpy.unravel_index (numpy.argmax(ir),ir.shape) angle = 180.0 * i0 / ir.shape [0] scale = log_base ** i1 / pre> 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.The algorithm:Convert both images to LogPolar.Find the translational shift using Phase Correlation.Convert the translational shift to scale and rotation angle (how to do this?).My code:#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/imgproc/imgproc_c.h>#include <opencv2/highgui/highgui.hpp>#include <iostream>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(&ipl_a, &ipl_pa, cvPoint2D32f(a.cols >> 1, a.rows >> 1), 40); cvLogPolar(&ipl_b, &ipl_pb, cvPoint2D32f(b.cols >> 1, b.rows >> 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 << "Shift = " << pt << "Rotation = " << cv::format("%.2f", pt.y*180/(a.cols >> 1)) << std::endl; cv::waitKey(0); return 0;}The log polar images:For the sample image images above, the translational shift is (16.2986, 36.9105). I have successfully obtain the rotation angle, which is 44.29. But I have difficulty in calculating the scale. How to convert the given translational shift to obtain the scale? 解决方案 here is python versionwhich tells ir = abs(ifft2((f0 * f1.conjugate()) / r0)) i0, i1 = numpy.unravel_index(numpy.argmax(ir), ir.shape) angle = 180.0 * i0 / ir.shape[0] scale = log_base ** i1 这篇关于如何从LogPolar变换获取比例和旋转角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 12:19