0

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? enter image description here

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

corrected image

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?

ajayramesh
  • 3,576
  • 8
  • 50
  • 75
  • 1
    Given that undistorting your image is unlikely to happen completely by chance, maybe searching for similar questions would help: have you tried that? I tried searching for _opencv estimate lens image correction_ and without too much difficulty I found e.g. https://stackoverflow.com/questions/26602981/correct-barrel-distortion-in-opencv-manually-without-chessboard-image - what reseach have you already done? – DisappointedByUnaccountableMod Aug 06 '19 at 21:20
  • Or this https://stackoverflow.com/questions/2477774/correcting-fisheye-distortion-programmatically - i.e. the best thing you can do is just *search* - i.e. go out and look for answers rather than sit back and wait for them – DisappointedByUnaccountableMod Aug 06 '19 at 21:27
  • Agree, the post is updated based on research on estimating the camera parameters. I [followed](https://medium.com/@kennethjiang/calibrate-fisheye-lens-using-opencv-333b05afa0b0) article. However, I am not sure why I am getting loss of information. – ajayramesh Aug 07 '19 at 18:13

0 Answers0