TensorFlow对象检测API:视频输入的边界框坐标和时间戳

时间:2019-01-30 14:21:48

标签: python tensorflow logging object-detection bounding-box

我能够以[ymin,xmin,ymax,xmax]的形式输出边界框的坐标,并已从规范化形式转换为具有图像坐标的数据框。

我想知道是否有一种方法可以将边界框坐标记录到终端上,因为代码运行时带有时间戳(视频概述了每个框的生成时间)?

我的目标是要产生一个数据框,其中显示边框框坐标以及视频时间戳的生成时间,即[框号,时间戳,ymin,xmin,ymax,xmax]

相关代码如下所示:

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    while cap.isOpened():
      ret, image_np = cap.read()
      if ret == True:
          image_np_expanded = np.expand_dims(image_np, axis=0)
          image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
          boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
          scores = detection_graph.get_tensor_by_name('detection_scores:0')
          classes = detection_graph.get_tensor_by_name('detection_classes:0')
          num_detections = detection_graph.get_tensor_by_name('num_detections:0')
          (boxes, scores, classes, num_detections) = sess.run(
              [boxes, scores, classes, num_detections],
              feed_dict={image_tensor: image_np_expanded})
          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)
          out.write(image_np)
          cv2.imshow('Output',image_np)
          if cv2.waitKey(1) & 0xFF == ord('q'):
              cv2.destroyAllWindows()
              break
      else:
          break

cap.release()
out.release()
cv2.destroyAllWindows()

0 个答案:

没有答案