Skip to content

Commit

Permalink
web页面显示OCR识别时间
Browse files Browse the repository at this point in the history
wenlihaoyu committed Aug 24, 2018
1 parent d0c41f6 commit c0eef57
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ def POST(self):
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 @@ def POST(self):
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)



14 changes: 8 additions & 6 deletions static/js/helps.js
Original file line number Diff line number Diff line change
@@ -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,27 +77,27 @@ function FunimgPreview(avatarSlect,avatarPreview,myCanvas) {
function getChildDetail(){
jQuery("#billmodeltable").remove();
childResult = imgJson["result"];
createTable(childResult);//新建table
createTable(childResult,imgJson['timeTake']);//新建table
}




//根据获取的数据,创建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 = "<h2>识别结果为:</h2>"
var tableString = "<table id='billmodeltable' class='gridtable'><tr><th>序号</th><th>值</th></tr>"
var p = "<h3>耗时:"+timeTake+"秒 ,识别结果为:</h3>";
var tableString =p+ "<table id='billmodeltable' class='gridtable'><tr><th>序号</th><th>值</th></tr>"

for(var i=0;i<jsObject.length;i++){
tableString+="<tr><td><p>"+i+"</p></td><td><p contenteditable='true'>"+jsObject[i]["text"]+"</p></td></tr>";
}
tableString+="</table>";
jQuery("#mytable").append(p);
//jQuery("#mytable").append(p);
jQuery("#mytable").append(tableString);

}
4 changes: 2 additions & 2 deletions templates/ocr.html
Original file line number Diff line number Diff line change
@@ -40,9 +40,9 @@
imgJson = {"imgString":"",
"num":0,
"url":"",
"result":""
"result":"",
"timeTake":0.0
};

</script>


0 comments on commit c0eef57

Please sign in to comment.