|
| 1 | +--- |
| 2 | +title: Using PicoClaw with MaixCAM / MaixCAM2 |
| 3 | +--- |
| 4 | + |
| 5 | +## What Is PicoClaw |
| 6 | + |
| 7 | +[PicoClaw](https://github.com/sipeed/picoclaw) is a lightweight open-source AI Agent project initiated by Sipeed. It is written in Go and can run on PCs, MaixCAM / MaixCAM2, Raspberry Pi, LicheeRV-Nano, and other Linux devices. |
| 8 | + |
| 9 | +After PicoClaw is running on MaixCAM / MaixCAM2, you can ask it from the PicoClaw conversation UI to operate the device itself, such as creating and running MaixPy scripts, opening the camera, running a YOLO model, reading the detection result, and replying to you. |
| 10 | + |
| 11 | +## Preparation |
| 12 | + |
| 13 | +1. Connect MaixCAM / MaixCAM2 to the network. |
| 14 | +2. Install the `picoclaw` executable for the current device architecture according to the official PicoClaw documentation. See [PicoClaw documentation](https://docs.picoclaw.io/). |
| 15 | +3. Configure the model provider, API key, and other PicoClaw settings according to the PicoClaw documentation. |
| 16 | + |
| 17 | +You can check the device architecture in the MaixCAM / MaixCAM2 terminal: |
| 18 | + |
| 19 | +```bash |
| 20 | +uname -m |
| 21 | +``` |
| 22 | + |
| 23 | +After configuration, run a simple test on the device: |
| 24 | + |
| 25 | +```bash |
| 26 | +picoclaw agent -m "Hello, reply with one sentence to confirm you are running on this device." |
| 27 | +``` |
| 28 | + |
| 29 | +You can also use the web UI or terminal UI provided by PicoClaw. Follow the PicoClaw documentation for the exact usage. |
| 30 | + |
| 31 | +## Run One Person Detection Through PicoClaw |
| 32 | + |
| 33 | +The workflow of this example is: |
| 34 | + |
| 35 | +1. You send a task in the PicoClaw conversation UI. |
| 36 | +2. PicoClaw creates a MaixPy script on the MaixCAM / MaixCAM2 device. |
| 37 | +3. PicoClaw runs the script. |
| 38 | +4. The script opens the camera and uses YOLO to detect `person`. |
| 39 | +5. If a person is detected, the script prints the detection result and saves an annotated image. PicoClaw then replies to you according to the output. |
| 40 | + |
| 41 | +You can send this prompt to PicoClaw: |
| 42 | + |
| 43 | +```txt |
| 44 | +Refer to https://wiki.sipeed.com/maixpy/doc/en/index.html, create /root/picoclaw_person_detect.py on the current device, and do the following: |
| 45 | +1. Write a MaixPy program: open the camera, use a YOLO model to detect person, and run for at most 15 seconds. |
| 46 | +2. If person is detected, save the annotated image to /root/person_detected.jpg, and output PICOCLAW_PERSON_DETECTED, confidence, and coordinates; if no person is detected, output PICOCLAW_NO_PERSON. |
| 47 | +3. Then run python /root/picoclaw_person_detect.py and notify me according to the output. |
| 48 | +``` |
| 49 | + |
| 50 | +After thinking, PicoClaw generates a script like the following. It is recommended to choose a capable model; otherwise, it may generate incorrect code: |
| 51 | + |
| 52 | +```python |
| 53 | +from maix import camera, display, image, nn, app, time |
| 54 | + |
| 55 | +MODEL_PATH = "/root/models/yolov5s.mud" |
| 56 | +TIMEOUT_MS = 15000 |
| 57 | +OUT_IMAGE = "/root/person_detected.jpg" |
| 58 | + |
| 59 | +detector = nn.YOLOv5(model=MODEL_PATH, dual_buff=True) |
| 60 | +# To use a YOLO11 model, change it to: |
| 61 | +# detector = nn.YOLO11(model="/root/models/yolo11n.mud", dual_buff=True) |
| 62 | + |
| 63 | +cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) |
| 64 | +disp = display.Display() |
| 65 | + |
| 66 | +start = time.ticks_ms() |
| 67 | +detected = False |
| 68 | + |
| 69 | +while not app.need_exit(): |
| 70 | + img = cam.read() |
| 71 | + objs = detector.detect(img, conf_th=0.5, iou_th=0.45) |
| 72 | + |
| 73 | + for obj in objs: |
| 74 | + class_name = detector.labels[obj.class_id] |
| 75 | + img.draw_rect(obj.x, obj.y, obj.w, obj.h, color=image.COLOR_RED) |
| 76 | + img.draw_string(obj.x, obj.y, f"{class_name}: {obj.score:.2f}", color=image.COLOR_RED) |
| 77 | + |
| 78 | + if class_name == "person": |
| 79 | + img.save(OUT_IMAGE) |
| 80 | + print( |
| 81 | + "PICOCLAW_PERSON_DETECTED " |
| 82 | + f"score={obj.score:.2f} " |
| 83 | + f"x={obj.x} y={obj.y} w={obj.w} h={obj.h} " |
| 84 | + f"image={OUT_IMAGE}" |
| 85 | + ) |
| 86 | + detected = True |
| 87 | + break |
| 88 | + |
| 89 | + disp.show(img) |
| 90 | + |
| 91 | + if detected: |
| 92 | + break |
| 93 | + if time.ticks_ms() - start > TIMEOUT_MS: |
| 94 | + break |
| 95 | + |
| 96 | +if not detected: |
| 97 | + print(f"PICOCLAW_NO_PERSON timeout_ms={TIMEOUT_MS}") |
| 98 | +``` |
| 99 | + |
| 100 | +If PicoClaw sees output similar to: |
| 101 | + |
| 102 | +```txt |
| 103 | +PICOCLAW_PERSON_DETECTED score=0.86 x=120 y=60 w=80 h=180 image=/root/person_detected.jpg |
| 104 | +``` |
| 105 | + |
| 106 | +it means a person was detected, and the annotated image is saved to `/root/person_detected.jpg`. |
| 107 | + |
| 108 | +## Model Path |
| 109 | + |
| 110 | +The example uses the common MaixCAM model path by default: |
| 111 | + |
| 112 | +```python |
| 113 | +MODEL_PATH = "/root/models/yolov5s.mud" |
| 114 | +``` |
| 115 | + |
| 116 | +If you are using MaixCAM2, or if a YOLO11 model is already available on your system, change it to: |
| 117 | + |
| 118 | +```python |
| 119 | +MODEL_PATH = "/root/models/yolo11n.mud" |
| 120 | +detector = nn.YOLO11(model=MODEL_PATH, dual_buff=True) |
| 121 | +``` |
| 122 | + |
| 123 | +The actual model path depends on the files in `/root/models/` on your device. For more YOLO usage, see [YOLO object detection](../vision/yolov5.md). |
0 commit comments