Skip to content

Commit

Permalink
optimize doc display var and update python usage doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Nov 28, 2024
1 parent e333aba commit 886b57a
Show file tree
Hide file tree
Showing 37 changed files with 99 additions and 89 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ from maix import camera, display, image, nn

classifier = nn.Classifier(model="/root/models/mobilenetv2.mud")
cam = camera.Camera(classifier.input_width(), classifier.input_height(), classifier.input_format())
dis = display.Display()
disp = display.Display()

while 1:
img = cam.read()
res = classifier.classify(img)
max_idx, max_prob = res[0]
msg = f"{max_prob:5.2f}: {classifier.labels[max_idx]}"
img.draw_string(10, 10, msg, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

Result video:
Expand Down
5 changes: 5 additions & 0 deletions docs/doc/en/basic/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ install_app(pkg_path)
- Since touchscreens are standard, it is recommended to create a simple interface with touch interaction. You can refer to examples for implementation methods.
- Avoid making interfaces and buttons too small, as MaixCAM default screen is 2.3 inches with 552x368 resolution and high PPI. Make sure fingers can easily tap without making mistakes.
- Implement a simple serial interaction for the main functionality of each application based on the [serial protocol](https://github.com/sipeed/MaixCDK/blob/master/docs/doc/convention/protocol.md) (see [example](https://github.com/sipeed/MaixPy/tree/main/examples/communication/protocol)). This way, users can directly use it as a serial module. For instance, in a face detection application, you can output coordinates via serial port when a face is detected.

## APP power on auto start

Refer to [APP auto start on power up](./auto_start.md).

2 changes: 1 addition & 1 deletion docs/doc/en/basic/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ After mastering the basic syntax, you will be able to use MaixPy for programming

### Using Built-in Packages

Python comes with many commonly used packages and APIs built-in, so if you encounter any issues, you can search for “Python using xxxx” and you might find a solution right away. This applies to various common tasks, such as file handling, networking, system operations, algorithms, and more.
Python comes with many commonly used packages and APIs built-in, so if you encounter any issues, you can search for “Python using xxxx” and you might find a solution right away. This applies to various common tasks, such as file handling, multi thread, multi process, networking, system operations, algorithms, and more.

For example:
For those who are new to Python and have only dabbled in basic microcontroller development, they might wonder why there are no examples in the documentation for reading and writing to SD/TF cards. The reason is that a file system is already running on the SD/TF card by default, so you can use Python’s file handling APIs to read and write files directly on the SD card:
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/en/comm/maix_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
dis.show(img)
disp.show(img)
```
You can see that `objs` is a list of detection results. Here, we draw bounding boxes on the screen, but we can also send these results via UART.

Expand Down
38 changes: 19 additions & 19 deletions docs/doc/en/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,25 @@ This is not an error message. It is a log message indicating that the multimedia

By default only support English charactors, if you want to show Chinese, you need to change font, refer to [Custom fonts part of image basic operation](./vision/image_ops.md#Chinese-support-and-custom-fonts)

## Program Exits with Prompt: app exit with code: 1

This occurs because the program encountered an error and exited abnormally. You need to check the logs to identify the issue. Here's how to check the logs:

### Method 1:
1. First, use **MaixVision** to connect to the device, ensuring all programs occupying the display and camera are closed.
2. Then connect to the device via **SSH** to access the SSH terminal. For details on connecting, refer to the [Linux Basics](./basic/linux_basic.md).
3. Execute the following commands:
- For Python programs:
```bash
cd /maixapp/apps/xxx && python main.py
```
Here, `xxx` is the ID of the application that encountered the error.
- For non-Python programs:
```bash
cd /maixapp/apps/xxx && ./xxx
```
Again, `xxx` is the ID of the application that encountered the error.
4. Carefully review the logs to check for errors. Note that errors might not always be at the last line, so check thoroughly from the end upward.
### Program Exit and Message: "app exit with code: 1, log in /maixapp/tmp/last_run.log"

This indicates that the program encountered an error and exited unexpectedly. You need to check the log to find the issue.

#### How to Check the Logs:

- **Method 1**: View the `/maixapp/tmp/last_run.log` file immediately after the error:
1. On MaixVision, run the script `MaixPy/examples/tools/show_last_run_log.py` to view the log.
2. On an SSH terminal, use the command `cat /maixapp/tmp/last_run.log` to view the log.

- **Method 2**:
- First, use MaixVision to connect to the device to exit any programs that are using the display or camera.
- Then, connect to the device via SSH and enter the SSH terminal. For connection steps, refer to the [Linux Basics](./basic/linux_basic.md).
- Manually run the program using the following commands:
- If it's a Python program: `cd /maixapp/apps/xxx && python main.py`, where `xxx` is the ID of the application that encountered the error.
- If it's not a Python program: `cd /maixapp/apps/xxx && ./xxx`, where `xxx` is the ID of the application that encountered the error.
- Carefully examine the logs for any errors. Note that the error may not appear on the last line, so check the logs from the bottom upwards.

- **Method 3**: If the application is written in Python, use MaixVision to run the source code to view runtime errors and fix them. Again, be aware that the error may not appear on the last line, so check the logs carefully from the bottom upwards.

### Method 2:
If the application is written in Python, use **MaixVision** to run the source code directly, examine the runtime errors, and make corrections. Be aware that errors may not be at the last line, so inspect the logs carefully from the end upward.
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/body_key_points.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ detector = nn.YOLOv8(model="/root/models/yolov8n_pose.mud", dual_buff=True)
# detector = nn.YOLO11(model="/root/models/yolo11n_pose.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -31,7 +31,7 @@ while not app.need_exit():
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color=image.COLOR_RED)
detector.draw_pose(img, obj.points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

You can also find the code in the [MaixPy/examples/vision](https://github.com/sipeed/MaixPy/tree/main/examples/vision/ai_vision) directory.
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/classify.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ from maix import camera, display, image, nn

classifier = nn.Classifier(model="/root/models/mobilenetv2.mud", dual_buff = True)
cam = camera.Camera(classifier.input_width(), classifier.input_height(), classifier.input_format())
dis = display.Display()
disp = display.Display()

while 1:
img = cam.read()
res = classifier.classify(img)
max_idx, max_prob = res[0]
msg = f"{max_prob:5.2f}: {classifier.labels[max_idx]}"
img.draw_string(10, 10, msg, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

Result video:
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/dual_buff.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ detector = nn.YOLOv5(model="/root/models/yolov5s.mud", dual_buff=True)
# detector = nn.YOLOv8(model="/root/models/yolov8n.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -22,7 +22,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
dis.show(img)
disp.show(img)
```

Generally, this parameter defaults to `True`, unless you manually set `dual_buff=False` to disable the dual buffer function.
Expand Down
8 changes: 4 additions & 4 deletions docs/doc/en/vision/face_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from maix import camera, display, image, nn, app
detector = nn.YOLOv8(model="/root/models/yolov8n_face.mud", dual_buff = True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -34,7 +34,7 @@ while not app.need_exit():
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
detector.draw_pose(img, obj.points, 2, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

For the other two models:
Expand All @@ -48,7 +48,7 @@ detector = nn.Retinaface(model="/root/models/retinaface.mud")
# detector = nn.FaceDetector(model="/root/models/face_detector.mud")

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -57,7 +57,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
radius = math.ceil(obj.w / 10)
img.draw_keypoints(obj.points, image.COLOR_RED, size = radius if radius < 5 else 4)
dis.show(img)
disp.show(img)
```

## Model Downloads and Other Resolution Models
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/face_recognition.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ recognizer = nn.FaceRecognizer(detect_model="/root/models/yolov8n_face.mud", fea
if os.path.exists("/root/faces.bin"):
recognizer.load_faces("/root/faces.bin")
cam = camera.Camera(recognizer.input_width(), recognizer.input_height(), recognizer.input_format())
dis = display.Display()
disp = display.Display()

while 1:
img = cam.read()
Expand All @@ -44,7 +44,7 @@ while 1:
img.draw_keypoints(obj.points, image.COLOR_RED, size = radius if radius < 5 else 4)
msg = f'{recognizer.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
dis.show(img)
disp.show(img)
```

When you first run this code, it can detect faces but will not recognize them. We need to enter a mode to learn faces.
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/ocr.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ model = "/root/models/pp_ocr.mud"
ocr = nn.PP_OCR(model)

cam = camera.Camera(ocr.input_width(), ocr.input_height(), ocr.input_format())
dis = display.Display()
disp = display.Display()

image.load_font("ppocr", "/maixapp/share/font/ppocr_keys_v1.ttf", size = 20)
image.set_default_font("ppocr")
Expand All @@ -39,7 +39,7 @@ while not app.need_exit():
points = obj.box.to_list()
img.draw_keypoints(points, image.COLOR_RED, 4, -1, 1)
img.draw_string(obj.box.x4, obj.box.y4, obj.char_str(), image.COLOR_RED)
dis.show(img)
disp.show(img)
```

You can see that `ocr = nn.PP_OCR(model)` loads the model, and then `ocr.detect(img)` detects and recognizes the text, displaying the results on the screen.
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/segmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ detector = nn.YOLOv8(model="/root/models/yolov8n_seg.mud", dual_buff=True)
# detector = nn.YOLO11(model="/root/models/yolo11n_seg.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -37,7 +37,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color=image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color=image.COLOR_RED)
dis.show(img)
disp.show(img)
```

> To switch between YOLOv8 and YOLO11, just modify the commented part of the above code.
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/en/vision/yolov5.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ detector = nn.YOLOv5(model="/root/models/yolov5s.mud", dual_buff=True)
# detector = nn.YOLO11(model="/root/models/yolo11n.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -31,7 +31,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color=image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color=image.COLOR_RED)
dis.show(img)
disp.show(img)
```

Example video:
Expand Down
2 changes: 2 additions & 0 deletions docs/doc/zh/basic/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ title: MaixCAM MaixPy 应用开发和应用商店
* 每个应用实现的主要功能实现一个简单的串口交互,基于[串口协议](https://github.com/sipeed/MaixCDK/blob/master/docs/doc/convention/protocol.md)[例程](https://github.com/sipeed/MaixPy/tree/main/examples/communication/protocol)),这样用户可以直接当成串口模块使用,比如人脸检测应用,可以在检测到人脸后通过串口输出坐标。


## 设置应用开机自动启动

参考 [应用开机自启](./auto_start.md)



Expand Down
2 changes: 1 addition & 1 deletion docs/doc/zh/basic/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Python 是一门解释性、面向对象、动态类型的高级编程语言。
## 使用内置的软件包

Python 已经内置了很多常用的软件包和 API,所以遇到什么问题可以搜索`“Python 使用 xxxx"`说不定就能直接能用。
比如常见的 文件、网络、系统、算法等等。
比如常见的 文件、多线程、多进程、网络、系统、算法等等。

举个例子:
对于没有接触过 Python, 只涉略过初级的单片机开发的同学来说,可能会有些疑问为什么文档没有读写 SD/TF 卡的例程:
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/zh/comm/maix_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
dis.show(img)
disp.show(img)
```
可以看到`objs`是多个检测结果,这里在屏幕上进行画框了,我们也可以在这里想办法把结果通过串口发送出去。
这里我们不需要手动初始化串口,直接使用内置的`maix.comm, maix.protocol`模块,调用`comm.CommProtoco`会自动初始化串口,默认波特率是`115200`,串口协议的相关可以在设备`系统设置->通信协议`里面设置。
Expand Down
11 changes: 7 additions & 4 deletions docs/doc/zh/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,21 @@ ImportError: arg(): could not convert default argument into a Python object (typ
默认只有英文字体,如果要显示中文,需要更换中文字体,具体请看[基本图像操作 中文支持和自定义字体 部分](./vision/image_ops.md#中文支持和自定义字体)


## 程序退出并提示 app exit with code: 1
## 程序退出并提示 app exit with code: 1, log in /maixapp/tmp/last_run.log

这是因为程序出错异常退出了,需要尝试看日志来找到问题所在。
看日志方法:
* 方法一:
* 先使用 MaixVision 连接上设备以让所有占用显示和摄像头的程序退出
* 方法一: 出错后立即查看 `/maixapp/tmp/last_run.log` 文件,查看方式:
1. MaixVision 运行 `MaixPy/examples/tools/show_last_run_log.py` 代码查看。
2. 在 ssh 终端中 `cat /maixapp/tmp/last_run.log` 查看。
* 方法二:
* 先使用 MaixVision 连接上设备以让所有占用显示和摄像头的程序退出。
* 然后通过 ssh 连接设备进入 ssh 终端,进入方法见[Linux 基础](./basic/linux_basic.md) 中描述。
* 执行命令手动运行程序
* 如果是 Python 程序 `cd /maixapp/apps/xxx && python main.py` 这里 `xxx`是出错应用的 ID。
* 如果不是 Python 程序 `cd /maixapp/apps/xxx && ./xxx` 这里 `xxx`是出错应用的 ID。
* 仔细查看日志看有没有报错,注意报错可能不在最后一行,可以从后往前仔细查找。
* 方法二:如果是 Python 编写的应用,使用 MaixVision 运行源码查看运行错误并修正,注意报错可能不在最后一行,可以从后往前仔细查找。
* 方法三:如果是 Python 编写的应用,使用 MaixVision 运行源码查看运行错误并修正,注意报错可能不在最后一行,可以从后往前仔细查找。


## 如何读写 SD/TF 卡,保存数据到 SD/TF 卡
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/zh/vision/body_key_points.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ detector = nn.YOLOv8(model="/root/models/yolov8n_pose.mud", dual_buff = True)
# detector = nn.YOLO11(model="/root/models/yolo11n_pose.mud", dual_buff = True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -32,7 +32,7 @@ while not app.need_exit():
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
detector.draw_pose(img, obj.points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

另外代码也在[MaixPy/examples/vision](https://github.com/sipeed/MaixPy/tree/main/examples/vision/ai_vision)目录下可以找到。
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/zh/vision/classify.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ from maix import camera, display, image, nn

classifier = nn.Classifier(model="/root/models/mobilenetv2.mud", dual_buff = True)
cam = camera.Camera(classifier.input_width(), classifier.input_height(), classifier.input_format())
dis = display.Display()
disp = display.Display()

while 1:
img = cam.read()
res = classifier.classify(img)
max_idx, max_prob = res[0]
msg = f"{max_prob:5.2f}: {classifier.labels[max_idx]}"
img.draw_string(10, 10, msg, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

效果视频:
Expand Down
4 changes: 2 additions & 2 deletions docs/doc/zh/vision/dual_buff.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ detector = nn.YOLOv5(model="/root/models/yolov5s.mud", dual_buff=True)
# detector = nn.YOLOv8(model="/root/models/yolov8n.mud", dual_buff=True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -22,7 +22,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
dis.show(img)
disp.show(img)
```

一般来说这个参数默认就是`True`,除非手动设置`dual_buff=False`才会关闭 `dual_buff`功能。
Expand Down
8 changes: 4 additions & 4 deletions docs/doc/zh/vision/face_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ from maix import camera, display, image, nn, app
detector = nn.YOLOv8(model="/root/models/yolov8n_face.mud", dual_buff = True)

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -35,7 +35,7 @@ while not app.need_exit():
msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}'
img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED)
detector.draw_pose(img, obj.points, 2, image.COLOR_RED)
dis.show(img)
disp.show(img)
```

另外两种模型使用方法:
Expand All @@ -50,7 +50,7 @@ detector = nn.Retinaface(model="/root/models/retinaface.mud")
# detector = nn.FaceDetector(model="/root/models/face_detector.mud")

cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format())
dis = display.Display()
disp = display.Display()

while not app.need_exit():
img = cam.read()
Expand All @@ -59,7 +59,7 @@ while not app.need_exit():
img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED)
radius = math.ceil(obj.w / 10)
img.draw_keypoints(obj.points, image.COLOR_RED, size = radius if radius < 5 else 4)
dis.show(img)
disp.show(img)

```

Expand Down
Loading

0 comments on commit 886b57a

Please sign in to comment.