-
Notifications
You must be signed in to change notification settings - Fork 27
/
ocr_bankcard.html
103 lines (73 loc) · 2.3 KB
/
ocr_bankcard.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>银行卡识别</title>
<script type="text/javascript" src="facepp_sdk/jquery.min.js"></script>
<script type="text/javascript" src="facepp_sdk/exif.js"></script>
<script type="text/javascript" src="facepp_sdk/facepp_sdk.js"></script>
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script type="text/javascript" src="common.js"></script>
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<style>
#input{
opacity: 0;
}
#preview{
left: 10%;
max-width: 90%;
}
#text{
left: 10%;
top: 20px;
width: 90%;
}
</style>
<body>
<div class="container">
<div class="button" onclick=clickInput()>选择银行卡照片</div>
<input id="input" type="file" accept="image/*" name="xaunz" onchange="selectImage(this)"/>
<img id="preview" />
<div id="text"></div>
</div>
</body>
<script>
resetContainer();
//点击按钮
function clickInput(){
document.getElementById('input').click();
}
this.facepp = new FACEPP(APIKEY,APISERET,1);
</script>
<script>
// 选择照片
function selectImage(input){
let imageView = document.getElementById('preview');
const reader = new FileReader();
reader.readAsDataURL(input.files[0]);
reader.onload = function (e) {
//图片的base64数据
const base64Image = e.target.result;
imageView.src = base64Image;
/*
//base64方式上传图片
let dic = {'image_base64' : base64Image};
facepp.detectFace(dic,success,failed);
*/
// 以二进制的方式上传图片
// 将base64转为二进制
let imageData = facepp.dataURItoBlob(base64Image);
//上传图片,获取结果
let dataDic = {'image_file':imageData};
facepp.OCRBankCard(dataDic,handleResult,handleResult);
}
}
//失败的回调
function handleResult(e){
console.log(e);
let textView = document.getElementById('text');
textView.innerText = JSON.stringify(e,null,"\t");
}
</script>
</html>