首页 > 解决方案 > 带有open cv python响应的索引错误数组

问题描述

运行对象检测系统 ubnutu 20.04 lts 时出现此错误

它开始运行并打印一些数组但随后立即发生错误任何帮助将不胜感激我使用的是opencv最新版本

[[1]
 [1]] [[578  25 182 215]
 [604 112 675 608]]
[[ 1]
 [82]
 [18]] [[657 277 623 443]
 [953  16 309 442]
 [636 258 644 461]]
Traceback (most recent call last):
  File "/home/jason/Documents/PythonProjects/VoiceAssistant/ObjectDetection.py", line 31, in <module>
    cv2.putText(img,classNames[classId-1].upper(),(box[0]+10,box[1]+30), IndexError: list index out of range
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,255,0),2)

标签: pythonnumpyopencvindex-error

解决方案


推荐阅读