diff --git a/api-customer/src/controllers/analyze_controller.py b/api-customer/src/controllers/analyze_controller.py index 27206468..585afca0 100644 --- a/api-customer/src/controllers/analyze_controller.py +++ b/api-customer/src/controllers/analyze_controller.py @@ -1,3 +1,7 @@ +import base64 + +import cv2 +import numpy as np from flask import jsonify, request from src.services.detection_service import DetectionService @@ -18,8 +22,19 @@ class AnalyzeController: try : payload = request.get_json() print(payload) - fen = self._detection_service.analyze_single_frame(payload["image"]) + img = self._decode_image(payload["image"]) + fen = self._detection_service.analyze_single_frame(img) return jsonify({"success": False, "payload": {"fen" : fen}}), 200 except Exception as e: print(e) - return jsonify({"success": False, "message": "Failed to analyze image"}), 500 \ No newline at end of file + return jsonify({"success": False, "message": "Failed to analyze image"}), 500 + + def _decode_image(self, b64_img): + if b64_img.startswith("data:image"): + b64_img = b64_img.split(",")[1] + + img_bytes = base64.b64decode(b64_img) + + nparr = np.frombuffer(img_bytes, np.uint8) + + return cv2.imdecode(nparr, cv2.IMREAD_COLOR) \ No newline at end of file