From 0c8b6add64edcda69fee7fa1e69ede2546139c7a Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Tue, 29 Jul 2025 10:34:55 +0800 Subject: [PATCH] =?UTF-8?q?1.kangda=E7=B1=BB=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E8=A3=81=E5=89=AA\n2.ocr=E5=9B=BE=E5=83=8F=E5=89=8D?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E5=83=8F=E8=A3=81=E5=89=AA=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/event_sync_service.py | 4 ++++ app/util/kangda.py | 21 ++++++++++++++++++++- test_t.py | 12 +++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/services/event_sync_service.py b/app/services/event_sync_service.py index fe7484c..8025859 100644 --- a/app/services/event_sync_service.py +++ b/app/services/event_sync_service.py @@ -281,6 +281,10 @@ class EventSyncService: return for image in image_list: + + # 裁剪图片, 去掉时间日期信息 + self.kangda.crop_timestamp_with_cv2(image.localPath, image.localPath, 0, 0, 106, 115) + result = self.ocr.image_inference(image.localPath) values, conf = self.ocr.parse_result(result) diff --git a/app/util/kangda.py b/app/util/kangda.py index 103ef59..e15d2d3 100644 --- a/app/util/kangda.py +++ b/app/util/kangda.py @@ -1,6 +1,7 @@ import re import os -from urllib import response +import cv2 +# from urllib import response import yaml import requests from app.util.status import TemperatureStatus @@ -438,6 +439,24 @@ class Kangda: return TemperatureStatus.ALDATE return TemperatureStatus.NORMAL + + + # 裁剪图片 + def crop_timestamp_with_cv2(self, input_path, output_path, x, y, w, h): + """ + 裁剪输入图片中从 (x, y) 开始,宽度为 w、高度为 h 之外的区域。 + 也就是保留从 (x+w, y+h) 到右下角的部分。 + """ + img = cv2.imread(input_path) + if img is None: + raise FileNotFoundError(f"无法打开 {input_path}") + height, width = img.shape[:2] + + # 定义裁剪 ROI 区域 + cropped = img[y+h:height, x+w:width] + + # 保存结果 + cv2.imwrite(output_path, cropped) diff --git a/test_t.py b/test_t.py index 9bec22c..79342be 100644 --- a/test_t.py +++ b/test_t.py @@ -32,11 +32,17 @@ kangda = Kangda() #---------------------------测试康达前端登录end-------------------------------------- #--------------------------测试康达后台获取机器人任务----------------------------------- -token = kangda._login_gettoken() -task_list = kangda._get_task(token, ["6865c4ce61ee45a69e79f62eee55b83c"]) -print(task_list) +# token = kangda._login_gettoken() +# task_list = kangda._get_task(token, ["6865c4ce61ee45a69e79f62eee55b83c"]) +# print(task_list) #--------------------------测试康达后台获取机器人任务end------------------------------------- +#------------------------测试图片裁剪-------------------------------------------------- +image_path = "/home/admin-root/haotian/康达瑞贝斯/康达后台项目/imagesDownload/ffb447d5f89ea303cfeb25370495ad26.jpeg" +ouput_path = "/home/admin-root/haotian/康达瑞贝斯/康达后台项目/imagesDownload/ffb447d5f89ea303cfeb25370495ad26.jpeg" +kangda.crop_timestamp_with_cv2(image_path, ouput_path, 0, 0, 106, 115) +#------------------------测试图片裁剪end---------------------------------------------- +