【发布时间】:2020-04-19 07:05:34
【问题描述】:
我正在尝试使用 ssd_inception_v2_coco_2018_01_28 模型在图像上实现对象检测模型。
我正在尝试获取顶部带有边界框的输出。
1) ssd_inception_v2_coco_2018_01_28 对象检测模型。已成功转换为 IR。
2) 取一张输入图像,根据模型的输入层信息进行预处理。
3) 成功提取模型输出。
4) 为输出图像添加边界框。
但出现以下错误,请帮忙!
源代码
#Preprocessing image
img = r'D:\SriSailam.jpg'
img = cv2.imread(img)
img = cv2.resize(img,(300,300))
img = img.transpose((2,0,1))
img = img.reshape(1,3,300,300)
exec_net = engine.load_network(net,'cpu')
#Asynchronous request
infer_request_handle = exec_net.start_async(request_id=0, inputs={'image_tensor': img})
infer_status = infer_request_handle.wait()
output = next(iter(net.outputs))
n,c,h,w = img.shape
result = infer_request_handle.outputs[output] #output layer shape
'''
Draw bounding boxes onto the image.
'''
for box in result[0][0]: # Output shape is 1x1x100x7
conf = box[2] #box[2] = result[0][0][2] is a probability value
print("probability value : ",conf)
print("box[0] : ",box[0])
print("box[1] : ",box[1])
print("xmin : ", box[3])
print("ymin : ", box[4])
print("xmax : ", box[5])
print("ymax : ", box[6])
if conf >= 0:
xmin = int(box[3] * w) #box[3] - xmin
ymin = int(box[4] * h) #box[4] - ymin
xmax = int(box[5] * w) #box[5] - xmax
ymax = int(box[6] * h) #box[6] - ymax
rect = cv2.rectangle(img, ((xmin), (ymin)), ((xmax), (ymax)), (0, 0, 255), 1)
cv2.imshow(rect,'face_detection')
cv2.waitKey(0)
输出
C:\Users\adity\Desktop\openvino>py check_infer.py
probability value : 0.6344592
box[0] : 0.0
box[1] : 1.0
xmin : 0.1831626
ymin : 0.10697469
xmax : 0.86960804
ymax : 1.0
Traceback (most recent call last):
File "check_infer.py", line 68, in <module>
rect = cv2.rectangle(img, ((xmin), (ymin)), ((xmax), (ymax)), (0, 0, 255), 1)
TypeError: an integer is required (got type tuple)
【问题讨论】:
-
哪个opencv版本?你试过
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 0, 255), 1)吗? -
版本是 4.2.0 。我尝试使用您指定的相同功能。
-
我在通话中删除了
xmin、ymin、xmax和ymax周围的额外括号。
标签: python opencv object-detection-api openvino