如何获得列表中所有不同的检测对象?

时间:2019-07-09 07:47:26

标签: python tensorflow object-detection

通过使用Tensorflow预训练的COCO模型,我试图从帧中获取每个检测到的对象,并尝试存储它们,以使每个对象中的每个对象都具有不同的标签。

例如:

ist=[["person1_info"],["person2_info']]

我搜索了诸如How to count objects in Tensorflow Object Detection API之类的某些堆栈溢出页面,但是无法获得明确的结果。主循环在下面:

  boxes = np.squeeze(boxes)
  scores = np.squeeze(scores)
  classes = np.squeeze(classes)

  indices = np.argwhere(classes == 1)
  boxes = np.squeeze(boxes[indices])

  scores = np.squeeze(scores[indices])
  classes = np.squeeze(classes[indices])

  # Visualization of the results of a detection.
  vis_util.visualize_boxes_and_labels_on_image_array(
      image_np,
      np.squeeze(boxes),
      np.squeeze(classes).astype(np.int32),
      np.squeeze(scores),
      category_index,
      use_normalized_coordinates=True,
      line_thickness=8)

  cv2.imshow('object detection', cv2.resize(image_np, (800,600)))

  if cv2.waitKey(25) & 0xFF == ord('q'):
    cv2.destroyAllWindows()
    break

1 个答案:

答案 0 :(得分:0)

要创建自定义输出列表,您可以这样操作:

(im_width, im_height, _) = frame.shape
boxes = np.squeeze(boxes)
scores = np.squeeze(scores)
classes = np.squeeze(classes).astype(np.int32)
out = []
for box, score, obj_class in zip(boxes, scores, classes):
    xmin, ymin, xmax, ymax = box

    # delete this if you need to keep normalized coordinates
    (xmin, xmax, ymin, ymax) = (xmin * im_width, xmax * im_width,
                                ymin * im_height, ymax * im_height)
    out.append([xmin, xmax, ymin, ymax, obj_class, score])