Ask Your Question
0

How to Undistort fisheye image into max bounding rectangle?

asked 2019-10-28 11:24:48 -0500

JeyP4 gravatar image

updated 2019-10-28 14:27:47 -0500

image description

I have calibrated camera with cv2.fisheye.calibrate with images of size 720x1280. Python script

K = 
array([[541.11407173,   0.        , 659.87320043],
       [  0.        , 541.28079025, 318.68920531],
       [  0.        ,   0.        ,   1.        ]])
D =
array([[-3.91414244e-02],
       [-4.60198728e-03],
       [-3.02912651e-04],
       [ 2.83586453e-05]])

And performed un-distortion with

new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, D, (1280, 720), np.eye(3), balance=1)
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), new_K, (1280, 720), cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT)

image description

How can I achieve max obtainable rectangular image?

If I directly crop this image, quality deteriotes :(

I guess I have to play with balance, new_size, fov_scale properties of estimateNewCameraMatrixForUndistortRectify(). And also some properties of initUndistortRectifyMap().

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-10-30 11:54:17 -0500

JeyP4 gravatar image
new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(K, D, (1280, 720), np.eye(3), balance=1, new_size=(3400, 1912), fov_scale=1)

map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), new_K, (3400, 1912), cv2.CV_16SC2)

undistorted_img = cv2.remap(img, map1[575:1295, 23:3119, :], map2[575:1295, 23:3119], interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-10-28 11:24:48 -0500

Seen: 588 times

Last updated: Oct 30 '19