在detectObjectsFromImage()中抑制输出图像生成可以通过设置参数来实现。具体而言,可以使用output_type
参数来控制输出类型,将其设置为"array"
或"dataframe"
,即可抑制输出图像的生成。
"array"
:将输出结果以数组的形式返回,不生成输出图像。"dataframe"
:将输出结果以数据框的形式返回,不生成输出图像。这样,你可以根据需要选择适合的输出类型,以避免生成输出图像。
以下是一个示例代码,展示如何在detectObjectsFromImage()中抑制输出图像生成:
from imageai.Detection import ObjectDetection
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath("path_to_model")
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image="path_to_input_image",
output_image_path="path_to_output_image",
output_type="array")
for eachObject in detections:
print(eachObject["name"], " : ", eachObject["percentage_probability"])
在上述代码中,output_type
参数被设置为"array"
,因此不会生成输出图像。输出结果将以数组的形式存储在detections
变量中,然后可以根据需要进行进一步处理或展示。
请注意,以上示例代码中的path_to_model
和path_to_input_image
需要替换为实际的模型路径和输入图像路径。
推荐的腾讯云相关产品:腾讯云图像识别(https://cloud.tencent.com/product/imagerecognition)
领取专属 10元无门槛券
手把手带您无忧上云