;============================================================ ; sample_mediapipe_hand.hsp — MediaPipe Hand 検出サンプル ; ; hsptflite.dll (Tensorflow Lite C API + MediaPipe helpers) と ; iron_mediapipe.hsp を使って、画像から手のひらを検出し、 ; 21 点 landmark を重ねて描画するデモです。 ; ; 配置: ; mediapipe_models/hand_detector.tflite ; mediapipe_models/hand_landmarks_detector.tflite ; mediapipe_models/tensorflowlite_c.dll ; mediapipe_models/hand.jpg (任意の手の写真) ;============================================================ #include "hsp3_net_64.as" #include "iron_mediapipe.hsp" title "MediaPipe Hand Detection (IronHSP)" screen 0, 800, 600 ; --- 画像読み込み --- picload "mediapipe_models/hand.jpg" src_w = ginfo_winx src_h = ginfo_winy ; --- bmscr から 24bit DIB を取得 --- mref bm, 67 sdim bgr, src_w * src_h * 3 memcpy bgr, bm, src_w * src_h * 3, 0, 0 ; HSP の DIB は上下反転 & BGR。上下反転 + BGR→RGB を ; 一度に処理するため、まず y 方向に flip してから mp_bgr_to_rgb。 sdim bgr_flip, src_w * src_h * 3 repeat src_h memcpy bgr_flip, bgr, src_w * 3, cnt * src_w * 3, (src_h - 1 - cnt) * src_w * 3 loop sdim rgb, src_w * src_h * 3 mp_bgr_to_rgb bgr_flip, src_w, src_h, rgb ; --- MediaPipe Hand 初期化 --- mp_hand_init "mediapipe_models/hand_detector.tflite", "mediapipe_models/hand_landmarks_detector.tflite" if stat < 0 { color 255, 0, 0 pos 10, 10 mes "mp_hand_init failed: stat=" + stat mes "(SDK 未配置または tensorflowlite_c.dll が見つかりません)" stop } ; --- 検出実行 --- mp_hand_run rgb, src_w, src_h nhand = stat ; --- 結果の描画 --- repeat nhand i = cnt mp_hand_bbox_xyxy i, bx1, by1, bx2, by2 mp_hand_score i, sc mp_hand_presence i, pc color 0, 255, 0 boxf bx1, by1, bx2, by1 + 2 boxf bx1, by1, bx1 + 2, by2 boxf bx2 - 2, by1, bx2, by2 boxf bx1, by2 - 2, bx2, by2 pos bx1, by1 - 16 color 255, 255, 0 mes strf("hand[%d] score=%.2f pres=%.2f", i, sc, pc) ; 21 点 landmark color 255, 0, 255 repeat 21 mp_hand_landmark_pt i, cnt, lx, ly circle lx - 3, ly - 3, lx + 3, ly + 3, 1 loop loop color 255, 255, 255 pos 10, src_h + 4 mes "detected hands: " + nhand mp_hand_close stop