我目前正在设置代码,以便在计算机中使用两台摄像机从立体声摄像机设置的2d点中获取3d点(如果输入错误,请注释我的代码,但这不是问题所在)。我想导入cv.StereoRectify以获取投影矩阵,但是却收到错误消息,该函数在包中找不到。

我想我可能使用了错误的软件包。我已经下载了opencv 4.1的普通版和contrib版。我运行Python 3.7 64位

我要导入的功能的链接:https://docs.opencv.org/4.1.0/d9/d0c/group__calib3d.html#ga617b1685d4059c6040827800e72ad2b6

在某些示例中,cv与cv2进行了交换,我也尝试过这样做:
https://www.programcreek.com/python/example/89312/cv2.stereoRectify

import cv2


left_cam = [
    [523.767345904798, 0.0, 268.20033902081417],
    [0.0, 550.2332063123357, 232.55503628081783],
    [0.0, 0.0, 1.0]
]

left_dist = [0.18999914119422034, -1.1006674853253424, -0.0037412308565715193, 0.023153597402935818, 1.7303232709773213]

right_cam = [
    [538.1299316757662, 0.0, 349.4715067576933],
    [0.0, 544.3638349123668, 240.18753969060498],
    [0.0, 0.0, 1.0]
]

right_dist = [0.12126236480318829, -0.14032072749598928, -0.006271304663061128, 0.01641265601395131, -0.02049471257256062]

tx = 286.07359237108625

proj = cv2.StereoRectify(
    left_cam,
    right_cam,
    left_dist,
    right_dist,
    (1920, 1080)
)

从理论上讲,该程序包应该包含此功能,但是我得到以下错误:该属性不存在:
File ".\get_projection_matrix.py", line 23, in <module>
    proj = cv.StereoRectify(
AttributeError: module 'cv2.cv2' has no attribute 'StereoRectify'

我已经离散地尝试了这些导入:
import cv2
import cv2 as cv (this should definitely not work)
from cv2 import cv

最佳答案

它是stereoRectify,首字母s不是大写字母。

10-08 12:05