【发布时间】:2018-04-15 07:58:04
【问题描述】:
我正在使用鱼眼相机,我想使用 OpenCV 或 Python 中的任何其他库对其进行校准并纠正其桶形失真。我通过不同的图像尝试了使用经典棋盘图案的不同方法。
我一直在遵循这种方法:
# Prepare object points, like (0,0,0), (1,0,0), (2,0,0), ...,(7,5,0)
object_p = np.zeros((self.__ny*self.__nx,3),np.float32)
object_p[:,:2] = np.mgrid[0:self.__nx,0:self.__ny].T.reshape(-1,2) # s,y coordinates
for image_filename in calibration_filenames:
# Read in each image
image = cv2.imread(image_filename)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # RGB is standard in matlibplot
# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# Find the chessboard corners
ret, corners = cv2.findChessboardCorners(gray, (self.__nx, self.__ny), None)
# If found, draw corners
if ret == True:
# Store the corners found in the current image
object_points.append(object_p) # how it should look like
image_points.append(corners) # how it looks like
# Draw and display the corners
cv2.drawChessboardCorners(image, (self.__nx, self.__ny), corners, ret)
plt.figure()
plt.imshow(image)
plt.show()
# Do the calibration
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(object_points, image_points, shape, None, None)
然后这个来纠正我的形象:
cv2.undistort(image, mtx, dist, None, mtx)
主要问题是,虽然某些图像的校正效果很好,但很容易受到相机位置的影响。相机中厘米的变化将导致非常不同的校正(见下文)。
知道如何控制这种缩放效果以显示始终在校正后的图像中保持网格区域吗?
我知道这个问题可能与here 中的问题相似。
【问题讨论】:
标签: python opencv computer-vision