Skip to content

Commit 3460e76

Browse files
committed
* add find barcodes doc
1 parent 0747242 commit 3460e76

File tree

5 files changed

+203
-3
lines changed

5 files changed

+203
-3
lines changed

docs/doc/en/sidebar.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ items:
4242
label: Line tracking
4343
- file: vision/qrcode.md
4444
label: QRcode identity
45+
- file: vision/find_barcodes.md
46+
label: Barcode identity
4547
- file: vision/apriltag.md
4648
label: AprilTag identity
4749
- file: vision/opencv.md
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: MaixCAM MaixPy Barcode Recognition
3+
update:
4+
- date: 2024-12-16
5+
author: lxowalle
6+
version: 1.0.0
7+
content: Initial documentation
8+
9+
---
10+
11+
Before reading this article, make sure you know how to develop with MaixCAM. For details, please read [Quick Start](../README.md).
12+
13+
## Introduction
14+
15+
This article explains how to use MaixPy for Barcode recognition.
16+
17+
18+
## Using MaixPy to Recognize Barodes
19+
20+
MaixPy's `maix.image.Image` includes the `find_barcodes` method for Barcode recognition.
21+
22+
### How to Recognize Barcodes
23+
24+
A simple example that recognizes Barcodes and draws a bounding box:
25+
26+
```python
27+
from maix import image, camera, display
28+
29+
cam = camera.Camera(480, 320)
30+
disp = display.Display()
31+
32+
while 1:
33+
img = cam.read()
34+
35+
barcodes = img.find_barcodes()
36+
for b in barcodes:
37+
rect = b.rect()
38+
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
39+
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)
40+
41+
disp.show(img)
42+
```
43+
44+
Steps:
45+
46+
1. Import the image, camera, and display modules:
47+
48+
```python
49+
from maix import image, camera, display
50+
```
51+
52+
2. Initialize the camera and display:
53+
54+
```python
55+
cam = camera.Camera(480, 320) # Initialize the camera with a resolution of 480x320 in RGB format
56+
disp = display.Display()
57+
```
58+
59+
3. Capture and display images from the camera:
60+
61+
```python
62+
while 1:
63+
img = cam.read()
64+
disp.show(img)
65+
```
66+
67+
4. Use the `find_barcodes` method to detect barcodes in the camera image:
68+
69+
```python
70+
barcodes = img.find_barcodes()
71+
```
72+
73+
- `img` is the camera image captured by `cam.read()`. When initialized as `cam = camera.Camera(480, 320)`, the `img` object is a 480x320 resolution RGB image.
74+
- `img.find_barcodes` searches for barcodes and saves the results in `barcodes` for further processing.
75+
- Note: The spacing of barcodes is small, and the width of barcodes is generally much larger than the height, so when adjusting the recognition rate and speed, you can try to make the width of the target image larger and the height smaller.
76+
77+
5. Process and display the results of barcode recognition on the screen:
78+
79+
```python
80+
for b in barcodes:
81+
rect = b.rect()
82+
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
83+
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)
84+
```
85+
86+
- `barcodes` is the result of querying barcodes by `img.find_barcodes()`, if no barcode is found then `barcodes` is empty.
87+
- `b.rect()` is used to get the position and size of the scanned barcode, `img.draw_rect()` uses the position information to draw the shape of the barcode.
88+
- `img.draw_string` is used to display the content and position of the barcode, `b.payload()` is used to get the content of the barcode.
89+
90+
91+
### 常用参数说明
92+
93+
List common parameters and their explanations. If you cannot find parameters that fit your application, consider whether to use a different algorithm or extend the functionality based on the current algorithm's results.
94+
95+
| Parameter | Description | Example |
96+
| ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
97+
| roi | Sets the rectangular area for the algorithm to compute, where roi=[x, y, w, h], x and y denote the top-left coordinates of the rectangle, and w and h denote the width and height of the rectangle, defaulting to the entire image. | Compute the area with coordinates (50,50) and width and height of 100:<br />`img.find_barcodes(roi=[50, 50, 100, 100])` |
98+
99+
This article introduces common methods. For more API details, refer to the [image](../../../api/maix/image.md) section of the API documentation.

docs/doc/zh/sidebar.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ items:
4242
label: 寻找直线
4343
- file: vision/qrcode.md
4444
label: 二维码识别
45+
- file: vision/find_barcodes.md
46+
label: 条形码识别
4547
- file: vision/apriltag.md
4648
label: AprilTag 识别
4749
- file: vision/opencv.md
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: MaixCAM MaixPy 条形码识别
3+
update:
4+
- date: 2024-12-16
5+
author: lxowalle
6+
version: 1.0.0
7+
content: 初版文档
8+
9+
---
10+
11+
阅读本文前,确保已经知晓如何开发MaixCAM,详情请阅读[快速开始](../README.md)
12+
13+
## 简介
14+
15+
本文介绍如何使用MaixPy来识别条形码
16+
17+
18+
## 使用 MaixPy 识别条形码
19+
20+
MaixPy的 `maix.image.Image`中提供了`find_barcodes`方法,用来识别条形码
21+
22+
### 如何识别条形码
23+
24+
一个简单的示例,实现识别条形码并画框
25+
26+
```python
27+
from maix import image, camera, display
28+
29+
cam = camera.Camera(480, 320)
30+
disp = display.Display()
31+
32+
while 1:
33+
img = cam.read()
34+
35+
barcodes = img.find_barcodes()
36+
for b in barcodes:
37+
rect = b.rect()
38+
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
39+
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)
40+
41+
disp.show(img)
42+
```
43+
44+
步骤:
45+
46+
1. 导入image、camera、display模块
47+
48+
```python
49+
from maix import image, camera, display
50+
```
51+
52+
2. 初始化摄像头和显示
53+
54+
```python
55+
cam = camera.Camera(480, 320) # 初始化摄像头,输出分辨率480x320 RGB格式
56+
disp = display.Display()
57+
```
58+
59+
3. 从摄像头获取图片并显示
60+
61+
```python
62+
while 1:
63+
img = cam.read()
64+
disp.show(img)
65+
```
66+
67+
4. 调用`find_barcodes`方法识别摄像头中的条形码
68+
69+
```python
70+
barcodes = img.find_barcodes()
71+
```
72+
73+
- `img`是通过`cam.read()`读取到的摄像头图像,当初始化的方式为`cam = camera.Camera(320, 240)`时,`img`对象是一张分辨率为480x320的RGB图。
74+
- `img.find_barcodes`用来寻找条形码,并将查询结果保存到`barcodes`,以供后续处理
75+
- 注意: 条形码的间距较小, 并且一般宽度远大于高度, 所以在调整识别率和识别速度时可以尽量让识别目标图像的宽度更大, 高度更小
76+
77+
5. 处理识别条形码的结果并显示到屏幕上
78+
79+
```python
80+
for b in barcodes:
81+
rect = b.rect()
82+
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
83+
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)
84+
```
85+
86+
- `barcodes`是通过`img.find_barcodes()`查询条形码的结果,如果找不到条形码则`barcodes`内部为空
87+
- `b.rect()`用来获取已扫描到的条形码的位置和大小,`img.draw_rect()`利用这些位置信息画出条形码的形状
88+
- `img.draw_string`用来显示条形码的内容和位置等信息,`b.payload()`用来获取条形码的内容
89+
90+
### 常用参数说明
91+
92+
列举常用参数说明,如果没有找到可以实现应用的参数,则需要考虑是否使用其他算法实现,或者基于目前算法的结果扩展所需的功能
93+
94+
| 参数 | 说明 | 示例 |
95+
| ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
96+
| roi | 设置算法计算的矩形区域,roi=[x, y, w, h],x,y表示矩形区域左上角坐标,w,h表示矩形区域的宽度和高度,默认为整张图片 | 计算坐标为(50,50),宽和高为100的区域<br />```img.find_barcodes(roi=[50, 50, 100, 100])``` |
97+
98+
本文介绍常用方法,更多 API 请看 API 文档的 [image](../../../api/maix/image.md) 部分。
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from maix import camera, display, image
22

3-
cam = camera.Camera(320, 240)
3+
cam = camera.Camera(480, 320)
44
disp = display.Display()
55

6-
76
while 1:
87
img = cam.read()
98

@@ -13,4 +12,4 @@
1312
img.draw_rect(rect[0], rect[1], rect[2], rect[3], image.COLOR_BLUE, 2)
1413
img.draw_string(0, 0, "payload: " + b.payload(), image.COLOR_GREEN)
1514

16-
disp.show(img)
15+
disp.show(img)

0 commit comments

Comments
 (0)