diff --git a/web/dashboard.py b/web/dashboard.py index 357e116..218b39e 100644 --- a/web/dashboard.py +++ b/web/dashboard.py @@ -1490,6 +1490,38 @@ def mark_training(): return {"ok": False, "error": str(e)}, 500 +@app.route("/api/feeder-image/capture", methods=["POST"]) +def capture_feeder_image(): + """Capture current camera frame and save as feeder reference photo.""" + import cv2 + + if _monitor is None or not _monitor.running: + return {"ok": False, "error": "Camera not running"}, 503 + + try: + frame = _monitor.camera.get_full_res_frame() + if frame is None: + frame = _monitor.camera.capture_lores_array() + + if frame.shape[0] > frame.shape[1] * 1.2: + frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420) + + destinations = [ + config.BASE_DIR / "web" / "static" / "feeder.jpg", + config.BASE_DIR / "website" / "img" / "feeder.jpg", + ] + for dest in destinations: + dest.parent.mkdir(parents=True, exist_ok=True) + cv2.imwrite(str(dest), frame, [cv2.IMWRITE_JPEG_QUALITY, 90]) + + logger.info("Feeder reference image updated") + return {"ok": True} + + except Exception as e: + logger.exception("Failed to capture feeder reference image") + return {"ok": False, "error": str(e)}, 500 + + _retrain_in_progress = False _retrain_lock = threading.Lock() diff --git a/web/templates/dashboard.html b/web/templates/dashboard.html index eea8e35..34f5c62 100644 --- a/web/templates/dashboard.html +++ b/web/templates/dashboard.html @@ -248,6 +248,7 @@

Live Camera Feed

+