OpenMV 固件版本 v5.0.0 · 基于 MicroPython v1.28 · 文档构建于 2026年6月19日

机器视觉,
化繁为简。

实时人脸检测、AprilTag 追踪、QR 码扫描和 YOLO,全部在设备端以纯 MicroPython 运行,无需主机,无需云端。

新增内容 查看 OpenMV 固件 v5.0.0 更新日志

Hello world

import csi
import time
import ml
from ml.postprocessing.ultralytics import YoloV8

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.snapshot(time=2000)  # let AWB/AGC stabilize

# Built-in single-class person detector model.
model = ml.Model("/rom/yolov8n_192.tflite",
                 postprocess=YoloV8(threshold=0.4))
clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    # predict returns a list per class of ((x, y, w, h), score) tuples.
    for class_dets in model.predict([img]):
        for rect, score in class_dets:
            img.draw_rectangle(rect, color=(0, 255, 0))
    print(clock.fps(), "fps")

实时人体追踪

板载 YOLOv8 模型是单类别人体检测器——经过 int8 量化并内置于 ROM 中。

/rom/yolov8n_192.tflite 加载——无需 SD 卡或下载。
在配备 NPU 的开发板(OpenMV N6 和 AE3)上实时运行。
使用在 Roboflow 上训练的自定义 YOLOv8 模型,以相同方式加载即可。
import csi
import math
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)  # let AWB/AGC stabilize
csi0.auto_gain(False)
csi0.auto_whitebal(False)

clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    for tag in img.find_apriltags():
        img.draw_detection(tag, color1=(255, 0, 0), color2=(0, 255, 0))
        deg = math.degrees(tag.rotation)
        print("ID %d  rotation %.1f deg" % (tag.id, deg))
    print(clock.fps(), "fps")

定位并识别 AprilTag

AprilTag 是二维基准标记,对运动模糊和局部遮挡具有鲁棒性,并可提供完整的三维位姿。

内置检测器——无需模型文件或训练。
返回 ID 及完整六自由度位姿——x/y/z 平移量和 x/y/z 旋转量。
适用于机器人标定、AR 标记和室内定位。
import csi
import time
import ml
from ml.postprocessing.mediapipe import BlazeFace

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.window((400, 400))  # square window for best results
csi0.snapshot(time=2000)  # let AWB/AGC stabilize

model = ml.Model("/rom/blazeface_front_128.tflite",
                 postprocess=BlazeFace(threshold=0.4))
clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    for rect, score, keypoints in model.predict([img]):
        img.draw_rectangle(rect, color=(0, 0, 255))
        ml.utils.draw_keypoints(img, keypoints, color=(255, 0, 0))
    print(clock.fps(), "fps")

使用 BlazeFace 检测人脸

Google 的 BlazeFace 是一款轻量级 TensorFlow Lite 人脸检测器,可为每张人脸返回边界框及六个关键点。

/rom/blazeface_front_128.tflite 加载——已预量化,无需下载。
每张人脸六个关键点:眼睛、鼻子、嘴巴和耳朵。
无隐私顾虑——图像帧不会离开摄像头。
import csi
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)  # let AWB/AGC stabilize
csi0.auto_gain(False)

clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    for code in img.find_qrcodes():
        img.draw_rectangle(code.rect, color=(255, 0, 0))
        print(code.payload)
    print(clock.fps(), "fps")

从实时画面中扫描 QR 码

内置 QR 解码器可处理倾斜、变形和部分遮挡的二维码。

每个结果还提供版本号、ECC 级别和角点坐标。
支持数字、字母数字、二进制和汉字数据模式。
将解码内容以 Python 字符串形式返回,可直接使用。
import csi
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)  # let AWB/AGC stabilize
csi0.auto_gain(False)
csi0.auto_whitebal(False)

# LAB thresholds: (L_min, L_max, A_min, A_max, B_min, B_max)
thresholds = [
    (30, 100, 15, 127, 15, 127),   # red
    (30, 100, -64, -8, -32, 32),   # green
]

clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    for blob in img.find_blobs(thresholds, pixels_threshold=200):
        img.draw_rectangle(blob.rect, color=(255, 0, 0))
        img.draw_cross((blob.cx, blob.cy))
    print(clock.fps(), "fps")

查找色块

find_blobs 返回与一个或多个 LAB 阈值匹配的连通像素区域。

针对当前光照调整阈值——请先关闭自动增益和自动白平衡。
在一次调用中传入多个阈值以实现多颜色追踪。
pixels_threshold 可过滤微小检测结果;merge=True 可合并重叠色块。
import csi
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.VGA)
csi0.window((640, 80))  # narrow strip for fast linear scanning
csi0.snapshot(time=2000)  # let AWB/AGC stabilize
csi0.auto_gain(False)
csi0.auto_whitebal(False)

clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    for code in img.find_barcodes():
        img.draw_rectangle(code.rect, color=(0, 255, 0))
        print(code.payload, "(quality %d)" % code.quality)
    print(clock.fps(), "fps")

读取一维条形码

在画面中任意位置查找一维条形码并解码其内容。

Powered by the ZBar library — recognises EAN, UPC, Code 39/93/128, Codabar, ITF, ISBN, and DataBar.
使用灰度窗口条带可获得最快的线性扫描速度。
每个结果包含格式、内容、旋转角度、角点和边界矩形。
import csi
import time
import ml
from ml.postprocessing.mediapipe import HandLandmarks

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.window((400, 400))  # square window for the model
csi0.snapshot(time=2000)  # let AWB/AGC stabilize

# Connections between the 21 keypoints — palm + 5 fingers.
hand_lines = ((0, 1), (1, 2), (2, 3), (3, 4), (0, 5), (5, 6),
              (6, 7), (7, 8), (5, 9), (9, 10), (10, 11), (11, 12),
              (9, 13), (13, 14), (14, 15), (15, 16), (13, 17), (17, 18),
              (18, 19), (19, 20), (0, 17))

model = ml.Model("/rom/hand_landmarks_full_224.tflite",
                 postprocess=HandLandmarks(threshold=0.4))
clock = time.clock()

while True:
    clock.tick()
    img = csi0.snapshot()
    # predict returns a list per hand: index 0 = left, index 1 = right.
    for detections in model.predict([img]):
        for rect, score, keypoints in detections:
            ml.utils.draw_skeleton(img, keypoints, hand_lines,
                                   kp_color=(255, 0, 0),
                                   line_color=(0, 255, 0))
    print(clock.fps(), "fps")

追踪 21 个手部关键点

Google 的 MediaPipe 手部关键点模型为每只检测到的手标注 21 个关节——手腕、指关节和指尖。

/rom/hand_landmarks_full_224.tflite 加载——此处独立运行,无需上游的手掌检测。
每只手返回一个列表——索引 0 为左手,索引 1 为右手。
ml.utils.draw_skeleton 一次调用即可绘制全部 21 个关节及连接线。

初次使用 OpenMV?

从分步教程开始——涵盖硬件设置、IDE、基础脚本以及第一个实际项目的技巧。

核心库

硬件、摄像头、图像处理、ndarray、机器学习、多任务、网络、Web 服务器和蓝牙——全部通过 MicroPython 实现。

查看所有库 →

按开发板浏览

选择您的 OpenMV Cam 以查看其引脚图、规格和特定开发板的快速参考。

查看所有支持的开发板 →

扩展板

可插入 OpenMV Cam 的扩展板——网络、电机控制、显示屏等。

查看所有扩展板 →

传感器

通过板对板连接器插入的摄像头模块和传感器适配器——彩色、单色、热成像和事件视觉。

查看所有传感器 →

更多资源

社区 & 链接