我使用Matlab做了双目标定,然后把标定后的参数拿到opencv里做双目视觉,可是测的点云在左相机坐标系下的距离都是固定在500mm左右,不管是距离300mm还是1m都是这个结果。而且背景和物体都是显示500mm左右的距离。也就是差不多在一个平面上。
imgL = cv2.imread("testleft09.bmp")
imgR = cv2.imread("testright09.bmp")
height, width = imgL.shape[0:2]
# 读取相机内参和外参
config = stereoconfig.stereoCameral()
map1x, map1y, map2x, map2y, Q = getRectifyTransform(height, width, config)
print(Q)
iml_rectified, imr_rectified = rectifyImage(imgL, imgR, map1x, map1y, map2x, map2y)
cv2.imwrite("iml_rectified.bmp",iml_rectified)
cv2.imwrite("imr_rectified.bmp",imr_rectified)
imglr=draw_line(iml_rectified, imr_rectified)
imglr=cv2.resize(imglr,[1280,480])
cv2.imshow("imglr", imglr)
disp,stereo= sgbm(iml_rectified, imr_rectified) #生成视差图
points_3d = cv2.reprojectImageTo3D(disp, Q) # 计算像素点的3D坐标(左相机坐标系下)
print(disp.max(),disp.min())
#保存点云数据
colors = cv2.cvtColor(iml_rectified, cv2.COLOR_BGR2RGB)
mask = disp > disp.min()
out_points = points_3d[mask]
out_colors = colors[mask]
out_fn = 'out.ply'
write_ply(out_fn, out_points, out_colors)
print('%s saved' % out_fn)
我希望能测量出正确的距离,而不是物体和背景的距离一样。
matlab和opencv坐标系不一样
或者你把左右弄反了