问题描述
在处理 OpenCV
的拼接过程时,我认为将点从拼接图像映射到原始图像,反之亦然。这些点可以是任意点。 AffineWarper 有两个我们感兴趣的成员函数:warp 和 warpPoint。前者会根据 K
和 H
扭曲图像,而后者会根据上述矩阵扭曲点。
假设这两个函数会类似地扭曲是合理的。但是,我从这些函数中得到了奇怪的结果。为了重现结果,您可以使用以下代码。在下面的代码中,我随意创建了 K
和 H
。为了说明这一点,我从图像中选择了一个点,例如 (504,298)
,并在原始图像上显示了该点。然后我分别对Image和Point进行了翘曲,并在翘曲的图像上显示出翘曲点,但不幸的是,翘曲点的位置与原始位置不一样。(为了让你更容易重现结果,我有使用 CMake 创建了一个 github 项目,您可以通过 clicking here)
#include "opencv2/opencv_modules.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/timelapsers.hpp"
#include "opencv2/stitching/detail/camera.hpp"
#include "opencv2/stitching/detail/exposure_compensate.hpp"
#include "opencv2/stitching/detail/matchers.hpp"
#include "opencv2/stitching/detail/motion_estimators.hpp"
#include "opencv2/stitching/detail/seam_finders.hpp"
#include "opencv2/stitching/detail/warpers.hpp"
#include "opencv2/stitching/warpers.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::detail;
float data_k[9] = { 1.2341799f,1.2341799f,1 };
float data_R[9] = { 0.97279942f,0.033378981f,-78.555443f,-0.033378981f,0.97279942,195.70378,1 };
Ptr <RotationWarper> initializeData(Mat&K,Mat&R,Ptr <WarperCreator> warper_creator);
int main(int argc,char *argv[])
{
cv::Mat img = cv::imread("4.jpg");
cv::Mat K(3,3,CV_32F),R;
//prepare data and warper
Ptr <WarperCreator> warper_creator = makePtr <cv::AffineWarper>();
Ptr <RotationWarper> warper = initializeData(K,R,warper_creator);
//do warper on the original image
cv::Mat img_warped;
cv::Point dst_roi = warper->warp(img,K,INTER_CUBIC,BORDER_CONSTANT,img_warped);
//plot a point in original image
cv::Point2f p(504,298);
cv::circle(img,p,6,cv::Scalar(255,255,0),cv::FILLED);
//warp the point to the new image
cv::Point2f p2 = warper->warpPoint(p,R);
p2.x -= dst_roi.x;
p2.y -= dst_roi.y;
cv::circle(img_warped,p2,cv::FILLED);
//plot images
cv::imshow("image",img);
cv::imshow("warped",img_warped);
cv::waitKey(0);
}
Ptr <RotationWarper> initializeData(Mat&K,Ptr <WarperCreator> warper_creator)
{
K = cv::Mat(3,CV_32F,data_k);
R = cv::Mat(3,data_R);
float warped_image_scale = 1;
float seam_work_aspect = 1.2;
return(warper_creator->create(static_cast <float>(warped_image_scale * seam_work_aspect)));
}
在原图像上显示选中的点
在扭曲图像上显示扭曲点。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)