1
votes

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'

1
Can you please add a sample image with sample coordinates (ymin, xmin, ymax, xmax) to test your code with? minimal reproducible example.Bilal
ymin, xmin, ymax, xmax : 0.6325336 0.2925815 0.92287964 0.40271035 object type : b'Chair' image_url = "upload.wikimedia.org/wikipedia/commons/6/60/Naxos_Taverna.jpg" #@parammrNicky

1 Answers

1
votes
  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)