【发布时间】:2021-12-04 15:22:44
【问题描述】:
python 和机器学习的新手。我正在尝试在我的 mss 屏幕截图上绘制边界框。这是我认为我应该接收坐标以绘制矩形的代码部分。
while True:
img = screnshot.grab(bounding_box)
frame = np.array(img)
cv2.imshow('Testing', frame)
results = model(frame)
results.print()
pandasbox=results.pandas().xyxy[0]
print(pandasbox)
使用 pandas 可以很好地打印坐标和类,例如:
image 1/1: 400x350 1 person, 1 truck
Speed: 0.0ms pre-process, 14.4ms inference, 0.0ms NMS per image at shape (1, 3, 640, 576)
xmin ymin xmax ymax confidence class name
0 61.171875 134.765625 133.046875 334.0625 0.810547 0 person
1 181.562500 0.273438 347.500000 86.2500 0.768555 7 truck
但是...我不知道如何使用这些坐标形成一个矩形。向 cv2.rectangle 函数添加“(xmin, xmax),(ymin, ymax)” 以及许多其他尝试均未成功,包括此尝试,尽管检测到打印,但从未在 mss 屏幕中绘制边界框:
for box in results.xyxy[0]:
if box[5]==0:
xB = int(box[2])
xA = int(box[0])
yB = int(box[3])
yA = int(box[1])
cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)
如果有人可以向我展示一个使用“results.pandas().xyxy[0]”中的坐标来绘制带有 cv2.rectangle 的边界框的示例,那就太好了!以及任何其他新手不知道的指针或见解......
【问题讨论】:
标签: python machine-learning object-detection yolov5