我目前正在按照此 https://stereopi.com/blog/opencv-and-depth-map-stereopi-tutorial 指南创建立体视觉相机。我已经到了 Step3 并且能够拍摄图像并将它们分成左右图像。然而,在我校准后的第 4 步中,校正后的图像看起来非常奇怪,正确的图像完全是黑色的。我附上了下面的代码(StereoPi 的学分),以及导入了很多类的stereovision.calibration 文件的代码。我已经根据我的棋盘修改了行/列/square_size,所以我真的不确定问题出在哪里。
校准python脚本(主要)
import os
import cv2
import numpy as np
import json
from ss import StereoCalibrator
from stereovision.calibration import StereoCalibration
from stereovision.exceptions import ChessboardNotFoundError
# Global variables preset
total_photos = 30
photo_width = 640
photo_height = 240
img_width = 320
img_height = 240
image_size = (img_width, img_height)
# Chessboard parameters
# Very important to change these parameters depending on the ChessBoard image used! Count number of squares - 1 is equals to row and columns
rows = 7
columns = 9
square_size = 2
calibrator = StereoCalibrator(rows, columns, square_size, image_size)
photo_counter = 0
print('Start cycle')
while photo_counter != total_photos:
photo_counter = photo_counter + 1
print('Import pair No ' + str(photo_counter))
leftName = './pairs/left_' + str(photo_counter).zfill(2) + '.png'
rightName = './pairs/right_' + str(photo_counter).zfill(2) + '.png'
if os.path.isfile(leftName) and os.path.isfile(rightName):
imgLeft = cv2.imread(leftName, 1)
print(type(imgLeft))
imgRight = cv2.imread(rightName, 1)
try:
calibrator._get_corners(imgLeft)
calibrator._get_corners(imgRight)
except ChessboardNotFoundError as error:
print(error)
print("Pair No " + str(photo_counter) + " ignored")
else:
calibrator.add_corners((imgLeft, imgRight), True)
print('End cycle')
print('Starting calibration... It can take several minutes!')
calibration = calibrator.calibrate_cameras()
calibration.export('calib_result')
print('Calibration complete!')
# Lets rectify and show last pair after calibration
calibration = StereoCalibration(input_folder='calib_result')
rectified_pair = calibration.rectify((imgLeft, imgRight))
cv2.imshow('Left CALIBRATED', rectified_pair[0])
cv2.imshow('Right CALIBRATED', rectified_pair[1])
cv2.imwrite("rectifyed_left.jpg", rectified_pair[0])
cv2.imwrite("rectifyed_right.jpg", rectified_pair[1])
cv2.waitKey(0)
stereo.calibration python 脚本(正在导入): http://erget.github.io/StereoVision/_modules/stereovision/calibration.html