-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
tite: Target Detection with Rotation Angles (OBB, Oriented Bounding Box) | ||
update: | ||
- date: 2024-12-20 | ||
version: v1.0 | ||
author: neucrack | ||
content: | ||
Support YOLO11/YOLOv8 OBB model and add documentation | ||
--- | ||
|
||
## Introduction | ||
|
||
In standard object detection, the output is typically a rectangular bounding box. However, in certain scenarios, objects may have a rotated shape, requiring a bounding box with a rotation angle. This type of bounding box is referred to as an OBB (Oriented Bounding Box). | ||
![](../../assets/ships-detection-using-obb.jpeg) | ||
|
||
**Standard detection results:** `x, y, w, h` represent the top-left or center coordinates of the rectangle, along with its width and height. | ||
**OBB detection results:** `x, y, w, h, angle` includes an additional parameter for the rotation angle. | ||
|
||
## Using Rotated Bounding Boxes (OBB) in MaixPy MaixCAM | ||
|
||
`MaixPy` supports the `YOLO11/YOLOv8` OBB model, enabling quick and convenient implementation. Below is an example based on the `nn_yolo11_obb.py` script from [MaixPy/examples](https://github.com/sipeed/maixpy): | ||
|
||
```python | ||
from maix import camera, display, image, nn, app | ||
|
||
detector = nn.YOLO11(model="/root/models/yolo11n_obb.mud", dual_buff=True) | ||
|
||
cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) | ||
disp = display.Display() | ||
|
||
while not app.need_exit(): | ||
img = cam.read() | ||
objs = detector.detect(img, conf_th=0.5, iou_th=0.45) | ||
for obj in objs: | ||
points = obj.get_obb_points() | ||
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}, {obj.angle * 180:.1f}' | ||
img.draw_string(points[0], points[1] - 4, msg, color=image.COLOR_RED) | ||
detector.draw_pose(img, points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED, close=True) | ||
disp.show(img) | ||
``` | ||
|
||
In this example, the `YOLO11` model is used to load an OBB model. After detecting an object, the rotation angle can be accessed via `obj.angle`. The `x, y, w, h` attributes of `obj` represent the unrotated rectangle. The `get_obb_points` method retrieves the four vertices of the rotated rectangle, and `draw_pose` is used to draw the rotated bounding box. The `close` parameter ensures the vertices are connected. | ||
|
||
The default model is the official YOLO11 15-class model with the following labels: | ||
|
||
```python | ||
plane, ship, storage tank, baseball diamond, tennis court, basketball court, ground track field, harbor, bridge, large vehicle, small vehicle, helicopter, roundabout, soccer ball field, swimming pool | ||
``` | ||
|
||
The model file can be found at `/root/models/yolo11n_obb.mud`. | ||
|
||
## Customizing Your Own OBB Model for MaixPy MaixCAM | ||
|
||
### Using the Model on a Computer | ||
|
||
For an introduction to the official `YOLO11` OBB models, refer to [YOLO11 OBB](https://docs.ultralytics.com/tasks/obb/). This documentation explains how to use OBB models on a computer and export ONNX model files. | ||
|
||
### Exporting the Model for MaixCAM | ||
|
||
Follow the [YOLO11/YOLOv8 Custom Models](./customize_model_yolov8.md) guide to convert an ONNX model into a MUD model compatible with MaixCAM. | ||
**Note:** Ensure the output names of the model's layers are correctly configured during conversion. | ||
|
||
### Training Your Own OBB Model | ||
|
||
Refer to the [YOLO11 Official Training Documentation](https://docs.ultralytics.com/datasets/obb/dota-v2/) to prepare your dataset and train your own OBB model. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
tite: 带旋转角度的目标检测(OBB, Oriented Bounding Box) | ||
update: | ||
- date: 2024-12-20 | ||
version: v1.0 | ||
author: neucrack | ||
content: | ||
支持 YOLO11/YOLOv8 OBB 模型并添加文档 | ||
--- | ||
|
||
## 简介 | ||
|
||
普通的检测中输出结果是一个矩形框,但是在一些场景中,目标物体的形状是旋转的,这时候就需要输出一个带旋转角度的矩形框,这种矩形框叫做OBB(Oriented Bounding Box)。 | ||
![](../../assets/ships-detection-using-obb.jpeg) | ||
|
||
普通检测结果: x, y, w, h, 分别是 矩形框左上角或者中心点坐标,以及矩形宽高。 | ||
OBB 检测结果:x, y, w, h, angle, 多了一个旋转角度。 | ||
|
||
## MaixPy MaixCAM 中使用带旋转角度的目标检测(OBB) | ||
|
||
`MaixPy` 中移植了 `YOLO11/YOLOv8` `OBB` 模型,可以快速方便地实现, 以下为例程,以[MaixPy/examples](https://github.com/sipeed/maixpy)中的`nn_yolo11_obb.py`为准: | ||
```python | ||
from maix import camera, display, image, nn, app | ||
|
||
detector = nn.YOLO11(model="/root/models/yolo11n_obb.mud", dual_buff = True) | ||
|
||
cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) | ||
disp = display.Display() | ||
|
||
while not app.need_exit(): | ||
img = cam.read() | ||
objs = detector.detect(img, conf_th = 0.5, iou_th = 0.45) | ||
for obj in objs: | ||
points = obj.get_obb_points() | ||
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}, {obj.angle * 180:.1f}' | ||
img.draw_string(points[0], points[1] - 4, msg, color = image.COLOR_RED) | ||
detector.draw_pose(img, points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED, close=True) | ||
disp.show(img) | ||
``` | ||
|
||
可以看到这里使用`YOLO11`加载了`obb`模型,然后在检测到目标后,通过`obj.angle`获取到矩形旋转角度,`obj`的`x,y,w,h`属性是未旋转的矩形,通过`get_obb_points`获取到旋转后的矩形的四个顶点坐标,然后通过`draw_pose`绘制出目标的旋转矩形框,`close`参数表示将矩形框四个顶点连线起来。 | ||
|
||
|
||
默认的模型是 YOLO11 官方的`15`类模型,分类标签如下: | ||
```python | ||
plane, ship, storage tank, baseball diamond, tennis court, basketball court, ground track field, harbor, bridge, large vehicle, small vehicle, helicopter, roundabout, soccer ball field, swimming pool | ||
``` | ||
在`/root/models/yolo11n_obb.mud`文件中也能看到。 | ||
|
||
|
||
## MaixPy MaixCAM 自定义自己的OBB模型 | ||
|
||
### 电脑端使用模型 | ||
|
||
关于 `YOLO11` 官方的 OBB 模型介绍请看[YOLO11 OBB](https://docs.ultralytics.com/tasks/obb/)。 | ||
在这个文档中可以看到如何在电脑端使用`obb`模型,以及如何导出 ONNX 模型文件。 | ||
|
||
### 导出模型给 MaixCAM 使用 | ||
|
||
根据 [YOLO11/YOLOv8 自定义模型](./customize_model_yolov8.md) 即可将 ONNX 模型转换为 MaixCAM 可以使用的 MUD 模型。 | ||
注意:转换时需要注意输出层的输出名不要弄错。 | ||
|
||
### 训练自己的 OBB 模型 | ||
|
||
根据[YOLO11 官方训练文档](https://docs.ultralytics.com/datasets/obb/dota-v2/) 准备自己的数据集,然后进行训练即可。 | ||
|
||
|
||
|
||
|