# ImageAI : Object Detection
## ---------------------------------------------------
## Introducing TheiaEngine.
![](https://raw.githubusercontent.com/Gen-XR/TheiaEngine/main/logo.png)
We the creators of ImageAI are glad to announce [TheiaEngine](https://www.genxr.co/theia-engine), the next-generation computer Vision AI API capable of all computer vision tasks in a single API call and available via REST API to all programming languages. Features include
- **Detect 300+ objects** ( 220 more objects than ImageAI)
- **Provide answers to any content or context questions** asked on an image
- very useful to get information on any object, action or information without needing to train a new custom model for every tasks
- **Generate scene description and summary**
- **Convert 2D image to 3D pointcloud and triangular mesh**
- **Semantic Scene mapping of objects, walls, floors, etc**
- **Stateless Face recognition and emotion detection**
- **Image generation and augmentation from prompt**
- etc.
Visit [https://www.genxr.co/theia-engine](https://www.genxr.co/theia-engine) to try the demo and join in the beta testing today.
## ---------------------------------------------------
### TABLE OF CONTENTS
- <a href="#firstdetection" > :white_square_button: First Object Detection</a>
- <a href="#objectextraction" > :white_square_button: Object Detection, Extraction and Fine-tune</a>
- <a href="#customdetection" > :white_square_button: Custom Object Detection</a>
- <a href="#detectionspeed" > :white_square_button: Detection Speed</a>
- <a href="#hidingdetails" > :white_square_button: Hiding/Showing Object Name and Probability</a>
- <a href="#inputoutputtype" > :white_square_button: Image Input & Output Types</a>
- <a href="#documentation" > :white_square_button: Documentation</a>
ImageAI provides very convenient and powerful methods to perform object detection on images and extract each object from the image. The object detection class supports RetinaNet, YOLOv3 and TinyYOLOv3. To start performing object detection, you must download the RetinaNet, YOLOv3 or TinyYOLOv3 object detection model via the links below:
* **[RetinaNet](https://github.com/OlafenwaMoses/ImageAI/releases/download/3.0.0-pretrained/retinanet_resnet50_fpn_coco-eeacb38b.pth)** _(Size = 130 mb, high performance and accuracy, with longer detection time)_
* **[YOLOv3](https://github.com/OlafenwaMoses/ImageAI/releases/download/3.0.0-pretrained/yolov3.pt)** _(Size = 237 mb, moderate performance and accuracy, with a moderate detection time)_
* **[TinyYOLOv3](https://github.com/OlafenwaMoses/ImageAI/releases/download/3.0.0-pretrained/tiny-yolov3.pt)** _(Size = 34 mb, optimized for speed and moderate performance, with fast detection time)_
Once you download the object detection model file, you should copy the model file to the your project folder where your .py files will be.
Then create a python file and give it a name; an example is FirstObjectDetection.py. Then write the code below into the python file:
### FirstObjectDetection.py
<div id="firstdetection" ></div>
```python
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("--------------------------------")
```
Sample Result:
Input Image
![Input Image](../../data-images/image2.jpg)
Output Image
![Output Image](../../data-images/yolo.jpg)
```
laptop : 87.32235431671143 : (306, 238, 390, 284)
--------------------------------
laptop : 96.86298966407776 : (121, 209, 258, 293)
--------------------------------
laptop : 98.6301600933075 : (279, 321, 401, 425)
--------------------------------
laptop : 99.78572130203247 : (451, 204, 579, 285)
--------------------------------
bed : 94.02391314506531 : (23, 205, 708, 553)
--------------------------------
apple : 48.03136885166168 : (527, 343, 557, 364)
--------------------------------
cup : 34.09906327724457 : (462, 347, 496, 379)
--------------------------------
cup : 44.65090036392212 : (582, 342, 618, 386)
--------------------------------
person : 57.70219564437866 : (27, 311, 341, 437)
--------------------------------
person : 85.26121377944946 : (304, 173, 387, 253)
--------------------------------
person : 96.33603692054749 : (415, 130, 538, 266)
--------------------------------
person : 96.95255160331726 : (174, 108, 278, 269)
--------------------------------
```
Let us make a breakdown of the object detection code that we used above.
```python
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
```
In the 3 lines above , we import the **ImageAI object detection** class in the first line, import the `os` in the second line and obtained the path to folder where our python file runs.
```python
detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolov3.pt"))
detector.loadModel()
```
In the 4 lines above, we created a new instance of the `ObjectDetection` class in the first line, set the model type to YOLOv3 in the second line, set the model path to the YOLOv3 model file we downloaded and copied to the python file folder in the third line and load the model in the fourth line.
```python
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image2.jpg"), output_image_path=os.path.join(execution_path , "image2new.jpg"))
for eachObject in detections:
print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("--------------------------------")
```
In the 2 lines above, we ran the `detectObjectsFromImage()` function and parse in the path to our image, and the path to the new image which the function will save. Then the function returns an array of dictionaries with each dictionary corresponding to the number of objects detected in the image. Each dictionary has the properties `name` (name of the object), `percentage_probability` (percentage probability of the detection) and `box_points` (the x1,y1,x2 and y2 coordinates of the bounding box of the object).
Should you want to use the RetinaNet which is appropriate for high-performance and high-accuracy demanding detection tasks, you will download the RetinaNet model file from the links above, copy it to your python file's folder, set the model type and model path in your python code as seen below:
```python
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "retinanet_resnet50_fpn_coco-eeacb38b.pth"))
detector.loadModel()
```
However, if you desire TinyYOLOv3 which is optimized for speed and embedded devices, you will download the TinyYOLOv3 model file from the links above, copy it to your python file's folder, set the model type and model path in your python code as seen below:
```python
detector = ObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath( os.path.join(execution_path , "tiny-yolov3.pt"))
detector.loadModel()
```
## Object Detection, Extraction and Fine-tune
<div id="objectextraction" ></div>
In the examples we used above, we ran the object detection on an image and it returned the detected objects in an array as well as save a new image with rectangular markers drawn on each object. In our next examples, we will be able to extract each object from the input image
and save it independently.
In the example code below which is very identical to the previous object
没有合适的资源?快使用搜索试试~ 我知道了~
AI 图像识别和视频分析
共225个文件
py:120个
jpg:67个
md:18个
需积分: 5 5 下载量 26 浏览量
2023-09-02
17:05:18
上传
评论
收藏 44.18MB ZIP 举报
温馨提示
ImageAI 是一个用于计算机视觉任务的开源Python库,它简化了图像处理和分析的任务。ImageAI构建在一些流行的深度学习框架(如TensorFlow、Keras和OpenCV)之上,使开发人员能够轻松地执行各种计算机视觉任务,包括对象检测、图像识别、文本识别和视频分析等。以下是ImageAI的一些主要特点和功能: **1. 对象检测:** ImageAI支持目标检测任务,可用于识别图像中的对象、物体或人脸。它预训练了一些常用的检测模型,如YOLO(You Only Look Once)和RetinaNet。 **2. 图像识别:** 该库允许您构建和训练图像分类模型,以识别图像中的物体、场景或情感。您可以使用预训练的模型或自己的自定义模型。 **3. 视频分析:** ImageAI支持对视频进行分析,包括视频对象检测、视频跟踪和视频分析。这对于监控、视频监控和视频内容分析非常有用。 **4. 文本识别:** 除了图像处理,ImageAI还支持文本识别任务,如识别图像中的文本或文档中的文本。 **5. 简化接口:** ImageAI提供了简单而直观的API,使开发人员
资源推荐
资源详情
资源评论
收起资源包目录
AI 图像识别和视频分析 (225个子文件)
customvideodetection.gif 1.44MB
.gitignore 3KB
MANIFEST.in 88B
1.jpg 2.02MB
6flash.jpg 718KB
image3custom.jpg 621KB
image3new.jpg 611KB
nodetails.jpg 608KB
2.jpg 588KB
5flash.jpg 561KB
5faster.jpg 549KB
5fast.jpg 547KB
5fastest.jpg 545KB
5normal.jpg 544KB
image2detected.jpg 408KB
image2new.jpg 408KB
yolo.jpg 399KB
4.jpg 300KB
5.jpg 220KB
image3.jpg 212KB
headsets.jpg 185KB
idenprof.jpg 177KB
6.jpg 152KB
video1.jpg 117KB
video-2.jpg 111KB
video-4.jpg 110KB
8.jpg 99KB
video-3.jpg 98KB
11.jpg 96KB
holo1.jpg 94KB
customvideodetection.jpg 94KB
5.jpg 94KB
holo2-detected.jpg 92KB
3.jpg 86KB
holo-video-detected.jpg 81KB
video2.jpg 79KB
holo-video.jpg 79KB
holo2-nodetails.jpg 78KB
video-1.jpg 75KB
video--1.jpg 74KB
7.jpg 63KB
car-4.jpg 63KB
13.jpg 62KB
2.jpg 58KB
person-10.jpg 56KB
holo2.jpg 54KB
12.jpg 54KB
3.jpg 51KB
video_analysis_visualization.jpg 49KB
10.jpg 44KB
image2.jpg 37KB
1.jpg 34KB
supportimage.jpg 33KB
9.jpg 33KB
bicycle-5.jpg 30KB
motorcycle-3.jpg 24KB
person-7.jpg 17KB
person-6.jpg 16KB
cat-2.jpg 16KB
dog-1.jpg 14KB
person-9.jpg 12KB
4.jpg 9KB
hololens-2.jpg 8KB
person-8.jpg 7KB
hololens-3.jpg 7KB
hololens-1.jpg 2KB
hololens-6.jpg 2KB
hololens-4.jpg 1KB
hololens-5.jpg 1KB
hololens-7.jpg 1KB
LICENSE 1KB
VIDEO.md 32KB
VIDEO.md 29KB
CUSTOMDETECTIONTRAINING.md 19KB
README.md 17KB
README.md 17KB
README.md 16KB
CUSTOMTRAINING.md 15KB
CUSTOMVIDEODETECTION.md 15KB
CUSTOMVIDEODETECTION.md 15KB
CUSTOMDETECTIONTRAINING.md 11KB
README.md 11KB
CUSTOMDETECTION.md 11KB
CUSTOMDETECTION.md 10KB
CUSTOMTRAINING.md 8KB
CUSTOMCLASSIFICATION.md 7KB
README.md 6KB
CUSTOMCLASSIFICATION.md 5KB
BACKEND_MIGRATION.md 2KB
holo1.mp4 19.63MB
traffic.mp4 7.45MB
traffic-mini.mp4 2.91MB
logo1.png 19KB
logo2.png 13KB
__init__.py 65KB
__init__.py 58KB
__init__.py 48KB
__init__.py 43KB
imagenet_utils.py 36KB
__init__.py 32KB
共 225 条
- 1
- 2
- 3
资源评论
田猿笔记
- 粉丝: 2710
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功