【问题标题】:AttributeError: module 'cv2' has no attribute 'dnn_DetectionModel'AttributeError:模块“cv2”没有属性“dnn_DetectionModel”
【发布时间】:2020-09-17 03:41:55
【问题描述】:

当我尝试运行此代码时,为什么会收到错误 `AttributeError: module 'cv2' has no attribute 'dnn_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'

我已经通过在终端中输入以下内容升级了我的开放式简历:pip install opencv-python --upgrade 这就是结果

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

这是我唯一的 cv2.dnn:

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    您也可以尝试更新一次 opencv 模块。在我将 opencv 模块更新为 opencv 4 后,它在我的情况下有效。尝试运行此命令,看看它是否有效:

    pip install --upgrade opencv-python
    

    【讨论】:

      【解决方案2】:

      您需要安装 OpenCV_contrib 才能使用 DNN 功能,这可以通过下面的链接完成,我建议使用 CMAKE gui

      Link with the steps to build opencv_contrib

      【讨论】:

      • 我对 configPath 和 weightsPath 的路径没有问题。我的错误是 cv2.dnn_DetectionModel 不存在。
      • 在您尝试添加完整路径之前,我遇到了确切的错误。
      • 我尝试了你的建议,但我仍然得到同样的错误......
      • 我想不通的是为什么我的cv2 中没有dnn_DetectionModel 属性
      • 你添加了opencv_contrib吗? DNN 功能不在 OpenCV 的标准构建中。
      猜你喜欢
      • 2017-11-22
      • 2019-07-25
      • 2017-11-21
      • 2021-02-17
      • 2019-11-13
      • 2018-11-13
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多