juechafun/05-原子化笔记本/MaixCam-find_blobs说明.md

69 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#领域/MaixCam
20260105-备忘-主题名-文件内容
## 模板变更
- 20260105(`v1.0.1`):增加分割线区分提示内容和实际内容
- 20260105(`v1.0.0`):模板创建
---
## 一句话描述
说明 Image.find_bobs 函数
## 核心定义
查找图像中的所有色块blobs / 连通域),并返回一个 `image.Blob` 类的列表,每个 `image.Blob` 实例用于描述一个色块
## 最小实现代码
```python
img = cam.read()
...
blobs = img.find_blobs((0, 100, -129, 129, -129, 129),
pixels_threshold=200,
merge=True,
margin=5
)
```
## 函数定义
```python
def find_blobs(
self,
thresholds: list[list[int]] = [],
invert: bool = False,
roi: list[int] = [],
x_stride: int = 2,
y_stride: int = 1,
area_threshold: int = 10,
pixels_threshold: int = 10,
merge: bool = False,
margin: int = 0,
x_hist_bins_max: int = 0,
y_hist_bins_max: int = 0
) -> list[Blob]:
```
## 参数说明
| 参数名 | 描述 |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| thresholds | 可定义多个阈值:<br><br>- 灰度GRAYSCALE格式使用 `{{Lmin, Lmax}, ...}` 定义一个或多个阈值;<br><br>- RGB888 格式:使用 `{{Lmin, Lmax, Amin, Amax, Bmin, Bmax}, ...}` 定义一个或多个阈值;<br><br>其中大写 L/A/B 代表 LAB 图像格式的对应通道min/max 代表对应通道的最小值和最大值。 |
| invert | 若设为 True会在查找色块前反转阈值默认值为 False。 |
| roi | 感兴趣区域ROI输入格式为 `(x, y, w, h)`x 和 y 为左上角坐标w 和 h 为 ROI 的宽度和高度;默认值为空列表,代表处理整张图像。 |
| x_stride | X 方向步长,即执行霍夫变换时跳过的 X 方向像素数,默认值为 2。 |
| y_stride | Y 方向步长,即执行霍夫变换时跳过的 Y 方向像素数,默认值为 1。 |
| area_threshold | 面积阈值:若色块面积小于该值,则不返回该色块,默认值为 10。 |
| pixels_threshold | 像素数阈值:若色块的像素数量小于该值,则不返回该色块,默认值为 10<br><br>当 x_stride 和 y_stride 均为 1 时,该参数与 area_threshold 等效。 |
| merge | 若设为 True会合并所有未被过滤、且外接矩形相交的色块默认值为 False。 |
| margin | 边距:用于在相交检测时扩大 / 缩小色块外接矩形的尺寸;例如,边距设为 1 时,外接矩形间距为 1 像素的色块会被合并,默认值为 0。 |
| x_hist_bins_max | 若设为非 0 值,会在每个色块对象中填充一个直方图缓冲区,存储该对象所有列的 X 方向直方图投影;该值用于设置投影的分箱数,默认值为 0。 |
| y_hist_bins_max | 若设为非 0 值,会在每个色块对象中填充一个直方图缓冲区,存储该对象所有行的 Y 方向直方图投影;该值用于设置投影的分箱数,默认值为 0。 |
## 关联资源
- [MaixPy API - find_blobs](https://wiki.sipeed.com/maixpy/api/maix/image.html#find_blobs)