我目前正在按照这个{a1}指南创建立体视觉相机。我已经到了第三步,能够拍摄图像并将其分为左右图像。然而,在我校准后的第4步中,校正后的图像看起来非常奇怪,右边的图像完全是黑色的。我已经附上了下面的代码(归功于StereoPi),以及stereovision.calibration文件的代码,其中导入了很多类。我已经根据我的棋盘修改了行/列/方格大小,所以我真的不确定问题出在哪里
校准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.python脚本(正在导入):http://erget.github.io/StereoVision/_modules/stereovision/calibration.html
目前没有回答
相关问题 更多 >
编程相关推荐