10行代码实现目标检测
原文地址:
1.https://blog.youkuaiyun.com/jiangjiang_jian/article/details/80781063
2.https://towardsdatascience.com/object-detection-with-10-lines-of-code-d6cb4d86f606
github地址:https://github.com/OlafenwaMoses/ImageAI
环境要求
库包名称 | 下载 |
---|---|
python | https://www.anaconda.com/distribution/#download-section(anaconda下载地址) |
Tensorflow | pip install tensorflow |
NumPy | pip install numpy |
SciPy | pip install scipy |
OpenCV | pip install opencv-python |
Pillow | pip install pillow |
Matplotlib | pip install matplotlib |
H5py | pip install h5py |
Keras | pip install keras |
ImageAI | pip install https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.1/imageai-2.0.1-py3-none-any.whl |
下载RetinaNet 模型文件
https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_coco_best_v2.0.1.h5
运行代码
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image.jpg"), output_image_path=os.path.join(execution_path , "imagenew.jpg"))
for eachObject in detections:
print(eachObject["name"] + " : " + eachObject["percentage_probability"] )
测试图片