2017-05-04 289 views
0

我试图用OpenCV不扭曲鱼眼图像。我已校准的摄像头,并且还使用下面的代码得到一个体面的不失真的图像(我刚刚发布的相关部分):如何使用OpenCV无畸变裁剪鱼眼图像

img = cv2.imread('img.jpeg') #image path of pic to distort 
h,w = img.shape[:2] 

Knew = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K,D,(w,h),None) 
Knew[(0,1), (0,1)] = .3* Knew[(0,1), (0,1)] 

mapx, mapy = cv2.fisheye.initUndistortRectifyMap(K,D,None,Knew,(w,h),5) 
img_undistorted = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR) 

cv2.imshow('undistorted', img_undistorted) 
cv2.waitKey(0) 
cv2.destroyAllWindows() 

现在我必须裁剪这样的鱼眼图像: Photo from wikipedia enter image description here

这些照片仅用于演示目的。 我使用鱼眼镜头的映射功能来确定我在右侧裁剪的点。但是,如果我使用与上述相同的代码(和相同的相机矩阵),则输出是非常奇怪的失真图片。

我也曾经想过首先不扭曲然后裁剪,但是我不能准确计算出我必须以这种方式裁剪的点。所以我必须先裁剪图像。

那么我该如何正确unistort不对称裁剪鱼眼图像?

回答

0

当您移动并剪裁图像时,鱼相机校准参数不适合新相机。

也许你可以尝试通过填充零值来使iamge对称。 重点是使两个图像的中心点位于相同的位置。

参考:

http://docs.opencv.org/3.0-beta/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#fisheye-estimatenewcameramatrixforundistortrectify

http://answers.opencv.org/question/64614/fisheyeundistortimage-doesnt-work-what-wrong-with-my-code/

+0

所以你的意思是我应该作物的“填写”内的黑像素的裁剪区域的图像,但那种? – sybilcut

+0

这是我会尝试的。 –

+0

它没有为我工作:(我只是尝试调整一些其他参数,然后...... – sybilcut