diff --git a/app/api/v1/endpoints/events.py b/app/api/v1/endpoints/events.py index 1951278..cb984d3 100644 --- a/app/api/v1/endpoints/events.py +++ b/app/api/v1/endpoints/events.py @@ -487,6 +487,15 @@ async def get_etype_name_list( ): etype_name_list = await event.get_etype_name_list(db) return BaseResponse(code=200, msg="success", data=etype_name_list) + +# 获取仪表识别结果 +@router.get("/events/getOcrResult") +async def get_ocr_result( + db: AsyncSession = Depends(get_db) +): + ocr_result = await event.get_ocr_result(db) + return BaseResponse(code=200, msg="success", data=ocr_result) + # 获取机器人任务列表 @router.get("/events/robotTask") async def get_robot_task( diff --git a/app/crud/event.py b/app/crud/event.py index 9d75793..9da476a 100644 --- a/app/crud/event.py +++ b/app/crud/event.py @@ -44,6 +44,31 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]): return result + async def get_ocr_result( + self, + db: AsyncSession, + ) -> List[BackStageEvent]: + """获取所有仪表识别结果""" + stmt = ( + select(Event.eventId, Event.number, Event.name, Image.imageUrl, Image.localPath, Temperature.temperature, Temperature.confidence, Temperature.createTime, Temperature.status) + .select_from(Temperature) + .outerjoin(Event, Event.eventId==Temperature.eventId) + .outerjoin(Image, Image.imageId == Temperature.imageId) + .order_by(Temperature.createTime.desc()) + ) + + results = await db.execute(stmt) + + results = results.mappings().all() + + back = list() + + for result in results: + back.append(BackStageEvent(**result)) + + return back + + async def get_multi_backstage_events( self, db: AsyncSession, @@ -70,14 +95,16 @@ class CRUDEvent(CRUDBase[Event, EventUpdate, EventUpdate]): - stmt = (select(Event.eventId, Event.number, Event.name, Image.imageUrl, Image.localPath, Temperature.temperature, Temperature.confidence, Temperature.createTime, Temperature.status) + stmt = ( + select(Event.eventId, Event.number, Event.name, Image.imageUrl, Image.localPath, Temperature.temperature, Temperature.confidence, Temperature.createTime, Temperature.status) .select_from(Temperature) .outerjoin(Event, Event.eventId==Temperature.eventId) .outerjoin(Image, Image.imageId == Temperature.imageId) .where(*conditions) .order_by(Temperature.createTime.desc()) .offset(query.skip) - .limit(query.limit)) + .limit(query.limit) + ) results = await db.execute(stmt) diff --git a/app/services/event_sync_service.py b/app/services/event_sync_service.py index 6c0fc92..57b2846 100644 --- a/app/services/event_sync_service.py +++ b/app/services/event_sync_service.py @@ -290,9 +290,9 @@ class EventSyncService: - if len(values) > 0 and len(values) < 3 and conf > 0.7: + if len(values) > 0 and len(values) < 3: - status = self.kangda.parse_value(values) + status = self.kangda.parse_value(values, conf) if status.value != 4: # 插入temperature表数据 @@ -344,6 +344,7 @@ async def run_sync_event(eventId: str): if __name__ == "__main__": + # asyncio.run(run_sync()) - asyncio.run(run_sync_event("477b88a72063465586957fe7126fbae5")) \ No newline at end of file + asyncio.run(run_sync_event("56163a3ce6e44230bd8f0110bcd33e6b")) \ No newline at end of file diff --git a/app/util/baiduOcr.py b/app/util/baiduOcr.py index 6f2f1b2..2e1488b 100644 --- a/app/util/baiduOcr.py +++ b/app/util/baiduOcr.py @@ -1,7 +1,8 @@ import yaml import os from PIL import Image -from paddleocr import PaddleOCR, draw_ocr +from paddleocr import PaddleOCR +# , draw_ocr class BadiduOcr(): @@ -41,7 +42,7 @@ class BadiduOcr(): scores = [line[1][1] for line in result] # 最好自己下个字体文件 - im_show = draw_ocr(image, boxes, txts, scores, font_path='/usr/share/fonts/truetype/teluguvijayam/PottiSreeramulu.ttf') + # im_show = draw_ocr(image, boxes, txts, scores, font_path='/usr/share/fonts/truetype/teluguvijayam/PottiSreeramulu.ttf') im_show = Image.fromarray(im_show) im_show.save(save_path) diff --git a/app/util/kangda.py b/app/util/kangda.py index 6f55e27..839dfb8 100644 --- a/app/util/kangda.py +++ b/app/util/kangda.py @@ -385,7 +385,7 @@ class Kangda: print("fail to download image ", url," ", e) return None - def parse_value(self, values): + def parse_value(self, values, conf): ''' 解析温度是否正常, ''' @@ -406,9 +406,11 @@ class Kangda: status = list() - for value in values: + for i, value in enumerate(values): # 字符串中含有AL以外的字母. - if bool(al_pattern_not.search(value)): + if(conf[i] < 0.8): + status.append(TemperatureStatus.CN) + elif bool(al_pattern_not.search(value)): status.append(TemperatureStatus.CN) elif bool(float_pattern.fullmatch(value)): status.append(TemperatureStatus.CN) diff --git a/run_sync.py b/run_sync.py index baedfac..0baddd0 100644 --- a/run_sync.py +++ b/run_sync.py @@ -7,5 +7,5 @@ from app.services.event_sync_service import run_sync, run_sync_event if __name__ == "__main__": print("启动事件同步服务...") - asyncio.run(run_sync()) - # asyncio.run(run_sync_event("ac0278e8384e4025b202871df9c1a1d8")) \ No newline at end of file + # asyncio.run(run_sync()) + asyncio.run(run_sync_event("56163a3ce6e44230bd8f0110bcd33e6b")) \ No newline at end of file diff --git a/测试Ocr.py b/测试Ocr.py index a2039fb..c6deb77 100644 --- a/测试Ocr.py +++ b/测试Ocr.py @@ -8,22 +8,27 @@ from app.util.kangda import Kangda baiduOcr = BadiduOcr() kangda = Kangda() -file_path = '/home/admin-root/haotian/康达瑞贝斯/康达后台项目/imagesOcr' +# file_path = '/home/admin-root/haotian/康达瑞贝斯/康达后台项目/imagesOcr' -image_path = [os.path.join(file_path, t) for t in os.listdir(file_path)] +# image_path = [os.path.join(file_path, t) for t in os.listdir(file_path)] -for image in image_path: - result = baiduOcr.image_inference(image) - value, conf = baiduOcr.parse_result(result) - print("-"*100) - print("image: ", image) - print("value:", value) - print("conf:", conf) - status = None - if len(value) > 0 and len(value) < 3: - status = kangda.parse_value(value) - print("status:", status, status.value if status else 0) - +# for image in image_path: +# result = baiduOcr.image_inference(image) +# value, conf = baiduOcr.parse_result(result) +# print("-"*100) +# print("image: ", image) +# print("value:", value) +# print("conf:", conf) +# status = None +# if len(value) > 0 and len(value) < 3: +# status = kangda.parse_value(value) +# print("status:", status, status.value if status else 0) + +# 测试单个图片 +result = baiduOcr.image_inference('4a70ea44c0f292284173055efab4d140.jpeg') +value, conf = baiduOcr.parse_result(result) +print("value:", value) +print("conf:", conf)