Let‘s Go,图像识别初探——ImageAI

我们常常能接触到图像识别,例如人脸识别,物体检测,自动驾驶等等。让我们通过ImageAI来初探图像识别吧。

开始

环境这里就不再赘述,请自觉查询官网
https://github.com/OlafenwaMoses/ImageAI

图像分类 Image Classification

在这里插入图片描述
在这里插入图片描述

目录结构

$ tree .
.
├── 1.jpg
├── FirstPrediction.py
├── image2.jpg
└── resnet50-19c8e357.pth

0 directories, 4 files

代码

from imageai.Classification import ImageClassification
import os

execution_path = os.getcwd()

prediction = ImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(os.path.join(execution_path, "resnet50-19c8e357.pth"))
prediction.loadModel()

# predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "image2.jpg"), result_count=5 )
for eachPrediction, eachProbability in zip(predictions, probabilities):
    print(eachPrediction , " : " , eachProbability)

输出

sports car  :  65.5919
convertible  :  12.3926
car wheel  :  8.0013
beach wagon  :  5.3135
grille  :  4.7835
物体检测 Object Detection

在这里插入图片描述

目录结构

$ tree
.
├── FirstObjectDetection.py
├── image2.jpg
├── image2new.jpg
└── yolov3.pt

0 directories, 4 files

代码

from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path, "yolov3.pt"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path, "image2.jpg"), output_image_path=os.path.join(execution_path, "image2new.jpg"), minimum_percentage_probability=30)

for eachObject in detections:
    print(eachObject["name"], " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"])
    print("--------------------------------")

在这里插入图片描述

视频物体检测,跟踪,分析 Video Object Detection, Tracking and Analysis

目录结构

$ tree
.
├── FirstVideoObjectDetection.py
├── traffic.mp4
├── traffic_detected.mp4
└── yolov3.pt

0 directories, 4 files

代码

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolov3.pt"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "traffic.mp4"),
                        output_file_path=os.path.join(execution_path, "traffic_detected")
                        , frames_per_second=20, log_progress=True)
print(video_path)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值