dual_core_vision_and_speech.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2026 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# デュアルコアビジョン&音声の例
#
# この例は、HPコアでBlazeFace顔検出を実行し、HEコアで
# MicroSpeechキーワードスポッターを同時に実行します。直近に検出された
# キーワードがカメラ画像上に描画されます。
#
# 組み込みのMicroSpeechモデルは、キーワード"Yes"と"No"のみを認識します。

import csi
import time
import openamp
import ml
from ml.postprocessing.mediapipe import BlazeFace


label = None
label_ticks = 0
LABEL_HOLD_MS = 2000


def task_callback(src_addr, data):
    global label, label_ticks
    label = data.decode()
    label_ticks = time.ticks_ms()


# この非同期関数はHEコアで実行されます。
@openamp.async_remote(task_callback)
async def task1(ept):
    from ml.apps import MicroSpeech
    speech = MicroSpeech(gain_db=24)
    while True:
        l, scores = speech.listen(timeout=0, threshold=0.70)
        if l:
            ept.send(l)


# HPコアでカメラを初期化する前に、HEコアを起動してください。
rproc = openamp.RemoteProc(0x80320000)
rproc.start()

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# BlazeFaceで最良の結果を得るには正方形の画像が必要です。
csi0.window((400, 400))

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

clock = time.clock()
while True:
    clock.tick()
    img = csi0.snapshot()

    # facesは((x, y, w, h), score, keypoints)タプルのリストです
    for r, score, keypoints in model.predict([img]):
        ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)
        ml.utils.draw_keypoints(img, keypoints, color=(255, 0, 0))

    if label is not None:
        if time.ticks_diff(time.ticks_ms(), label_ticks) < LABEL_HOLD_MS:
            img.draw_string((4, 4), f"Heard: {label}", color=(255, 0, 0), scale=2)
        else:
            label = None

    print(clock.fps(), "fps")

results matching ""

    No results matching ""