I have a picture which is taken from a camera at 180-degree angle distortion. Now I don't know what are camera calibrate values, but only lens distortion angle i.e., 180. Typically it can be 180, 160, 140 and 120 degrees. Below image is 180 degree. How to correct the image using OpenCV?
Below code is also available in Google Collab to quicky check it
update
After going through some of the articles, I found a way to estimate camera calibrated matrix. Please find below code, and output of it.
import cv2
import numpy as np
from matplotlib import pyplot as plt
import cv2
!curl -o sample.png https://i.stack.imgur.com/GnmPZ.jpg
img = cv2.imread('sample.png' , cv2.COLOR_BGR2GRAY)
DIM=(1920, 1080)
K=np.array([[398.1857242569939, 0.0, 963.3984478620766], [0.0, 396.103047637193, 537.6190158807337], [0.0, 0.0, 1.0]])
D=np.array([[0.17682834817555731], [0.009067092657290292], [0.029294074625554698], [-0.02216486600536073]])
def undistort(img):
h,w = img.shape[:2]
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
return undistorted_img
fig, (oldimg_ax, newimg_ax) = plt.subplots(1, 2)
oldimg_ax.imshow(img)
oldimg_ax.set_title('Original image')
newimg_ax.imshow(undistort(img))
newimg_ax.set_title('Corrected image')
plt.show()
Above corrected technique using OpenCV is the right way to doing it? I see the loss of information, please check above and below image, the undistorted image just has information. Above technique is right?