【问题标题】:Extract images object of Tensorflow object detection API提取 Tensorflow 对象检测 API 的图像对象
【发布时间】:2021-01-31 22:25:17
【问题描述】:

我的问题是我有 ymin、xmin、ymax、xmax 和盒子形状。

我无法提取检测到的对象,它只显示所有图像而不是框。

我尝试了什么:


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)

我使用这个 API:https://www.tensorflow.org/hub/tutorials/object_detection

一个物体检测的例子 ymin,xmin,ymax,xmax:0.6325336 0.2925815 0.92287964 0.40271035 对象类型:b'Chair'

【问题讨论】:

标签: python tensorflow opencv computer-vision


【解决方案1】:
  1. 矩形的坐标必须是整数,而不是浮点数!

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

  2. 另一个问题是起点和终点坐标应该是这种格式

    (xmin, ymin), (xmax, ymax),添加不必要的括号((),())会将整数定义为元组,这会导致错误。

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)

【讨论】:

  • 我知道,谢谢它有效!然后我只使用 image[ymin:ymax, xmin:xmax]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多