diff --git a/app.py b/app.py index 5d86e65b45689ce7708eec4816b6257f26e17c92..bf9a6448cfcceeb50177be57070a272901d87679 100644 --- a/app.py +++ b/app.py @@ -43,6 +43,7 @@ class OCR: f.write(imgString) img = Image.open(path).convert("RGB") W,H = img.size + timeTake = time.time() _,result,angle= model.model(img,detectAngle=True,config=dict(MAX_HORIZONTAL_GAP=200, MIN_V_OVERLAPS=0.6, MIN_SIZE_SIM=0.6, @@ -56,12 +57,13 @@ class OCR: textmodel = 'opencv_dnn_detect' ), leftAdjust=True,rightAdjust=True,alph=0.1) - + + timeTake = time.time()-timeTake res = map(lambda x:{'w':x['w'],'h':x['h'],'cx':x['cx'],'cy':x['cy'],'degree':x['degree'],'text':x['text']}, result) res = list(res) os.remove(path) - return json.dumps(res,ensure_ascii=False) + return json.dumps({'res':res,'timeTake':round(timeTake,4)},ensure_ascii=False) diff --git a/static/js/helps.js b/static/js/helps.js index f2c7e83e1a2f3d0f1b06831bdc588a7085ec993a..1eab5f97f712fff7ba8ba574e9f756159ed4d250 100644 --- a/static/js/helps.js +++ b/static/js/helps.js @@ -12,7 +12,9 @@ function postImg(){           success:function(d){ loadingGif('loadingGif'); imgJson['num']=0;//防止重复提交 - imgJson["result"] = JSON.parse(d); + res = JSON.parse(d); + imgJson["result"] = res['res']; + imgJson["timeTake"] = res['timeTake']; getChildDetail(); W = imgJson["width"]; H = imgJson["height"]; @@ -75,7 +77,7 @@ function FunimgPreview(avatarSlect,avatarPreview,myCanvas) { function getChildDetail(){ jQuery("#billmodeltable").remove(); childResult = imgJson["result"]; - createTable(childResult);//新建table + createTable(childResult,imgJson['timeTake']);//新建table } @@ -83,19 +85,19 @@ function getChildDetail(){ //根据获取的数据,创建table //创建table -function createTable(result){ +function createTable(result,timeTake){ //根据获取的数据,创建table jQuery("#mytable").empty(); var jsObject = result; //var jsObject = [{"name":10,"value":20},{"name":10,"value":20}]; - var p = "

识别结果为:

" - var tableString = "" + var p = "

耗时:"+timeTake+"秒 ,识别结果为:

"; + var tableString =p+ "
序号
" for(var i=0;i"; } tableString+="
序号

"+jsObject[i]["text"]+"

"; - jQuery("#mytable").append(p); + //jQuery("#mytable").append(p); jQuery("#mytable").append(tableString); } diff --git a/templates/ocr.html b/templates/ocr.html index 043039e28434aefcefd625553247e358bc714580..7a9060c4cff8343144143871b0e3867fde0ebdd2 100644 --- a/templates/ocr.html +++ b/templates/ocr.html @@ -40,9 +40,9 @@ table.gridtable td { imgJson = {"imgString":"", "num":0, "url":"", - "result":"" + "result":"", + "timeTake":0.0 }; -