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 は 2D フィデューシャルマーカーです — モーションブラーや部分的な遮蔽にも強く、完全な 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 顔検出器で、バウンディングボックスと顔ごとに 6 つのランドマークを返します。

/rom/blazeface_front_128.tflite から読み込み — 事前量子化済み、ダウンロード不要です。
顔ごとに 6 つのキーポイント: 目、鼻、口、耳。
プライバシーの懸念なし — フレームはカメラの外に出ません。
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 は 1 つ以上の LAB 閾値に一致する連続ピクセル領域を返します。

照明に合わせて閾値を調整します — まずオートゲインとオートホワイトバランスを無効にしてください。
1 回の呼び出しでマルチカラートラッキングのために複数の閾値を渡します。
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")

1D バーコードの読み取り

フレーム内の任意の場所にある 1D バーコードを検出してペイロードをデコードします。

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 から読み込み — ここでは手のひら検出なしのスタンドアロンで動作します。
手ごとに 1 つのリストを返します — インデックス 0 が左手、インデックス 1 が右手です。
ml.utils.draw_skeleton は 1 回の呼び出しで 21 のすべての関節と接続を描画します。

OpenMV が初めてですか?

ステップバイステップのチュートリアルから始めましょう — ハードウェアのセットアップ、IDE、基本スクリプト、最初の実プロジェクトのヒントを網羅しています。

コアライブラリ

ハードウェア、カメラ、画像処理、ndarray、ML、マルチタスク、ネットワーキング、ウェブサーバー、Bluetooth — すべて MicroPython から。

すべてのライブラリを見る →

ボードで探す

OpenMV Cam を選択してピン配置、仕様、ボード固有のクイックリファレンスを確認します。

対応ボードをすべて見る →

シールド

OpenMV Cam に接続するアドオンボード — ネットワーキング、モーター制御、ディスプレイなど。

すべてのシールドを見る →

センサー

ボード間コネクタに接続するカメラモジュールとセンサーアダプター — カラー、モノクロ、サーマル、イベントベースビジョン。

すべてのセンサーを見る →

その他のリソース

コミュニティ & リンク