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")

定位並辨識 AprilTags

AprilTags 是二維基準標記——對運動模糊和部分遮擋具有強健性,並可提供完整的 3D 姿態資訊。

內建偵測器——無需模型檔案或訓練。
回傳 ID 及完整 6-DoF 姿態——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")

讀取一維條碼

在畫面中任意位置尋找一維條碼並解碼其內容。

ZBar 函式庫驅動——支援辨識 EAN、UPC、Code 39/93/128、Codabar、ITF、ISBN 與 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 Hand Landmarks 模型在每隻偵測到的手上標記 21 個關節——手腕、指節與指尖。

/rom/hand_landmarks_full_224.tflite 載入——此處獨立運行,不依賴上游手掌偵測。
每隻手回傳一個清單——索引 0 為左手,索引 1 為右手。
ml.utils.draw_skeleton 在單次呼叫中繪製所有 21 個關節與連線。

OpenMV 新手?

從逐步教學開始——涵蓋硬體設定、IDE、基本腳本以及您第一個實際專案的技巧。

核心函式庫

硬體、相機、影像處理、ndarray、ML、多工、網路、網頁伺服器與藍牙——全部透過 MicroPython。

檢視所有函式庫 →

依開發板瀏覽

選擇您的 OpenMV Cam 以查看其接腳圖、規格與開發板專屬快速參考。

檢視所有支援的開發板 →

擴充板

插入 OpenMV Cam 的附加板——網路、馬達控制、顯示器等更多功能。

檢視所有擴充板 →

感測器

插入板對板連接器的相機模組與感測器轉接器——彩色、單色、熱像儀與事件式視覺。

檢視所有感測器 →

更多資源

社群 & 連結