0

I am trying to undistort a fisheye image using OpenCV. I already calibrated the camera, and also getting a decent undistorted image using the following code (I just posted the relevant part):

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()

Now I have to crop the fisheye image like this: Photo from wikipedia enter image description here

These photos are only for demonstration purposes. I used the mapping function of a fisheye lens to determine the point where I crop at the right side. However, if I use the same code as above (and same camera matrix), the output is a really weird distorted picture.

I have also thought about first undistorting and then cropping, however I am not able to calculate exactly the point I have to crop in this way. So I have to crop the image first.

So how do I correctly undistort a not symmetrically cropped fisheye image?

rfn123
  • 151
  • 3
  • 12

1 Answers1

0

When you move and crop the image, the fish camera calibration parameters are not fit to the new camera.

May be you could try to make the iamge symmetrical by padding zero values. The point is to make the center point of both images at the same position.

Reference:

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/