如何提取或获取 Detectron 包围的图像

发布于 2025-01-10 16:39:40 字数 392 浏览 6 评论 0 原文

我正在使用我自己创建的训练数据集在检测的帮助下在图像上创建边界框,而我现在陷入了提取有界图像的部分。 我只想要边界框内零件的图像。 要预测的输入图像。

带有边界框轮廓的预测图像。

请帮助我完成此查询。结果图像应该是这样的。

I am working on creating bounding boxes upon images with my own created training dataset with the help of Detection, while I'm now stuck at the part of extracting the bounded image. I just want the image of the part inside the bounding box.
The input image to predicted.

The predicted image with the bounding box outlines.

Please help me with this query.The resultant image should be like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-01-17 16:39:40

Tensorflow方法中的检测功能

 # Detection Function
 detections = detect_fn(input_tensor)

 bscores = detections['detection_scores'][0].numpy()
 bclasses = detections['detection_classes'][0].numpy().astype(np.int32)
 bboxes = detections['detection_boxes'][0].numpy()

 det_boxes, class_labels = ExtractBBoxes(bboxes, bclasses, bscores, im_width, im_height, image_name=image_file)

提取和裁剪边界框

def ExtractBBoxes(bboxes, bclasses, bscores, im_width, im_height, image_name):
 bbox = []
 class_labels = []
 for idx in range(len(bboxes)):
    if bscores[idx] >= Threshold:
      #Region of Interest
      y_min = int(bboxes[idx][0] * im_height)
      x_min = int(bboxes[idx][1] * im_width)
      y_max = int(bboxes[idx][2] * im_height)
      x_max = int(bboxes[idx][3] * im_width)
      class_label = category_index[int(bclasses[idx])]['name']
      class_labels.append(class_label)
      bbox.append([x_min, y_min, x_max, y_max, class_label, float(bscores[idx])])

      #Crop Image
      cropped_image = tf.image.crop_to_bounding_box(image, y_min, x_min, y_max - y_min, x_max - x_min).numpy().astype(np.int32)
      output_image = tf.image.encode_jpeg(cropped_image) #For Jpeg
      score = bscores[idx] * 100
      # Create a constant as filename
      file_name = tf.constant(youfilename)
      file = tf.io.write_file(file_name, output_image)

Detection Function in Tensorflow

 # Detection Function
 detections = detect_fn(input_tensor)

 bscores = detections['detection_scores'][0].numpy()
 bclasses = detections['detection_classes'][0].numpy().astype(np.int32)
 bboxes = detections['detection_boxes'][0].numpy()

 det_boxes, class_labels = ExtractBBoxes(bboxes, bclasses, bscores, im_width, im_height, image_name=image_file)

Method to extract and crop bounding box

def ExtractBBoxes(bboxes, bclasses, bscores, im_width, im_height, image_name):
 bbox = []
 class_labels = []
 for idx in range(len(bboxes)):
    if bscores[idx] >= Threshold:
      #Region of Interest
      y_min = int(bboxes[idx][0] * im_height)
      x_min = int(bboxes[idx][1] * im_width)
      y_max = int(bboxes[idx][2] * im_height)
      x_max = int(bboxes[idx][3] * im_width)
      class_label = category_index[int(bclasses[idx])]['name']
      class_labels.append(class_label)
      bbox.append([x_min, y_min, x_max, y_max, class_label, float(bscores[idx])])

      #Crop Image
      cropped_image = tf.image.crop_to_bounding_box(image, y_min, x_min, y_max - y_min, x_max - x_min).numpy().astype(np.int32)
      output_image = tf.image.encode_jpeg(cropped_image) #For Jpeg
      score = bscores[idx] * 100
      # Create a constant as filename
      file_name = tf.constant(youfilename)
      file = tf.io.write_file(file_name, output_image)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文