0
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)

In one of the codes for tensorflow object detection API, there is the vis_util.visualize_boxes_and_labels_on_image_array method which draws bounding boxes on the image and returns the new image_np which is fed into plt.imshow(image_np) to display. However, vis_util.visualize_boxes_and_labels_on_image_array method is not assigned to image_np variable as shown in the code. How does plt.imshow(image_np) get the latest(The image which has the drawn bounding box) image?

3
  • But should it be image_np = vis_util.visualize_boxes_and_labels_on_image_array( ........... ), then the function can return the new modified content? Commented Feb 23, 2018 at 6:15
  • No. You are passing an array. The contents in the array (the image pixels) are modified. Commented Feb 23, 2018 at 6:17
  • Okay thank you very much. I am new to python lol Commented Feb 23, 2018 at 6:18

1 Answer 1

2

You are passing the image_np value into visualize_boxes_and_labels_on_image_array as the first parameter and the function modifies its contents to draw the bounding boxes. The code is open source. You can check it out for yourself here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.