;============================================================ ; iron_mediapipe.hsp — MediaPipe パイプライン (hand / pose / face) ; ; hsptflite.dll (Tensorflow Lite C API + MediaPipe helpers) を ; 基盤に、MediaPipe の .tflite モデルから手/姿勢/顔を検出する ; ラッパモジュール。 ; ; v2 (2026-04-15): ; - palm_detector + hand_landmarker の 2 段パイプラインを ; C++ 側の mp_palm_detect / mp_hand_landmark に委譲 ; - HSP 側は単に結果を 16*N 配列に溜めて取り出すだけ ; - pose / face は API 形のみ (スタブ) ; ; 使い方: ; #include "iron_mediapipe.hsp" ; mp_hand_init "hand_detector.tflite", "hand_landmarks_detector.tflite" ; mp_hand_run rgb_buf, w, h ; nhand = stat ; repeat nhand ; mp_hand_bbox cnt, bx, by, bw, bh ; mp_hand_score cnt, sc ; repeat 21 ; mp_hand_landmark_pt cnt, cnt, lx, ly ; loop ; loop ; mp_hand_close ;============================================================ #ifndef __iron_mediapipe_hsp__ #define __iron_mediapipe_hsp__ #include "iron_tflite.hsp" #module iron_mediapipe #define MP_HAND_MAX 16 #define MP_HAND_NUM_KEY 21 ; -------------------------------------------------------- ; mp_hand_init "hand_detector.tflite", "hand_landmarks_detector.tflite" ; -------------------------------------------------------- #deffunc mp_hand_init str p1, str p2 iron_tflite_open p1 _mp_hand_h1 = stat if _mp_hand_h1 < 0 : return _mp_hand_h1 if p2 != "" { iron_tflite_open p2 _mp_hand_h2 = stat } else { _mp_hand_h2 = -1 } dim _mp_hand_boxes, MP_HAND_MAX * 5 ; x1, y1, x2, y2, score*1000 dim _mp_hand_lm, MP_HAND_MAX * MP_HAND_NUM_KEY * 2 dim _mp_hand_conf, MP_HAND_MAX _mp_hand_cnt = 0 return _mp_hand_h1 #deffunc mp_hand_close if _mp_hand_h1 >= 0 : iron_tflite_close _mp_hand_h1 : _mp_hand_h1 = -1 if _mp_hand_h2 >= 0 : iron_tflite_close _mp_hand_h2 : _mp_hand_h2 = -1 _mp_hand_cnt = 0 return ; -------------------------------------------------------- ; mp_hand_run rgb_buf, w, h → stat = 検出数 ; -------------------------------------------------------- #deffunc mp_hand_run var vrgb, int iw, int ih, \ local _cnt, local _i, local _pt, local _lm, local _conf, \ local _x1, local _y1, local _x2, local _y2 _mp_hand_cnt = 0 if _mp_hand_h1 < 0 : return 0 ; 1) palm 検出 mp_palm_detect _mp_hand_h1, vrgb, iw, ih, 500, _mp_hand_boxes, _cnt if _cnt <= 0 : return 0 if _cnt > MP_HAND_MAX : _cnt = MP_HAND_MAX _mp_hand_cnt = _cnt ; 2) 各 bbox について landmark if _mp_hand_h2 < 0 : return _mp_hand_cnt dim _lm, MP_HAND_NUM_KEY * 2 repeat _cnt _i = cnt _x1 = _mp_hand_boxes(_i * 5 + 0) _y1 = _mp_hand_boxes(_i * 5 + 1) _x2 = _mp_hand_boxes(_i * 5 + 2) _y2 = _mp_hand_boxes(_i * 5 + 3) mp_hand_landmark _mp_hand_h2, vrgb, iw, ih, _x1, _y1, _x2, _y2, _lm, _conf _mp_hand_conf(_i) = _conf repeat MP_HAND_NUM_KEY _pt = cnt _mp_hand_lm(_i * MP_HAND_NUM_KEY * 2 + _pt * 2 + 0) = _lm(_pt * 2 + 0) _mp_hand_lm(_i * MP_HAND_NUM_KEY * 2 + _pt * 2 + 1) = _lm(_pt * 2 + 1) loop loop return _mp_hand_cnt #deffunc mp_hand_count var vn vn = _mp_hand_cnt return ; bbox は [x, y, w, h] で返す (既存互換) #deffunc mp_hand_bbox int idx, var vx, var vy, var vw, var vh vx = 0 : vy = 0 : vw = 0 : vh = 0 if idx >= 0 : if idx < _mp_hand_cnt { vx = _mp_hand_boxes(idx * 5 + 0) vy = _mp_hand_boxes(idx * 5 + 1) vw = _mp_hand_boxes(idx * 5 + 2) - _mp_hand_boxes(idx * 5 + 0) vh = _mp_hand_boxes(idx * 5 + 3) - _mp_hand_boxes(idx * 5 + 1) } return ; bbox を x1,y1,x2,y2 で返す #deffunc mp_hand_bbox_xyxy int idx, var vx1, var vy1, var vx2, var vy2 vx1 = 0 : vy1 = 0 : vx2 = 0 : vy2 = 0 if idx >= 0 : if idx < _mp_hand_cnt { vx1 = _mp_hand_boxes(idx * 5 + 0) vy1 = _mp_hand_boxes(idx * 5 + 1) vx2 = _mp_hand_boxes(idx * 5 + 2) vy2 = _mp_hand_boxes(idx * 5 + 3) } return #deffunc mp_hand_score int idx, var vs vs = 0.0 if idx >= 0 : if idx < _mp_hand_cnt { vs = double(_mp_hand_boxes(idx * 5 + 4)) / 1000.0 } return ; 21 点 landmark の取得 ; mp_hand_landmark_pt hand_idx, pt_idx, var_x, var_y #deffunc mp_hand_landmark_pt int hidx, int pidx, var vx, var vy vx = 0 : vy = 0 if hidx >= 0 : if hidx < _mp_hand_cnt : if pidx >= 0 : if pidx < MP_HAND_NUM_KEY { vx = _mp_hand_lm(hidx * MP_HAND_NUM_KEY * 2 + pidx * 2 + 0) vy = _mp_hand_lm(hidx * MP_HAND_NUM_KEY * 2 + pidx * 2 + 1) } return #deffunc mp_hand_presence int hidx, var vc vc = 0.0 if hidx >= 0 : if hidx < _mp_hand_cnt { vc = double(_mp_hand_conf(hidx)) / 1000.0 } return ; -------------------------------------------------------- ; pose / face — v1 スタブ ; -------------------------------------------------------- #deffunc mp_pose_init str path return -100 #deffunc mp_pose_close return #deffunc mp_pose_run var vrgb, int iw, int ih return 0 #deffunc mp_face_init str path return -100 #deffunc mp_face_close return #deffunc mp_face_run var vrgb, int iw, int ih return 0 #global _mp_hand_h1@iron_mediapipe = -1 _mp_hand_h2@iron_mediapipe = -1 _mp_hand_cnt@iron_mediapipe = 0 #endif