decode image

This commit is contained in:
2026-01-05 21:00:34 +01:00
parent 687b782a8f
commit 76b8c76af6

View File

@@ -1,3 +1,7 @@
import base64
import cv2
import numpy as np
from flask import jsonify, request from flask import jsonify, request
from src.services.detection_service import DetectionService from src.services.detection_service import DetectionService
@@ -18,8 +22,19 @@ class AnalyzeController:
try : try :
payload = request.get_json() payload = request.get_json()
print(payload) 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 return jsonify({"success": False, "payload": {"fen" : fen}}), 200
except Exception as e: except Exception as e:
print(e) print(e)
return jsonify({"success": False, "message": "Failed to analyze image"}), 500 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)