📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
更新web界面显示逻辑
SWHL17f65275e33c
diff --git a/ocrweb/main.py b/ocrweb/main.pyindex c6d8773..dc30ba6 100644--- a/ocrweb/main.py+++ b/ocrweb/main.py@@ -45,20 +45,28 @@ def ocr():t1 = time.time()dt_boxes, rec_res, img = text_sys(image)t2 = time.time()-- temp_rec_res = []- for i, value in enumerate(rec_res):- temp_rec_res.append([i, value[0], value[1]])- temp_rec_res = np.array(temp_rec_res)- rec_res_data = json.dumps(temp_rec_res.tolist(),- indent=2,- ensure_ascii=False)-- det_im = draw_text_det_res(dt_boxes, img)- image = cv2.imencode('.jpg', det_im)[1]- img = str(base64.b64encode(image))[2:-1]-- elapse = f'{t2-t1:.3f}'+ if dt_boxes is None or rec_res is None:+ temp_rec_res = []+ rec_res_data = json.dumps(temp_rec_res,+ indent=2,+ ensure_ascii=False)+ elapse = 0+ image = cv2.imencode('.jpg', img)[1]+ img = str(base64.b64encode(image))[2:-1]+ else:+ temp_rec_res = []+ for i, value in enumerate(rec_res):+ temp_rec_res.append([i, value[0], value[1]])+ temp_rec_res = np.array(temp_rec_res)+ rec_res_data = json.dumps(temp_rec_res.tolist(),+ indent=2,+ ensure_ascii=False)++ det_im = draw_text_det_res(dt_boxes, img)+ image = cv2.imencode('.jpg', det_im)[1]+ img = str(base64.b64encode(image))[2:-1]++ elapse = f'{t2-t1:.3f}'return json.dumps({'image': img,'elapse': elapse,'rec_res': rec_res_data})diff --git a/ocrweb/resources/bpocr.py b/ocrweb/resources/bpocr.pyindex fba270b..2b4ef83 100644--- a/ocrweb/resources/bpocr.py+++ b/ocrweb/resources/bpocr.py@@ -120,8 +120,8 @@ class TextSystem(object):dt_boxes, elapse = self.text_detector(img)print("dt_boxes num : {}, elapse : {}".format(len(dt_boxes), elapse))- if dt_boxes is None:- return None, None+ if dt_boxes is None or dt_boxes.size == 0:+ return None, None, imgimg_crop_list = []dt_boxes = self.sorted_boxes(dt_boxes)diff --git a/ocrweb/templates/index.html b/ocrweb/templates/index.htmlindex 4b1ed07..4d1f3f6 100644--- a/ocrweb/templates/index.html+++ b/ocrweb/templates/index.html@@ -37,6 +37,7 @@float: left;width: 50%;height: auto;+ position: relative;}.rightarea{@@ -70,13 +71,15 @@color:#000;font-style: italic;}- a{text-decoration:none}+ a{+ text-decoration:none;+ }/* wrapper */.leftarea>#wrapper {- position: absolute; top: 0px; left:0px;- width: 95%;- height: 95%;+ position: absolute; top: 36px; left:0px;+ width: 98%;+ height: 100%;background:linear-gradient(#1a98ca, #1a98ca),linear-gradient(90deg, #ffffff33 1px,transparent 0,transparent 19px),@@ -109,21 +112,19 @@<span class="uplodNote">图片文件类型支持PNG、JPG、JPEG、BMP,图片大小不超过10M。</span><span class="btn-gen" onclick="javascript:$('#rapid_ocr').click();">试试你的图片?</span><input type="file" style="display: none;" name="pic" id="rapid_ocr"/>- <span id="loading"></span></div><br/><div class="area"><div class="leftarea" id="detectDiv"><span class="span_title">文本检测结果:</span><br/><br/>- <div class="wrapper" id="wrapper" hidden>- </div>+ <div class="wrapper" id="wrapper" hidden></div><img id="detect_img" src=""/></div><div class="rightarea" id="recogDiv">- <span id="rec_res" class="span_title">文本识别结果:</span>- <br/> <br/>- <table id="locTable" border="1" class="table" cellspacing="0" cellpadding="5"></table>+ <span id="rec_res" class="span_title">文本识别结果:</span>+ <br/> <br/>+ <table id="locTable" border="1" class="table" cellspacing="0" cellpadding="5"></table></div></div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>@@ -156,7 +157,7 @@var reader = new FileReader();reader.onload = function(e){- var upload_data = {"file": reader.result,};+ var upload_data = {"file": reader.result};$.ajax({url:"/ocr",@@ -168,7 +169,7 @@beforeSend:function(){$("#detect_img").attr('src', reader.result);$('#detect_img').attr("width", "95%");- $('#detect_img').attr("height", "95%");+ $('#detect_img').attr("height", "100%");$('#wrapper').show();},