首页 > 解决方案 > detectObjectsFromImage 方法的问题

问题描述

我正在尝试执行对象检测操作,向程序发送图像,它会将新图像返回到指定位置,其中包含在原始图像中检测到的对象。我正在关注一些现有代码并尝试运行它,但它不会让我这样做,因为该detectObjectsFromImage方法存在错误。具体来说,它的参数被标记为红色,即 input_image 和 output_image_path。他们需要一个字符串,我确实给了他们(我的图像的路径),但它仍然给我这个错误。我还imageAI使用pip. 我不确定问题出在哪里,所以如果有人可以提供帮助,我将不胜感激。代码附在下面。

 from imageai.Detection import ObjectDetection
    
    detector = ObjectDetection()
    
    model_path = "yolo-tiny.h5"
    
    input_path = "./input/sampleimage.jpg"
    
    output_path = "./output/newimage.jpg"
    
    detector.setModelTypeAsTinyYOLOv3()
    
    detector.setModelPath(model_path)
    
    detector.loadModel()
    
    detection = detector.detectObjectsFromImage(input_image=input_path, output_image_path=output_path, input_type="file", output_type="file")
    
    for eachItem in detection:
        print(eachItem["name"] , " : ", eachItem["percentage_probability"])

标签: pythonobject-detection

解决方案


推荐阅读