Python 属性错误:模块';cv2和x27;没有属性';dnn#U检测模型&x27;

Python 属性错误:模块';cv2和x27;没有属性';dnn#U检测模型&x27;,python,opencv,Python,Opencv,为什么在尝试运行此代码时出现错误“AttributeError:模块“cv2”没有属性“dnn\u DetectionModel”: # get the weight configurations configPath = '/Users/Rodne/MyComputerVision/Folder3/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt' weightsPath = '/Users/Rodne/MyComputerVision/Folde

为什么在尝试运行此代码时出现错误“AttributeError:模块“cv2”没有属性“dnn\u DetectionModel”:

# get the weight configurations
 configPath = 
 '/Users/Rodne/MyComputerVision/Folder3/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = '/Users/Rodne/MyComputerVision/Folder3/frozen_inference_graph.pb'

# setting the bounding box
net = cv2.dnn_DetectionModel(weightsPath, configPath)
net.setInputSize(320, 320)
错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-355122b5b70e> in <module>()
      1 # setting the bounding box
----> 2 net = cv2.dnn_DetectionModel(weightsPath, configPath)
      3 net.setInputSize(320, 320)

AttributeError: module 'cv2' has no attribute 'dnn_DetectionModel'
这是我仅有的cv2.dnn:

您需要安装OpenCV\u contrib来使用DNN功能,这可以通过下面的链接完成。我建议您使用CMAKE gui


我对configPath和weightsPath的路径没有问题。我的错误是cv2.dnn_检测模型不存在。我之前有过确切的错误,您可以尝试添加完整路径吗。我尝试了您的建议,但仍然得到了相同的错误…我不明白的是,为什么我的
cv2
中没有
dnn_检测模型
属性,您在opencv_contrib中添加了吗?DNN功能不在OpenCV的标准版本中。
Collecting opencv-python
  Downloading opencv_python-4.4.0.42-cp37-cp37m-win_amd64.whl (33.5 MB)
     |████████████████████████████████| 33.5 MB 54 kB/s
Requirement already satisfied, skipping upgrade: numpy>=1.14.5 in d:\anaconda\lib\site-packages (from opencv-python) (1.18.5)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.4.0.42