如何获取用 tensorflow 2 检测到的最佳对象的坐标?

How to get coordinates of best object detected with tensorflow 2?

接受的答案说明了 tensorflow 如何绘制检测到的对象的边界框,但没有显示或解释如何检索这些坐标。有人可以告诉我如何为 tensorflow 2 完成此操作吗?

您可以在此处使用 this 文档中的大部分代码。

只需添加以下代码即可获取边界框坐标(在定义 detection_classes 之后)

width = image_np.shape[1]
height = image_np.shape[0]

for box,score,cls in zip(detections['detection_boxes'][0],detections['detection_scores'][0],detections['detection_classes'][0]):
    if score >= 0.5: # or any other value
        xmin = box[1]*width
        ymin = box[0]*height
        xmax = box[3]*width
        ymax = box[2]*height