feat: trace-level matching, health watcher/worker status, timezone config
This commit is contained in:
@@ -5,12 +5,16 @@ Calls Swift Vision Framework pose (swift_pose) with fallback to YOLOv8 Pose.
|
||||
Uses VNDetectHumanBodyPoseRequest with ANE acceleration.
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from redis_publisher import RedisPublisher
|
||||
|
||||
SWIFT_POSE_PATH = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"swift_processors/.build/debug/swift_pose"
|
||||
@@ -21,11 +25,14 @@ SWIFT_POSE_ALT = os.path.join(
|
||||
)
|
||||
|
||||
|
||||
SWIFT_POSE_PROGRESS_RE = re.compile(r"\[SwiftPose\] Progress:\s*(\d+)%")
|
||||
|
||||
def process_pose(
|
||||
video_path: str,
|
||||
output_path: str,
|
||||
uuid: str = "",
|
||||
sample_interval: int = 30,
|
||||
publisher: RedisPublisher = None,
|
||||
) -> dict:
|
||||
swift_bin = SWIFT_POSE_PATH
|
||||
if not os.path.exists(swift_bin):
|
||||
@@ -33,6 +40,8 @@ def process_pose(
|
||||
|
||||
if not os.path.exists(swift_bin):
|
||||
print("[Pose] Swift binary not found, using YOLOv8 fallback", file=sys.stderr)
|
||||
if publisher:
|
||||
publisher.error("pose", "Swift binary not found, using fallback")
|
||||
return _fallback(video_path, output_path, uuid, sample_interval)
|
||||
|
||||
cmd = [swift_bin, video_path, output_path,
|
||||
@@ -40,17 +49,32 @@ def process_pose(
|
||||
"--uuid", uuid]
|
||||
|
||||
print(f"[Pose] Running Swift Pose (Vision Framework)", file=sys.stderr)
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=7200)
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
|
||||
if result.stdout:
|
||||
for line in result.stdout.strip().split("\n"):
|
||||
print(f" {line}", file=sys.stderr)
|
||||
if result.stderr:
|
||||
for line in result.stderr.strip().split("\n"):
|
||||
last_pct = -1
|
||||
for line in proc.stdout:
|
||||
line = line.strip()
|
||||
m = SWIFT_POSE_PROGRESS_RE.search(line)
|
||||
if m:
|
||||
pct = int(m.group(1))
|
||||
if pct > last_pct:
|
||||
last_pct = pct
|
||||
print(f"[Pose] Progress: {pct}%", file=sys.stderr)
|
||||
if publisher:
|
||||
publisher.progress("pose", pct, 100, f"{pct}%")
|
||||
elif line:
|
||||
print(f" {line}", file=sys.stderr)
|
||||
|
||||
if result.returncode != 0 or not os.path.exists(output_path):
|
||||
print(f"[Pose] Swift Pose failed, falling back to YOLOv8", file=sys.stderr)
|
||||
stderr_output = proc.stderr.read()
|
||||
if stderr_output:
|
||||
print(stderr_output.strip(), file=sys.stderr)
|
||||
|
||||
proc.wait()
|
||||
|
||||
if proc.returncode != 0 or not os.path.exists(output_path):
|
||||
print(f"[Pose] Swift Pose failed (exit={proc.returncode}), falling back to YOLOv8", file=sys.stderr)
|
||||
if publisher:
|
||||
publisher.error("pose", f"Swift Pose failed, using fallback")
|
||||
return _fallback(video_path, output_path, uuid, sample_interval)
|
||||
|
||||
with open(output_path) as f:
|
||||
@@ -113,7 +137,14 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--sample-interval", type=int, default=30)
|
||||
args = parser.parse_args()
|
||||
|
||||
result = process_pose(args.video_path, args.output_path, args.uuid, args.sample_interval)
|
||||
publisher = RedisPublisher(args.uuid) if args.uuid else None
|
||||
if publisher:
|
||||
publisher.info("pose", "POSE_START")
|
||||
|
||||
result = process_pose(args.video_path, args.output_path, args.uuid,
|
||||
args.sample_interval, publisher)
|
||||
with open(args.output_path, "w") as f:
|
||||
json.dump(result, f, indent=2)
|
||||
print(f"Pose: {len(result.get('frames', []))} frames with poses")
|
||||
if publisher:
|
||||
publisher.complete("pose", f"{len(result.get('frames',[]))} frames")
|
||||
|
||||
Reference in New Issue
Block a user