微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ImageAI如何防止检测框被绘制

如何解决ImageAI如何防止检测框被绘制

我正在使用 ImageAI 和 resnet50 模型从照片中检测和提取人物图片。一切都很好,但我不知道如何禁用检测框的绘制。显然,当多人在同一个镜头中时,一个人的检测框就会渗透到其他人的提取图像上。

有人知道怎么做吗?我环顾四周,只发现 one other question 有同样的问题,出于某种原因,答案是在谈论 OpenCV 而不是 imageai。

我的代码

from pathlib import Path

import cv2
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.applications.resnet50 import resnet50

from imageai.Detection import ObjectDetection

physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0],True)

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath('resnet50_coco_best_v2.1.0.h5')
detector.loadModel()
person = detector.CustomObjects(person=True)

source_folder = Path(r'd:/pics')
files = [f for f in source_folder.glob('*.jpg')]
output_folder = Path('c:/python/datasets/raw/extracted_images')

for idx,i in enumerate(files):
    print(f'Extracting images from: {i.name}')
    image = i 
    output_path = output_folder.joinpath(f'{idx}.jpg')
    detected_image,detections = detector.detectCustomObjectsFromImage(input_image=str(image),output_image_path=str(output_path),minimum_percentage_probability=20,input_type='file',output_type='file',display_percentage_probability=False,extract_detected_objects=True,custom_objects=person)

编辑: 我找到了一种解决问题的黑客方法 - 通过转到 detectObjetcFromImage() 函数的源代码并注释掉这一点:

# image_copy = draw_Boxes(image_copy,#                 Box_points,#                 display_Box,#                 label,#                 percentage_probability,#                 self.__Box_color)

有没有一种不那么干扰的方式来处理这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。