From 03caa122ec394d503f426db93e327609d150b302 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Tue, 10 Mar 2026 10:40:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=9B=BE=E7=89=87=E7=AD=89?= =?UTF-8?q?=E6=AF=94=E7=BC=A9=E5=B0=8F=EF=BC=8Cjpg=E8=B4=A8=E9=87=8F?= =?UTF-8?q?=E5=87=8F=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/base_frame_processor.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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")