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 (将#修改为@)