diff --git a/biz/base_frame_processor.py b/biz/base_frame_processor.py index 9cbfc8e..cf9335b 100644 --- a/biz/base_frame_processor.py +++ b/biz/base_frame_processor.py @@ -81,7 +81,16 @@ class BaseFrameProcessorWorker(threading.Thread): def _encode_image_to_base64(self, img) -> str: """图像编码为 Base64""" - ok, buf = cv2.imencode(".jpg", img) + # 检查并调整图片尺寸 + h, w = img.shape[:2] + if h > 720: + new_h = 720 + new_w = int(w * (720 / h)) + img = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_AREA) + + # 设置JPEG质量参数 + params = [int(cv2.IMWRITE_JPEG_QUALITY), 80] # 质量0.8 + ok, buf = cv2.imencode(".jpg", img, params) if not ok: raise RuntimeError("Failed to encode image to JPEG") return base64.b64encode(buf.tobytes()).decode("ascii")