【发布时间】:2022-12-05 20:37:03
【问题描述】:
我正在尝试使用 OpenCV 处理我的对象检测项目,它输出和错误我无法理解这是我的代码:
`
import cv2
img = cv2.imread('lena.png')
ClassNames = []
ClassFile = 'coco.names'`
with open(ClassFile, 'rt') as f:
ClassNames = f.read().rstrip('\n').split('\n')
configpath = 'ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightspath = '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)
classIds, confs, bbox = net.detect(img, confThreshold= 0.5)
print(classIds, bbox)
for classId, confidence, box in zip(classIds.flatten(), confs.flatten, bbox):
cv2.rectangle(img, box, color=(0, 255, 0), thickness= 3)
cv2.imshow('Lena image',img)
`
使用上面的代码是错误的:
TypeError Traceback(最后一次调用) ~\AppData\Local\Temp\ipykernel_2776\4286890995.py 中 ----> 1 for classId, confidence, box in zip(classIds.flatten(), confs.flatten, bbox): 2 cv2.rectangle(img, box, color=(0, 255, 0), 厚度= 3)
TypeError: 'builtin_function_or_method' 对象不可迭代
【问题讨论】:
-
confs.flatten——你错过了()。
标签: python opencv object-detection