如何获取特定边界框的像素坐标 [英] How do I get the pixel coordinates for a specific bounding box

查看:33
本文介绍了如何获取特定边界框的像素坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Person类获取边界框的像素坐标(标记为: Mcoco_Label_map.pbtxt

item {
  name: "/m/01g317"
  id: 1
  display_name: "person"
}

目前我正在通过

将边界框和标签放到图像上
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections, predictions_dict, shapes = detect_fn(input_tensor)
label_id_offset = 1
image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array(
          image_np_with_detections,
          detections['detection_boxes'][0].numpy(),
          (detections['detection_classes'][0].numpy() + label_id_offset).astype(int),
          detections['detection_scores'][0].numpy(),
          category_index,
          use_normalized_coordinates=True,
          max_boxes_to_draw=3,
          min_score_thresh=.30,
          agnostic_mode=False)

(所有代码都在While循环中)

但是当我打印出检测时,我得到了这么多归一化的坐标,我不知道如何将这些坐标排序到特殊的框中,例如。人员标签。

那么,如何在检测中获取特定边界框的像素坐标?

StackOverflow新手入门,因此非常感谢您的任何提示。

推荐答案

sodetection_boxes应该是归一化坐标中[ymin, xmin, ymax, xmax]形式的N乘4边界框坐标数组,detection_classes应该是(`Float?)数字类标签。我假设他们没有太多更改API,因为我从去年年初开始就没有使用过对象检测API。

您应该能够这样做,将其转换为像素坐标,然后只获取一组标签。

detection_boxes = detections['detection_boxes'][0].numpy()
detection_classes = detections['detection_classes'][0].numpy().astype(int) + label_id_offset
detection_scores = detections['detection_scores'][0].numpy()

# Scale to pixel co-ordinates
detection_boxes[:, (0, 2)] *= IMAGE_HEIGHT
detection_boxes[:, (1, 3)] *= IMAGE_WIDTH

# Select person boxes
cond = (detection_classes == PERSON_CLASS_ID) & (detection_scores >= SCORE_THRESH)
person_boxes = detection_boxes[cond, :]
person_boxes = np.round(person_boxes).astype(int)

这篇关于如何获取特定边界框的像素坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆