使用initUndistortRectifyMap取消扭曲图像点 [英] using initUndistortRectifyMap to undistort image points

查看:223
本文介绍了使用initUndistortRectifyMap取消扭曲图像点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在该应用程序中,我经常需要将像素位置偏移到其正确"位置.

I have an application where I constantly have to undistort pixel positions to their "right" location.

我首先在Python中尝试过,下面的代码会产生良好的结果:

I tried it in Python first, thw following code yields good results:

cam_m=np.array([[2590.2742, 0, 997.78192],[0, 2582.9724, 509.76907],[0, 0, 1]])
dist_c=np.array([0.088253155, 0.96952456, 0.0033740622, -0.00064934365, -6.0030732])
map1,map2=cv2.initUndistortRectifyMap(cam_m, dist_c, None, None, (1920,1024), cv2.CV_32FC1)

当我尝试将其转换为C ++时,它只是返回废话.我在打电话:

When I tried to convert that into C++ it's just returning crap. I'm calling:

cv::initUndistortRectifyMap(this->m_cameraMatrix,this->m_distortionCoeffs, 
         cv::Mat::eye(3, 3, CV_32FC1),cv::Mat::eye(3, 3, CV_32FC1),
         cv::Size(dimX,dimY),CV_32FC1,this->m_undistortMapX,this->m_undistortMapY);

但是在地图中,它返回的值是大的,当我输出m_undistortMapX时,它包含的值约为-2.0e + 21. this->m_undistortMapXthis->m_undistortMapY在类中声明,并且之前未初始化.其他参数也看起来正确:

But in the maps it returns values which are way to big, when I output m_undistortMapX it contains values of about -2.0e+21 . this->m_undistortMapX and this->m_undistortMapY are declared in the class and not initialized before. The other parameters look right, too:

std::cout  << this->m_cameraMatrix << std::endl;
std::cout  << this->m_distortionCoeffs << std::endl;
std::cout << dimX <<" / "<<dimY<<std::endl;

输出

[2590.2742, 0, 997.78192;
0, 2582.9724, 509.76907;
0, 0, 1]
[0.088253155, 0.96952456, 0.0033740622, -0.00064934365, -6.0030732]
1920 / 1024

我想和Python一样.有什么想法仍然会出错吗?!

So just the same as in Python, I thought. Any ideas what can still go wrong?!

推荐答案

我遇到了类似的问题,偶然发现了您的问题,所以也许这可以对某人有所帮助.另一个答案提供了可行的解决方案,但没有解释出什么问题.

I was having a similar issue and stumbled on your question, so maybe this can help someone. The other answer provides a working solution, but does not explain whats wrong.

在CPP版本中,您为P矩阵提供了None/Identity矩阵,出于某种原因,尽管OpenCV会生成垃圾(生成的地图将使用1 f.e.的焦距),但出于某些原因,它在OpenCV中被允许.我将尝试看看是否可以在OpenCV中解决此问题.

In the CPP version you are providing None/Identity matrix for the P matrix, which for some reason is allowed in OpenCV, although it will generate garbage (the generated map will use focal lengths of 1 f.e.). I'll try to see if I can get this fixed in OpenCV.

我无法评论为什么python版本适合您,特别是由于自2017年以来OpenCV python绑定中发生的更改.

I can't comment on why the python version worked for you, especially due to the changes that happened in the OpenCV python bindings since 2017.

这篇关于使用initUndistortRectifyMap取消扭曲图像点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆