I faced with difficulties when trying to get result similar to this. After camera calibration I obtained the following parameters:
DIM=(800, 600)
K=np.array([[177.41548430658207, 0.0, 258.68599972062486], [0.0, 177.57591422482173, 205.71268583567885], [0.0, 0.0, 1.0]])
D=np.array([[-0.04397357230351177], [-0.03399404486757072], [0.03174104028771482], [-0.01131815456157867]])
My initial fish-eye image looks like this.
With the following code:
def undistort(img_path):
img = cv2.imread(img_path)
nk = K.copy()
nk[0,0]=K[0,0]
nk[1,1]=K[1,1]
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), nk, DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap( img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
cv2.imshow("undistorted", undistorted_img)
cv2.imwrite('recoPersp_wrong.jpg', undistorted_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
reconstructed perspective image looks like this. However by changing:
nk[0,0]=K[0,0]
nk[1,1]=K[1,1]
to
nk[0,0]=K[0,0]/2
nk[1,1]=K[1,1]/2
I don't get desired result as described by Hello Sam's answer. Instead my image is blurred and smeared on the edges like this (it is different image but still the same problem) Could you please tell me what am I doing wrong?