OpenCVstereoCalibrate给出错误“在函数'collectCalibrationData'中,objectPoints应该包含Point3f类型的点的向量的向量”

问题描述

我正在尝试从立体摄像机获取视差图像,但是我在第54行收到此错误消息:

error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/calib3d/src/calibration.cpp:3139: error: (-210:Unsupported format or combination of formats) objectPoints should contain vector of vectors of points of type Point3f in function 'collectCalibrationData'

[EDIT]关于此错误,我已经看到以下答案:python cv2.calibrateCamera throws error: objectPoints should contain vector of vectors of points of type Point3f 但这并不能解决我的问题,因为object_points和image_points的使用方式正确。

图像点:

[[2433.414    819.80554]
 [2436.264   1117.3773 ]
          ...
 [ 956.29877 2928.8433 ]
 [ 955.77747 3234.6638 ]]

Object_points:

[[ 0.        0.        0.      ]
 [ 3.6       0.        0.      ]
           ...
 [25.199999 18.        0.      ]
 [28.8      18.        0.      ]]

这是我到目前为止获得的代码,但是我必须主要从以下示例中接受它:Bad disparity map using StereoBM in OpenCV

我做了一些更改,使其与openCV 3.4.2兼容。

import cv2
import numpy as np
import matplotlib.pyplot as plt

calib_l = cv2.imread("Bilder/Calib1.jpg",cv2.IMREAD_GRAYSCALE)
calib_r = cv2.imread("Bilder/Calib2.jpg",cv2.IMREAD_GRAYSCALE)
imgL = cv2.imread("Bilder/Stereo1.jpg",cv2.IMREAD_GRAYSCALE)
imgR = cv2.imread("Bilder/Stereo2.jpg",cv2.IMREAD_GRAYSCALE)
                    
image_size = calib_l.shape[:2]

pattern_size = 9,6
object_points = np.zeros((np.prod(pattern_size),3),np.float32)
object_points[:,:2] = np.indices(pattern_size).T.reshape(-1,2)

object_points *= 3.6
image_points = {}

#chessboard
ret,corners_l = cv2.findChessboardCorners(calib_l,pattern_size,True)
cv2.cornerSubPix(calib_l,corners_l,(11,11),(-1,-1),(cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,30,0.01))
corners_l = np.float32(corners_l)
image_points["left"] = corners_l.reshape(-1,2)

ret,corners_r = cv2.findChessboardCorners(calib_r,True)
cv2.cornerSubPix(calib_r,corners_r,0.01))
corners_r = np.float32(corners_r)
image_points["right"] = corners_r.reshape(-1,2)

#calibrate
(rect_trans,proj_mats,valid_Boxes,undistortion_maps,rectification_maps) = {},{},{}
criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,100,1e-5)
flags = (cv2.CALIB_FIX_ASPECT_RATIO + cv2.CALIB_ZERO_TANGENT_disT + cv2.CALIB_SAME_FOCAL_LENGTH)

cam_mats = {"left": None,"right": None}
dist_coefs = {"left": None,"right": None}
rot_mat = None
trans_vec = None
e_mat = None
f_mat = None
(ret,cam_mats["left"],dist_coefs["left"],cam_mats["right"],dist_coefs["right"],rot_mat,trans_vec,e_mat,f_mat) = cv2.stereoCalibrate(object_points,image_points["left"],image_points["right"],image_size,f_mat,criteria=criteria,flags=flags)

(rect_trans["left"],rect_trans["right"],proj_mats["left"],proj_mats["right"],disp_to_depth_mat,valid_Boxes["left"],valid_Boxes["right"]) = cv2.stereoRectify(cam_mats["left"],flags=0)
for side in ("left","right"):
    (undistortion_maps[side],rectification_maps[side]) = cv2.initUndistortRectifyMap(cam_mats[side],dist_coefs[side],rect_trans[side],proj_mats[side],cv2.CV_32FC1)

# disparity map
rectified_l = cv2.remap(imgL,undistortion_maps["left"],rectification_maps["left"],cv2.INTER_NEAREST)
rectified_r = cv2.remap(imgR,undistortion_maps["right"],rectification_maps["right"],cv2.INTER_NEAREST)
cv2.imshow("left",rectified_l)
cv2.imshow("right",rectified_r)
stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET,5)
disparity = stereo.compute(rectified_l,rectified_r,disptype=cv2.CV_32F)

plt.subplot(121).imshow(imgL)
plt.subplot(122).imshow(disparity)
plt.show()

这是什么问题?

非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)