程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”?

开发过程中遇到“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”的问题如何解决?下面主要结合日常开发的经验,给出你关于“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”的解决方法建议,希望对你解决“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”有所启发或帮助;

CAMMands used to install

Folder structure

The error

代码

import cv2

thres = 0.45 # Threshold to detect object

cap = cv2.VIDeoCapture(0)
cap.set(3,1280)
cap.set(4,720)
cap.set(10,70)

classnames = []
classfile = '/home/pi/Desktop/objectDetection/coco.names'
with open(classfile,'rt') as f:
    classnames = f.read().rStrip('\n').split('\n')

configPath = '/home/pi/Desktop/objectDetection/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = '/home/pi/Desktop/objectDetection/froZen_inference_graph.pb'

net = cv2.dnn_DetectionModel(weightsPath,configPath)
net.seTinputSize(320,320)
net.seTinputScale(1.0/ 127.5)
net.seTinputMean((127.5,127.5,127.5))
net.seTinputSwapRB(true)

while True:
    success,img = cap.read()
    classIDs,confs,bBox = net.detect(img,confThreshold=thres)
    print(classIDs,bBoX)

    if len(classIDs) != 0:
        for classID,confIDence,Box in zip(classIDs.flatten(),confs.flatten(),bBoX):
            cv2.rectangle(img,Box,color=(0,255,0),thickness=2)
            cv2.putText(img,classnames[classID-1].upper(),(Box[0]+10,Box[1]+30),cv2.Font_HERShey_COMPLEX,1,(0,2)
            cv2.putText(img,str(round(confIDence*100,2)),(Box[0]+200,2)

    cv2.imshow("Output",img)
    cv2.waitKey(1)

   

以下是用于安装 opencv/opencv-contrib 4.5.1 版的命令列表、文件结构、代码和错误的屏幕截图。

感谢您花时间阅读并解决此问题,我很感激!

解决方法

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

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

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

大佬总结

以上是大佬教程为你收集整理的“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”全部内容,希望文章能够帮你解决“AttributeError:模块‘cv2.cv2’没有属性‘dnn_DetectionModel”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: