在tensorflow对象检测中可视化框

时间:2018-02-23 06:04:13

标签: python tensorflow

for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
  # Actual detection.
  output_dict = run_inference_for_single_image(image_np, detection_graph)
  # Visualization of the results of a detection.
  vis_util.visualize_boxes_and_labels_on_image_array(
      image_np,
      output_dict['detection_boxes'],
      output_dict['detection_classes'],
      output_dict['detection_scores'],
      category_index,
      instance_masks=output_dict.get('detection_masks'),
      use_normalized_coordinates=True,
      line_thickness=8)
  plt.figure(figsize=IMAGE_SIZE)
  plt.imshow(image_np)

在张量流对象检测API的代码之一中,有vis_util.visualize_boxes_and_labels_on_image_array方法,该方法在图像上绘制边界框并返回新的image_np,其被输入到plt.imshow(image_np)中以进行显示。但是, vis_util.visualize_boxes_and_labels_on_image_array方法未分配给image_np变量,如代码所示。 plt.imshow(image_np)如何获取最新的(带有绘制边界框的图像)图像?

1 个答案:

答案 0 :(得分:2)

您将image_np值作为第一个参数传递给visualize_boxes_and_labels_on_image_array,函数会修改其内容以绘制边界框。代码是开源的。您可以自己查看here.