1

My problem is that I have ymin,xmin,ymax,xmax and boxes shapes.

I can't extract objects detected, it just display all image not boxes.

What I tried:


image_url = "https://upload.wikimedia.org/wikipedia/commons/6/60/Naxos_Taverna.jpg"  #@param
downloaded_image_path = download_and_resize_image(image_url, 1280, 856, True)

import cv2

...

 for i in range(min(boxes.shape[0], max_boxes)):
    if scores[i] >= min_score:
      ymin, xmin, ymax, xmax = tuple(boxes[i])
      display_str = "{}: {}%".format(class_names[i].decode("ascii"),
                                     int(100 * scores[i]))
      color = colors[hash(class_names[i]) % len(colors)]
      image_pil = Image.fromarray(np.uint8(image)).convert("RGB")
      print(image_pil)
      image = np.array(image_pil)
      print(type(image))
      import cv2
      rect = cv2.rectangle(image, ((xmin), (ymin)), ((xmax), (ymax)), (0, 0, 255), 1)

      print(ymin, xmin, ymax, xmax)
      cv2_imshow(rect)

I use this API: https://www.tensorflow.org/hub/tutorials/object_detection

Example of one object detection ymin, xmin, ymax, xmax : 0.6325336 0.2925815 0.92287964 0.40271035 object type : b'Chair'

2

1 Answer 1

1
  1. The Coordinates of the Rectangle has to be integers, not floats!

    ymin, xmin, ymax, xmax : 0.6325336 0.2925815 0.92287964 0.40271035

  2. Another issue is the start point, and endpoint coordinates should be in this format

    (xmin, ymin), (xmax, ymax), adding unnecessary parentheses((),()) will define integers as tuples, and that will cause errors.

Recy

xmin = int(0.2925815 * img.shape[1])
xmax = int(0.40271035 * img.shape[1])
ymin = int(0.6325336 * img.shape[0])
ymax = int(0.92287964 * img.shape[0])

rect = cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 0, 255), 1)
Sign up to request clarification or add additional context in comments.

1 Comment

I know, thanks it works! And then I just use image[ymin:ymax, xmin:xmax]

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.