I want to detect the lower half of the image with python.

Asked 2 years ago, Updated 2 years ago, 428 views

Please let me know the code to detect only the lower half of the image.

python opencv

2022-09-30 22:03

1 Answers

If you mean code that only specifies the bottom half of the image to perform object detection, try running_detector in this notebook as follows:

#https://colab.research.google.com/github/tensorflow/hub/blob/master/examples/colab/object_detection.ipynb

def run_detector_half(detector, path):
  img=load_img(path)
  cropped_img=img [img.shape[0]//2:img.shape[0]]
  converted_img = tf.image.convert_image_dtype(cropped_img, tf.float32) [tf.newaxis,...]
  start_time = time.time()
  result=detector(converted_img)
  end_time = time.time()

  result={key:value.numpy()for key, value in result.items()}

  print("Found%objects."%len(result["detection_scores"]))
  print("Inference time:", end_time-start_time)

  image_with_boxes=draw_boxes(
      cropped_img.numpy(), result ["detection_boxes",
      result ["detection_class_entities", result ["detection_scores"))
  img_np=img.numpy()
  for i, jin enumerate (range(img.shape[0]//2, img.shape[0])):
    img_np[j]=image_with_boxes[i]
  display_image(img_np)


2022-09-30 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.