OpenCV鱼眼校准会剪切掉太多的结果图像 [英] OpenCV fisheye calibration cuts too much of the resulting image

查看:957
本文介绍了OpenCV鱼眼校准会剪切掉太多的结果图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenCV校准使用带鱼眼镜头的相机拍摄的图像.

I am using OpenCV to calibrate images taken using cameras with fish-eye lenses.

我正在使用的功能是:

  • findChessboardCorners(...);查找校准图案的角.
  • cornerSubPix(...);细化找到的角.
  • fisheye::calibrate(...);用于校准相机矩阵和失真系数.
  • fisheye::undistortImage(...);使用从校准获得的相机信息使图像不失真.
  • findChessboardCorners(...); to find the corners of the calibration pattern.
  • cornerSubPix(...); to refine the found corners.
  • fisheye::calibrate(...); to calibrate the camera matrix and the distortion coefficients.
  • fisheye::undistortImage(...); to undistort the images using the camera info obtained from calibration.

虽然生成的图像看起来确实不错(直线等),但我的问题是该功能切除了太多图像.

While the resulting image does appear to look good (straight lines and so on), my issue is that the function cut away too much of the image.

这是一个实际的问题,因为我使用的是四台相机,两台相机之间呈90度角,并且当切掉太多的侧面时,在我要拼接图像时,它们之间没有重叠的区域

This is a real problem, as I am using four cameras with 90 degrees between them, and when so much of the sides are cut off, there is no overlapping area between them which is needed as I am going to stitch the images.

我研究了使用fisheye::estimateNewCameraMatrixForUndistortRectify(...)的方法,但无法获得良好的结果,因为我不知道应该输入R的内容,因为fisheye::calibrate的旋转矢量输出为3xN(其中N是校准图像的数量),fisheye::estimateNewCameraMatrixForUndistortRectify需要1x3或3x3.

I looked into using fisheye::estimateNewCameraMatrixForUndistortRectify(...) but I could not get it to give good results, as I do not know what I should put in as the R input, as the rotation vector output of fisheye::calibrate is 3xN (where N is the number of calibration images) and fisheye::estimateNewCameraMatrixForUndistortRectify requires a 1x3 or 3x3.

下面的图像显示了我的未失真结果的图像,以及我理想中想要的结果类型的示例.

The images below show an image of my undistortion result, and an example of the kind of result I would ideally want.

不失真:

想要的结果示例:

推荐答案

我认为我也遇到了类似的问题,正在getOptimalNewCameraMatrix中寻找鱼眼"的"alpha"结.

I think I have ran into a similar issue, looking for the "alpha" knot in getOptimalNewCameraMatrix for fisheye.

原始照片:

我用cv2.fisheye.calibrate对其进行了校准,得到了K和D参数

I calibrated it with cv2.fisheye.calibrate, got the K and D parameters

K = [[ 329.75951163    0.          422.36510555]
 [   0.          329.84897388  266.45855056]
 [   0.            0.            1.        ]]

D = [[ 0.04004325]
 [ 0.00112638]
 [ 0.01004722]
 [-0.00593285]]

这就是我所得到的

map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, d, np.eye(3), k, (800,600), cv2.CV_16SC2)
nemImg = cv2.remap( img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)

我认为它砍得太多了.我想看整个魔方

And I think it chops too much. I want to see the whole Rubik's cube

我用

nk = k.copy()
nk[0,0]=k[0,0]/2
nk[1,1]=k[1,1]/2
# Just by scaling the matrix coefficients!

map1, map2 = cv2.fisheye.initUndistortRectifyMap(k, d, np.eye(3), nk, (800,600), cv2.CV_16SC2)  # Pass k in 1st parameter, nk in 4th parameter
nemImg = cv2.remap( img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)

TADA!

这篇关于OpenCV鱼眼校准会剪切掉太多的结果图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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