-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocr.html
355 lines (299 loc) · 9.76 KB
/
ocr.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
<script type="module">
import './node_modules/xy-ui/components/xy-button.js';
import './node_modules/xy-ui/components/xy-switch.js';
</script>
<!-- <script src="./js/index.js" type="text/javascript" defer="defer"></script>-->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- <link href="css/index.css" rel="stylesheet">-->
<style>
body {
background: url(img/rabbit.jpg);
background-repeat: no-repeat;
background-size: cover;
}
.container {
width: 90vw;
}
.header {
width: 100%;
height: 10%;
text-align: center;
margin-top: 40px;
}
#title {
margin-top: 30px;
font-size: x-large;
color: #ea9291;
font-weight: 30px;
}
.intro {
margin-bottom: 10px;
}
.left {
float: left;
width: 100px;
color: white;
text-align: center;
font-size: large;
}
.right {
float: right;
width: 100px;
color: white;
text-align: center;
font-size: large;
}
.pic {
margin-top: 40px;
}
.tag {
font-size: 16px;
line-height: 40px;
margin-left: 2vw;
}
.lalala {
width: 624px;
height: 351px;
border-style: solid;
border-color: black;
float: right;
}
.footer {
/*background: #f1f1f1;*/
margin-top: 5vh;
margin-bottom: 20vh;
}
/*.takephoto{
background-color: #df8e8f;
height: 30px;
length: 200px;
color: white;
font-size: large;
float: left;
}*/
.collect {
background-color: #df8e8f;
text-align: center;
color: white;
font-size: 15px;
float: right;
}
.xy-switch {
font-size: 20px;
}
.tools_tap {
/*margin: 15px;*/
/*padding: 15px;*/
height: 40px;
width: 100%;
float: none;
}
#fanzhuan {
float: right;
margin-right: 32px;
margin-left: 2px;
margin-top: 5px;
}
.fanzhuan_text {
float: right;
font-size: 16px;
margin-left: 5px;
margin-right: 5px;
padding-top: 4px;
line-height: 30px;
}
.back {
float: left;
font-size: 16px;
margin-left: 5px;
margin-right: 5px;
padding-top: 4px;
line-height: 30px;
vertical-align: center;
}
.output_canvas {
transform: rotateY(180deg);
-webkit-transform: rotateY(180deg); /* Safari and Chrome */
-moz-transform: rotateY(180deg); /* Firefox */
}
.photo_canvas {
transform: rotateY(180deg);
-webkit-transform: rotateY(180deg); /* Safari and Chrome */
-moz-transform: rotateY(180deg); /* Firefox */
}
.block {
margin-top: 20px;
font-size: xx-large;
color: #e79482;
font-weight: 30px;
}
</style>
</head>
<body>
<div class="container">
<header class="header">
<h1 id="title">ppReader</h1>
<div class="tools_tap">
<a href="javascript:history.go(-1);" style="display: block; /* 设置为块元素 */
text-align: center;
color: #95B8CE;
float: left;
margin: 4px">
<img src="img/back.png" width="20" , height="20"></a>
<p class="back">返回上一页</p>
<xy-switch checked id="fanzhuan"></xy-switch>
<p class="fanzhuan_text">镜子模式</p>
</div>
<div class="intro">
<div class="left">视频调试</div>
<div class="right">照片</div>
</div>
</header>
<div class="pic">
<content class="content">
<div>
<video class="input_video" style="display: none"></video>
<canvas class="output_canvas" width="624px" height="351px">
</canvas>
<div class="lalala">
<canvas class="photo_canvas" width="624px" height="351px">
</canvas>
</div>
</div>
</content>
</div>
<footer class="footer">
<div class="btns">
<xy-button class="takephoto" block onclick="sendImage()">点击开始识别文章</xy-button>
</div>
<div>
<div class="block">
<button class="collect">收藏</button>
<div class="tag" id="key">文章内容:</div>
</div>
</div>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script>
const videoElement = document.getElementsByClassName('input_video')[0];
const canvasElement = document.getElementsByClassName('output_canvas')[0];
const canvasCtx = canvasElement.getContext('2d');
const canvasElement_photo = document.getElementsByClassName('photo_canvas')[0];
const canvasCtx_photo = canvasElement_photo.getContext('2d');
const key = document.getElementById("key");
const en = document.getElementById("en");
const mean = document.getElementById("mean");
const fanzhuan_btn = document.getElementById("fanzhuan");
var fanzhuan_flag = 1;
fanzhuan_btn.onchange = function (ev) {
//获取checked的几种方式
/*
event:{
detail:{
checked,
}
}
*/
if (this.checked) {
fanzhuan_flag = 1;
canvasElement.style['transform'] = "rotateY(180deg)"
canvasElement.style['-webkit-transform'] = "rotateY(180deg)"
} else {
fanzhuan_flag = 0;
canvasElement.style['transform'] = "rotateY(0deg)"
canvasElement.style['-webkit-transform'] = "rotateY(0deg)"
}
console.log(this.checked);
// console.log(ev.target.checked);
// console.log(ev.detail.checked);
}
const xl = -1;
const yl = -1;
const xr = -1;
const yr = -1;
const mode = 2;
function sendImage() {
var imgData = canvasElement.toDataURL("image/jpeg", 1)
// document.write('<img src="'+imgData+'"/>');
canvasCtx_photo.save();
canvasCtx_photo.drawImage(
videoElement, 0, 0, canvasElement_photo.width, canvasElement_photo.height);
canvasCtx_photo.restore();
console.log(imgData, mode, xl, yl, xr, yr)
$.ajax({
type: "POST",
url: "https://ppreader.creativecc.cn/api/test",
// url: "http://192.168.0.105/api/test",
//url:"http://101.43.237.206:8080/api/test",
//url:"http://127.0.0.1:8000/api/test",
datatype: "json",
data: {
imgData: imgData,
mode: mode,
xl: xl,
yl: yl,
xr: xr,
yr: yr,
usrid: localStorage.string
},
//async: true,
//contentType:"application/json",
success: function (data) {
// alert(data);
console.log(data)
key.innerHTML = "文章内容: " + data['text_results'];
var to_speak = new SpeechSynthesisUtterance(data['text_results']);
window.speechSynthesis.speak(to_speak);
if (data['text_results'] == '无') {
key.innerHTML = "未识别到任何东西,请重新选择~";
}
},
error: function (data) {
alert("error!")
}
});
}
function onResults(results) {
canvasCtx.save();
canvasCtx.drawImage(
results.image, 0, 0, canvasElement.width, canvasElement.height);
canvasCtx.restore();
}
const hands = new Hands({
locateFile: (file) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
}
});
hands.setOptions({
maxNumHands: 2,
modelComplexity: 1,
minDetectionConfidence: 0.5,
minTrackingConfidence: 0.5
});
hands.onResults(onResults);
const camera = new Camera(videoElement, {
onFrame: async () => {
await hands.send({image: videoElement});
},
width: 1280,
height: 720
});
camera.start();
</script>
</body>
</html>