添加获取仪表识别告警列表
This commit is contained in:
parent
6fd4139c0a
commit
fa97923aae
@ -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(
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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"))
|
||||
asyncio.run(run_sync_event("56163a3ce6e44230bd8f0110bcd33e6b"))
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"))
|
||||
# asyncio.run(run_sync())
|
||||
asyncio.run(run_sync_event("56163a3ce6e44230bd8f0110bcd33e6b"))
|
||||
33
测试Ocr.py
33
测试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)
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user