📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
修复路径问题,调大一些检测框
SWHL32a17de97fed
diff --git a/ocrweb/main.py b/ocrweb/main.pyindex 308f57c..90e19be 100644--- a/ocrweb/main.py+++ b/ocrweb/main.py@@ -12,9 +12,9 @@ from werkzeug.utils import secure_filenamefrom resources.bpocr import TextSystem, draw_text_det_res# 实例化模型-det_model_path = 'resources/models/ch_ppocr_mobile_v2_det_train.onnx'+det_model_path = 'resources/models/ch_ppocr_mobile_v2.0_det_infer.onnx'cls_model_path = 'resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx'-rec_model_path = 'resources/models/ch_ppocr_mobile_v2.0_rec_pre_infer.onnx'+rec_model_path = 'resources/models/ch_ppocr_mobile_v2.0_rec_infer.onnx'text_sys = TextSystem(det_model_path,rec_model_path,@@ -24,16 +24,25 @@ text_sys = TextSystem(det_model_path,# 设置允许的文件格式ALLOWED_EXTENSIONS = {'png', 'jpg', 'JPG', 'PNG', 'bmp', 'jpeg', 'gif', 'tif'}app = Flask(__name__)++# 设置上传文件大小+app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 # 10M+# 设置静态文件缓存过期时间# app.send_file_max_age_default = TimedeltaFormat(seconds=10)+def make_directory(directory_path):+ if not isinstance(directory_path, Path):+ directory_path = Path(directory_path)+ directory_path.mkdir(parents=True, exist_ok=True)+def allowed_file(filename):return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS[email protected]('/upload', methods=['POST', 'GET'])-def upload():[email protected]('/ocr', methods=['POST', 'GET'])+def ocr():if request.method == 'POST':f = request.files['file']@@ -46,8 +55,15 @@ def upload():img_name = f"{time_stamp}_{secure_filename(f.filename)}"root_path = Path(__file__).resolve().parent- static_path = root_path / 'static'- upload_path = str(static_path / 'images' / f'raw_{img_name}')+ static_directory = root_path / 'static'++ raw_directory = static_directory / 'images'+ make_directory(raw_directory)++ infer_directory = static_directory / 'inference_results'+ make_directory(infer_directory)++ upload_path = str(raw_directory / f'raw_{img_name}')f.save(upload_path)t1 = time.time()@@ -56,13 +72,13 @@ def upload():rec_res = list(zip(range(len(rec_res)), rec_res))- plot_im = draw_text_det_res(dt_boxes, img)- plot_path = f'inference_results/det_{img_name}'+ det_im = draw_text_det_res(dt_boxes, img)+ det_path = f'inference_results/det_{img_name}'- cv2.imwrite(str(static_path / plot_path), plot_im)+ cv2.imwrite(str(static_directory / det_path), det_im)return render_template('index_ok.html',- det_img_path=plot_path,+ det_img_path=det_path,rec_res=rec_res,time=str(f'{t2-t1:.3f}'),width='100%',@@ -72,4 +88,4 @@ def upload():if __name__ == '__main__':- app.run(host='0.0.0.0', port=9003, debug=True)+ app.run(host='0.0.0.0', port=9003, debug=False, processes=True)diff --git a/ocrweb/readme.md b/ocrweb/readme.mdindex 446baab..541d1f0 100755--- a/ocrweb/readme.md+++ b/ocrweb/readme.md@@ -1 +1,3 @@-The whole project for web based OCR application.+#### The whole project for web based OCR application.++#### TODOdiff --git a/ocrweb/resources/bpocr.py b/ocrweb/resources/bpocr.pyindex 1a86a24..489bb51 100644--- a/ocrweb/resources/bpocr.py+++ b/ocrweb/resources/bpocr.py@@ -33,7 +33,7 @@ def draw_text_det_res(dt_boxes, raw_im):box = np.array(box).astype(np.int32).reshape(-1, 2)cv2.polylines(src_im, [box], True,color=(0, 0, 255),- thickness=2)+ thickness=1)cv2.putText(src_im, str(i), (int(box[0][0]), int(box[0][1])),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 2)return src_imdiff --git a/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py b/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.pyindex 0bf6163..78abb82 100644--- a/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py+++ b/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py@@ -54,7 +54,7 @@ class TextDetector(object):self.postprocess_op = DBPostProcess(thresh=0.3,box_thresh=0.5,max_candidates=1000,- unclip_ratio=1.6,+ unclip_ratio=2.0,use_dilation=True)self.session = onnxruntime.InferenceSession(det_model_path)self.input_name = self.session.get_inputs()[0].namediff --git a/ocrweb/templates/index_ok.html b/ocrweb/templates/index_ok.htmlindex f940544..e4a017c 100644--- a/ocrweb/templates/index_ok.html+++ b/ocrweb/templates/index_ok.html@@ -6,8 +6,8 @@</head><style type="text/css">body{- background-color:#ebedef;-}+ background-color:#ebedef;+ }.area{text-align: center;height: auto;@@ -27,16 +27,9 @@.table{margin: 0 auto;+ border: 0;/* border-spacing: 0px 15px; */}- tr td{- border:1px solid black;- border-bottom-width: thin;- border-right-style: thin;- border-left-style: thin;- border-top-style: thin;- }-.btn {margin-top: 4px;line-height: 32px;@@ -90,7 +83,7 @@<div class="rightarea"><span class="span_title">文本识别结果(耗时:{{time}}s):</span><br/> <br/>- <table class='table' cellpadding="0" cellspacing="0">+ <table class="table" cellpadding="0" cellspacing="0"><tr><td><strong>序号</strong></td><td><strong>识别结果</strong></td>