Ports blazepose_ref.py to a reusable C++ PoseEstimator: hand-written bilinear affine ROI warp (no OpenCV dep), ORT landmark inference, landmark/mask decode + inverse-affine to image space, and next-frame ROI from the aux landmarks for tracking. Validated headless vs the numpy reference (pose_probe vs dump_ref): presence matches to 1e-6, visible torso landmarks within ~1-2px, mask logit within 0.03; only low-confidence off-frame hand/aux landmarks differ.
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import struct
|
|
import numpy as np
|
|
import cv2
|
|
import scripts.blazepose_ref as bp
|
|
|
|
img = cv2.imread("testdata/pose_sample.jpg")
|
|
rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
H, W = img.shape[:2]
|
|
|
|
det = bp.load("pose_detector")
|
|
lmk = bp.load("pose_landmarks_detector")
|
|
d = bp.detect(det, rgb)
|
|
cx, cy, size, angle = bp.roi_from_detection(d, W, H)
|
|
crop, Minv = bp.crop_roi(rgb, cx, cy, size, angle)
|
|
pts, vis, presence, mask, _ = bp.landmarks(lmk, crop, Minv)
|
|
|
|
with open("testdata/sample_rgb.bin", "wb") as f:
|
|
f.write(struct.pack("<ii", W, H))
|
|
f.write(np.ascontiguousarray(rgb, dtype=np.uint8).tobytes())
|
|
|
|
with open("testdata/roi.txt", "w") as f:
|
|
f.write(f"{cx} {cy} {size} {angle}\n")
|
|
|
|
with open("testdata/ref.txt", "w") as f:
|
|
f.write(f"presence {presence}\n")
|
|
f.write(f"mask_prob_sum {float((mask).sum())}\n")
|
|
f.write(f"mask_at_128_128 {float(mask[128,128])}\n")
|
|
for i in range(39):
|
|
f.write(f"lm {i} {pts[i,0]} {pts[i,1]} {vis[i]}\n")
|
|
|
|
print(f"dumped W={W} H={H} roi=({cx:.1f},{cy:.1f},{size:.1f},{np.degrees(angle):.2f}deg) presence={presence:.3f}")
|