我有一张从相机以180度角失真拍摄的照片。现在我不知道什么是相机校准值,而只有镜头畸变角,即180度。通常可以是180度,160度,140度和120度。下图为180度。如何使用OpenCV校正图像?
Below code is also available in Google Collab to quicky check 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()
使用OpenCV纠正技术是正确的方法吗?我看到了信息丢失的情况,请检查图像上方和下方,未失真的图像仅包含信息。上面的技术对吗?