Skip to content

Commit 6a0a570

Browse files
committed
* update qrcode.md
1 parent 886b57a commit 6a0a570

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed

components/maix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ append_srcs_dir(ADD_SRCS "src") # append source file in src dir to var ADD_S
2323
###############################################
2424

2525
###### Add required/dependent components ######
26-
list(APPEND ADD_REQUIREMENTS pybind11 python3 basic nn peripheral ext_dev vision comm network voice)
26+
list(APPEND ADD_REQUIREMENTS pybind11 python3 basic nn peripheral ext_dev vision comm network voice vision_extra)
2727
###############################################
2828

2929
###### Add link search path for requirements/libs ######

docs/doc/en/vision/qrcode.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,66 @@ List common parameters and their explanations. If you cannot find parameters tha
9494
| qrcoder_type | Set the QR code library decoder type; you can choose either `image.QRCodeDecoderType.QRCODE_DECODER_TYPE_ZBAR` or `image::QRCodeDecoderType::QRCODE_DECODER_TYPE_QUIRC`. `QRCODE_DECODER_TYPE_ZBAR` offers faster recognition speed and higher accuracy at lower resolutions. `QRCODE_DECODER_TYPE_QUIRC` is relatively faster at higher resolutions but with slightly lower accuracy. By default, `QRCODE_DECODER_TYPE_ZBAR` is used.<br />Effective in version 4.7.7 and later. | img.find_qrcodes(decoder_type=image.QRCodeDecoderType.QRCODE_DECODER_TYPE_ZBAR) |
9595

9696
This article introduces common methods. For more API details, refer to the [image](../../../api/maix/image.md) section of the API documentation.
97+
98+
## Using Hardware Acceleration for QR Code Detection
99+
100+
MaixPy includes a built-in `image.QRCodeDetector` object that can use hardware acceleration for QR code detection. At a resolution of 320x224, the maximum frame rate for a single-frame algorithm can reach 60+ fps.
101+
102+
> Note: This feature is supported in MaixPy v4.7.9 and later versions
103+
104+
### Usage
105+
106+
```python
107+
from maix import camera, display, app, image
108+
109+
cam = camera.Camera(320, 224)
110+
disp = display.Display()
111+
detector = image.QRCodeDetector()
112+
113+
while not app.need_exit():
114+
img = cam.read()
115+
116+
qrcodes = detector.detect(img)
117+
for q in qrcodes:
118+
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)
119+
120+
disp.show(img)
121+
```
122+
123+
Steps:
124+
125+
1. Import the `image`, `camera`, and `display` modules:
126+
127+
```python
128+
from maix import camera, display, app, image
129+
```
130+
131+
2. Capture and display the image:
132+
133+
```python
134+
cam = camera.Camera(320, 224)
135+
disp = display.Display()
136+
137+
while not app.need_exit():
138+
img = cam.read()
139+
disp.show(img)
140+
```
141+
142+
- Create `Camera` and `Display` objects. Use the `cam.read()` method to capture the image and the `disp.show()` method to display it.
143+
144+
3. Create a `QRCodeDetector` object for QR code detection:
145+
146+
```python
147+
detector = image.QRCodeDetector()
148+
```
149+
150+
4. Use the `detect` method to detect QR codes, saving the results in the `qrcodes` variable:
151+
152+
```python
153+
qrcodes = detector.detect(img)
154+
for q in qrcodes:
155+
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)
156+
```
157+
158+
- Note: The detection process will utilize NPU resources. If other models are using the NPU at the same time, it may cause unexpected results.
159+
- The structure of the detection result is the same as the data returned by `find_qrcodes`. Refer to the `QRCode` object's methods to access the detection results. For example, calling `q.payload()` will retrieve the QR code's content string.

docs/doc/zh/vision/qrcode.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ update:
55
author: lxowalle
66
version: 1.0.0
77
content: 初版文档
8+
89
---
910

1011
阅读本文前,确保已经知晓如何开发MaixCAM,详情请阅读[快速开始](../README.md)
@@ -96,3 +97,65 @@ while 1:
9697

9798
本文介绍常用方法,更多 API 请看 API 文档的 [image](../../../api/maix/image.md) 部分。
9899

100+
## 使用硬件加速的方法识别二维码
101+
102+
MaixPy内置了一个`image.QRCodeDetector`对象可以使用硬件加速的方法识别二维码,在320x224分辨率下单帧算法最高速度可以到60+fps
103+
104+
> 注:MaixPy v4.7.8之后的版本支持该方法(不包括v4.7.8)
105+
106+
### 使用方法
107+
108+
```python
109+
from maix import camera, display, app, image
110+
111+
cam = camera.Camera(320, 224)
112+
disp = display.Display()
113+
detector = image.QRCodeDetector()
114+
115+
while not app.need_exit():
116+
img = cam.read()
117+
118+
qrcodes = detector.detect(img)
119+
for q in qrcodes:
120+
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)
121+
122+
disp.show(img)
123+
```
124+
125+
步骤:
126+
127+
1. 导入image、camera、display模块
128+
129+
```python
130+
from maix import camera, display, app, image
131+
```
132+
133+
2. 捕获和显示图像
134+
135+
```python
136+
cam = camera.Camera(320, 224)
137+
disp = display.Display()
138+
139+
while not app.need_exit():
140+
img = cam.read()
141+
disp.show(img)
142+
```
143+
144+
- 创建`Camera``Display`对象,通过`cam.read()`方法来捕获图像,用`disp.show()`方法来显示图像
145+
146+
3. 创建`QRCodeDetector`对象来检测二维码
147+
148+
```python
149+
detector = image.QRCodeDetector()
150+
```
151+
152+
4. 使用`detect`方法来检测二维码,检测结果保存到`qrcodes`变量中
153+
154+
```python
155+
qrcodes = detector.detect(img)
156+
for q in qrcodes:
157+
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)
158+
```
159+
160+
- 注意:检测过程中会占用NPU资源,如果此时有其他模型也再使用,则可能导致意外的结果
161+
- 检测的结果与`find_qrcodes`返回结果的数据结构一致,参考`QRCode`对象的方法来获取检测结果。例如:调用`q.payload()`即可获取二维码的内容字符串。
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from maix import camera, display, app, time, image
2+
3+
cam = camera.Camera(320, 224)
4+
disp = display.Display()
5+
detector = image.QRCodeDetector()
6+
while not app.need_exit():
7+
img = cam.read()
8+
9+
t = time.ticks_ms()
10+
qrcodes = detector.detect(img)
11+
t2 = time.ticks_ms()
12+
print(f"detect use {t2 - t} ms, fps:{1000 / (t2 - t)}")
13+
for q in qrcodes:
14+
corners = q.corners()
15+
for i in range(4):
16+
img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], image.COLOR_RED)
17+
img.draw_string(0, 0, "payload: " + q.payload(), image.COLOR_BLUE)
18+
19+
disp.show(img)
20+

0 commit comments

Comments
 (0)