姿勢推定と頭部検知を合成する手段を追加
This commit is contained in:
@@ -141,6 +141,90 @@ class AsyncMaskGenerator:
|
||||
self.worker_thread.start()
|
||||
bpy.app.timers.register(self._check_progress, first_interval=0.1)
|
||||
|
||||
def start_augment_pose(
|
||||
self,
|
||||
detections_path: str,
|
||||
total_frames: int,
|
||||
conf_threshold: float = 0.5,
|
||||
iou_threshold: float = 0.45,
|
||||
on_complete=None,
|
||||
on_progress=None,
|
||||
):
|
||||
"""既存キャッシュへの pose 補完を非同期で開始する。"""
|
||||
global bpy
|
||||
import bpy as _bpy
|
||||
bpy = _bpy
|
||||
|
||||
if self.is_running:
|
||||
raise RuntimeError("Mask generation already in progress")
|
||||
|
||||
self.is_running = True
|
||||
self.total_frames = total_frames
|
||||
self.current_frame = 0
|
||||
self._on_complete = on_complete
|
||||
self._on_progress = on_progress
|
||||
|
||||
self.worker_thread = threading.Thread(
|
||||
target=self._worker_augment_pose,
|
||||
args=(detections_path, conf_threshold, iou_threshold),
|
||||
daemon=True,
|
||||
)
|
||||
self.worker_thread.start()
|
||||
bpy.app.timers.register(self._check_progress, first_interval=0.1)
|
||||
|
||||
def _worker_augment_pose(
|
||||
self,
|
||||
detections_path: str,
|
||||
conf_threshold: float,
|
||||
iou_threshold: float,
|
||||
):
|
||||
"""client.augment_pose() を呼んで task_id でポーリング。"""
|
||||
import time
|
||||
from .inference_client import get_client
|
||||
|
||||
try:
|
||||
client = get_client()
|
||||
task_id = client.augment_pose(
|
||||
detections_path=detections_path,
|
||||
conf_threshold=conf_threshold,
|
||||
iou_threshold=iou_threshold,
|
||||
)
|
||||
|
||||
while self.is_running:
|
||||
status = client.get_task_status(task_id)
|
||||
state = status.get("status")
|
||||
|
||||
total = status.get("total", 0)
|
||||
if total > 0:
|
||||
self.total_frames = total
|
||||
|
||||
if state == "completed":
|
||||
progress = status.get("progress", self.total_frames)
|
||||
if progress >= 0:
|
||||
self.progress_queue.put(("progress", progress))
|
||||
result_path = status.get("result_path", detections_path)
|
||||
self.result_queue.put(("done", result_path))
|
||||
return
|
||||
elif state == "failed":
|
||||
self.result_queue.put(("error", status.get("message", "Unknown error")))
|
||||
return
|
||||
elif state == "cancelled":
|
||||
self.result_queue.put(("cancelled", None))
|
||||
return
|
||||
|
||||
progress = status.get("progress", 0)
|
||||
if progress >= 0:
|
||||
self.progress_queue.put(("progress", progress))
|
||||
time.sleep(0.5)
|
||||
|
||||
client.cancel_task(task_id)
|
||||
self.result_queue.put(("cancelled", None))
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"[FaceMask] Error: {e}")
|
||||
traceback.print_exc()
|
||||
self.result_queue.put(("error", str(e)))
|
||||
|
||||
def cancel(self):
|
||||
"""Cancel the current processing."""
|
||||
self.is_running = False
|
||||
|
||||
@@ -237,6 +237,36 @@ class InferenceClient:
|
||||
except urllib.error.HTTPError as e:
|
||||
raise RuntimeError(f"Server error: {e.read().decode('utf-8')}")
|
||||
|
||||
def augment_pose(
|
||||
self,
|
||||
detections_path: str,
|
||||
conf_threshold: float,
|
||||
iou_threshold: float,
|
||||
) -> str:
|
||||
"""既存キャッシュに pose 推定結果を追加合成する。task_id を返す。"""
|
||||
if not self.is_server_running():
|
||||
self.start_server()
|
||||
|
||||
data = {
|
||||
"detections_path": detections_path,
|
||||
"conf_threshold": conf_threshold,
|
||||
"iou_threshold": iou_threshold,
|
||||
}
|
||||
|
||||
req = urllib.request.Request(
|
||||
f"{self.SERVER_URL}/augment_pose",
|
||||
data=json.dumps(data).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req) as response:
|
||||
result = json.loads(response.read().decode("utf-8"))
|
||||
return result["id"]
|
||||
except urllib.error.HTTPError as e:
|
||||
raise RuntimeError(f"Server error: {e.read().decode('utf-8')}")
|
||||
|
||||
def get_task_status(self, task_id: str) -> Dict[str, Any]:
|
||||
"""Get status of a task."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user