diff --git a/code/end.py b/code/end.py new file mode 100644 index 0000000..0ecce8d --- /dev/null +++ b/code/end.py @@ -0,0 +1,2 @@ +import subprocess +subprocess.Popen(["python", "main.py"]) \ No newline at end of file diff --git a/code/inference copy.py b/code/inference copy.py deleted file mode 100644 index a023709..0000000 --- a/code/inference copy.py +++ /dev/null @@ -1,133 +0,0 @@ -from ultralytics import YOLO -import numpy as np -import cv2 -from paddleocr import PaddleOCR -import re -import os -current_dir = os.path.dirname(os.path.abspath(__file__)) -img_path = os.path.join(current_dir, "test1.jpg") -img = cv2.imread(img_path) -model = YOLO(os.path.join(current_dir, "best.pt")) -results = model.predict(img_path, device='cpu') -ocr = PaddleOCR( - use_gpu=False, - use_angle_cls=True, - det_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_det_infer"), - rec_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_rec_infer"),) - -for r in results: - boxes = r.boxes - clses = np.array(boxes.cls).astype(int) - points = np.array(boxes.xyxy).astype(int) - target_0 = [] - target_1 = [] - target_2 = [] - target_3 = [] - for cls, point in zip(clses, points): - if cls == 0: - target_0.append(point) - elif cls == 1: - target_1.append(point) - elif cls == 2: - target_2.append(point) - elif cls == 3: - target_3.append(point) - -# 初始化结果字典 -results_summary = { - 'target_0': [], - 'target_1': [], - 'target_2': [], - 'target_3': [] -} - -# 检查类别数量 -if (len(target_0) == 2 and len(target_1) == 1 and (len(target_2) == 1 or len(target_2) == 2) and len(target_3) == 2): - - # 处理类别0 - target_0 = sorted(target_0, key=lambda x: x[0]) - left_point = target_0[0] - right_point = target_0[1] - for target, name in zip([left_point, right_point], ['地址', '姓名']): - target_img = img[target[1]:target[3], target[0]:target[2]] - cv2.imwrite(f'{name}.jpg', target_img) - result = ocr.ocr(target_img) - out = '' - if not result or not any(result): - out = '未识别到文字' - else: - for lines in result: - for line in lines: - out += line[1][0] - results_summary['target_0'].append(f"{name.capitalize()}: {out}") - - # # 处理类别1 - # for target in target_1: - # target_img = img[target[1]:target[3], target[0]:target[2]] - # cv2.imwrite(f'当前有功.jpg', target_img) - # result = ocr.ocr(target_img) - # out = '' - # for lines in result: - # for line in lines: - # out += line[1][0] - # out = out[:-2] + '.' + out[-2:] - # results_summary['target_1'].append(f"当前有功: {out}") - - # 处理类别1 - for target in target_1: - target_img = img[target[1]-5:target[3]+5, target[0]-5:target[2]+5] - cv2.imwrite(f'当前有功.jpg', target_img) - result = ocr.ocr(target_img, det=False) - for lines in result: - for line in lines: - out = line[0] - out = re.sub(r'\.', '', out) - out = out[:-2] + '.' + out[-2:] - results_summary['target_1'].append(f"当前有功: {out}") - - # 处理类别2 - if len(target_2) == 2: - target_2_sorted = sorted(target_2, key=lambda x: x[1]) - top_target = target_2_sorted[0] - target_img = img[top_target[1]:top_target[3], top_target[0]:top_target[2]] - elif len(target_2) == 1: - top_target = target_2[0] - target_img = img[top_target[1]:top_target[3], top_target[0]:top_target[2]] - cv2.imwrite(f'电表资产号.jpg', target_img) - result = ocr.ocr(target_img) - longest_line = "" - max_length = 0 - for lines in result: - for line in lines: - text = line[1][0] - if len(text) > max_length: - longest_line = text - max_length = len(text) - results_summary['target_2'].append(f"电表资产号: {longest_line}") - - # 处理类别3 - target_3 = sorted(target_3, key=lambda x: x[0]) - left_point = target_3[0] - right_point = target_3[1] - for target, name in zip([left_point, right_point], ['封印1', '封印2']): - target_img = img[target[1]:target[3], target[0]:target[2]] - height, width = target_img.shape[:2] - if width <= height: - target_img = cv2.transpose(target_img) - target_img = cv2.flip(target_img, flipCode=1) - cv2.imwrite(f'{name}.jpg', target_img) - result = ocr.ocr(target_img) - out = '' - for lines in result: - for line in lines: - out += line[1][0] - results_summary['target_3'].append(f"{name.capitalize()}: {out}") - - for category, result_list in results_summary.items(): - for result in result_list: - print(result) -else: - print("图像不清晰或要素不全请重新拍摄或人工记录") - - - diff --git a/code/main.py b/code/main.py index e04129b..934baaf 100644 --- a/code/main.py +++ b/code/main.py @@ -1,4 +1,4 @@ -from flask import Flask,request +from flask import Flask,request,jsonify,json from flask_cors import CORS from ultralytics import YOLO import base64 @@ -17,24 +17,24 @@ CORS(app) # 允许所有来源的请求 # CORS(app) # 加载模型 current_dir = os.path.dirname(os.path.abspath(__file__)) -model = YOLO(os.path.join(current_dir, "best.pt")) +model = YOLO(os.path.join(current_dir, "models/best.pt")) print("模型加载成功") -ocrSimple = PaddleOCR( +ocrSimple = [PaddleOCR( use_gpu=False, use_angle_cls=True, det_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_det_infer"), rec_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_rec_infer"), # det_model_dir=os.path.join(current_dir, "ocr/complex/ch_PP-OCRv4_det_server_infer"), # rec_model_dir=os.path.join(current_dir, "ocr/complex/ch_PP-OCRv4_rec_server_infer"), - ) -ocrComplex = PaddleOCR( + ) for _ in range(4)] +ocrComplex =[PaddleOCR( use_gpu=False, use_angle_cls=True, # det_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_det_infer"), # rec_model_dir=os.path.join(current_dir, "ocr/simple/ch_PP-OCRv4_rec_infer"), det_model_dir=os.path.join(current_dir, "ocr/complex/ch_PP-OCRv4_det_server_infer"), rec_model_dir=os.path.join(current_dir, "ocr/complex/ch_PP-OCRv4_rec_server_infer"), - ) + ) for _ in range(4)] # 开始识别 @app.route("/startOcr", methods=["post"]) def startOcr(): @@ -99,10 +99,10 @@ def startOcr(): target_0 = sorted(target_0, key=lambda x: x[0]) left_point = target_0[0] right_point = target_0[1] - for target, name in zip([left_point, right_point], ['地址', '姓名']): + for target, name in zip([left_point, right_point], ['address', 'name']): target_img = img[target[1]:target[3], target[0]:target[2]] # cv2.imwrite(f'{name}.jpg', target_img) - result = ocr.ocr(target_img) + result = ocr[0].ocr(target_img) out = '' if not result or not any(result): out = '未识别到文字' @@ -111,30 +111,17 @@ def startOcr(): for line in lines: out += line[1][0] results_summary['target_0'].append(f"{name.capitalize()}: {out}") - - # # 处理类别1 - # for target in target_1: - # target_img = img[target[1]:target[3], target[0]:target[2]] - # cv2.imwrite(f'当前有功.jpg', target_img) - # result = ocr.ocr(target_img) - # out = '' - # for lines in result: - # for line in lines: - # out += line[1][0] - # out = out[:-2] + '.' + out[-2:] - # results_summary['target_1'].append(f"当前有功: {out}") - # 处理类别1 for target in target_1: target_img = img[target[1]-5:target[3]+5, target[0]-5:target[2]+5] # cv2.imwrite(f'当前有功.jpg', target_img) - result = ocr.ocr(target_img, det=False) + result = ocr[1].ocr(target_img, det=False) for lines in result: for line in lines: out = line[0] out = re.sub(r'\.', '', out) out = out[:-2] + '.' + out[-2:] - results_summary['target_1'].append(f"当前有功: {out}") + results_summary['target_1'].append(f"lastPower: {out}") # 处理类别2 if len(target_2) == 2: @@ -145,7 +132,7 @@ def startOcr(): top_target = target_2[0] target_img = img[top_target[1]:top_target[3], top_target[0]:top_target[2]] # cv2.imwrite(f'电表资产号.jpg', target_img) - result = ocr.ocr(target_img) + result = ocr[2].ocr(target_img) longest_line = "" max_length = 0 for lines in result: @@ -154,20 +141,20 @@ def startOcr(): if len(text) > max_length: longest_line = text max_length = len(text) - results_summary['target_2'].append(f"电表资产号: {longest_line}") + results_summary['target_2'].append(f"currentMeterId: {longest_line}") # 处理类别3 target_3 = sorted(target_3, key=lambda x: x[0]) left_point = target_3[0] right_point = target_3[1] - for target, name in zip([left_point, right_point], ['封印1', '封印2']): + for target, name in zip([left_point, right_point], ['qrcode1', 'qrcode2']): target_img = img[target[1]:target[3], target[0]:target[2]] height, width = target_img.shape[:2] if width <= height: target_img = cv2.transpose(target_img) target_img = cv2.flip(target_img, flipCode=1) # cv2.imwrite(f'{name}.jpg', target_img) - result = ocr.ocr(target_img) + result = ocr[3].ocr(target_img) out = '' for lines in result: for line in lines: @@ -177,16 +164,17 @@ def startOcr(): for result in result_list: resultList=result.split(":") resultAll[resultList[0]]=resultList[1] - # print(result) - returnObj["resultsObj"]=resultAll + cleaned_data = {k.strip(): v.strip() for k, v in resultAll.items()} + returnObj["resultsObj"]=cleaned_data returnObj["message"]="识别成功" + returnObj["hasError"]=False else: returnObj["resultsObj"]={} returnObj["message"]="图像不清晰或要素不全请重新拍摄或人工记录" + returnObj["hasError"]=True # endTime=time.time() # print("运行时间:",endTime-startTime) - print("运行时间:",returnObj) - return returnObj + return jsonify(returnObj), 200, {'Content-Type': 'application/json'} if __name__ == "__main__": - app.run(host="0.0.0.0", port=7003) + app.run(debug=False,host="0.0.0.0", port=7003) diff --git a/code/best.pt b/code/models/best.pt similarity index 100% rename from code/best.pt rename to code/models/best.pt diff --git a/code/ocrCurrent.jpg b/code/ocrCurrent.jpg index 284fe89..2574d34 100644 Binary files a/code/ocrCurrent.jpg and b/code/ocrCurrent.jpg differ diff --git a/code/start.bat b/code/start.bat new file mode 100644 index 0000000..fb64e94 --- /dev/null +++ b/code/start.bat @@ -0,0 +1,4 @@ +@echo off +cd E:\code\code +python main.py start +exit \ No newline at end of file diff --git a/code/start.vbs b/code/start.vbs new file mode 100644 index 0000000..1f94943 --- /dev/null +++ b/code/start.vbs @@ -0,0 +1,3 @@ +DIM objShell +set objShell = wscript.createObject("wscript.shell") +iReturn = objShell.Run("start.bat", 0, TRUE) diff --git a/front/src/main/index.js b/front/src/main/index.js index 955dcc4..17a9ebf 100644 --- a/front/src/main/index.js +++ b/front/src/main/index.js @@ -57,7 +57,7 @@ app.whenReady().then(() => { }) ipcMain.on('ocrIdentify', async (eve, params) => { let res = await axios.post(`http://127.0.0.1:7003/startOcr`, params) - mainWindow.webContents.send(`ocrResult`, res) + mainWindow.webContents.send(`ocrResult`, res.data) }) }) app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required'); diff --git a/front/src/renderer/src/assets/css/base.css b/front/src/renderer/src/assets/css/base.css index bd4dce1..bbea223 100644 --- a/front/src/renderer/src/assets/css/base.css +++ b/front/src/renderer/src/assets/css/base.css @@ -4,9 +4,9 @@ body { padding: 0; } -.el-table .cell { +/* .el-table .cell { padding: 0 !important; -} +} */ .el-table .blueRow { background-color: #a0cfff; diff --git a/front/src/renderer/src/assets/js/db.js b/front/src/renderer/src/assets/js/db.js new file mode 100644 index 0000000..1a2c65f --- /dev/null +++ b/front/src/renderer/src/assets/js/db.js @@ -0,0 +1,6 @@ +import Dexie from 'dexie'; + +export const myDatabase = new Dexie('myDatabase'); +myDatabase.version(1).stores({ + users: '++id, Name,Address, lastPower,currentMeterId,Qrcode1,qrcode1,create_at,update_at', // Primary key and indexed props +}); \ No newline at end of file diff --git a/front/src/renderer/src/assets/json/user.json b/front/src/renderer/src/assets/json/user.json index a925094..e3259fd 100644 --- a/front/src/renderer/src/assets/json/user.json +++ b/front/src/renderer/src/assets/json/user.json @@ -1,7 +1,14 @@ [ { "label": "姓名", - "prop": "name", + "prop": "Name", + "type": "text", + "tableShow": true, + "formShow": true + }, + { + "label": "地址", + "prop": "Address", "type": "text", "tableShow": true, "formShow": true @@ -22,14 +29,14 @@ }, { "label": "二维码1", - "prop": "qrcode1", + "prop": "Qrcode1", "type": "text", "tableShow": true, "formShow": true }, { "label": "二维码2", - "prop": "qrcode2", + "prop": "Qrcode2", "type": "text", "tableShow": true, "formShow": true diff --git a/front/src/renderer/src/components/formcomponent.vue b/front/src/renderer/src/components/formcomponent.vue index 9705095..348fbf7 100644 --- a/front/src/renderer/src/components/formcomponent.vue +++ b/front/src/renderer/src/components/formcomponent.vue @@ -1,6 +1,6 @@