-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraCamera.html
More file actions
70 lines (60 loc) · 1.89 KB
/
CameraCamera.html
File metadata and controls
70 lines (60 loc) · 1.89 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css" media="all">
pre {
white-space: pre-wrap;
}
video {
/* transform: scaleX(-1); */
}
</style>
<title></title>
</head>
<body>
<video
id="video"
src=""
height="500"
width="360"
preload="none"
autoplay="autoplay"
muted
></video>
<pre id="pre"></pre>
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
<script type="text/javascript" charset="utf-8">
const preTag = document.getElementById("pre");
const video = document.getElementById("video");
const body = document.querySelector("body");
async function setVideo() {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'environment' }
});
video.srcObject = stream;
}
async function setUp() {
const worker = await Tesseract.createWorker("eng");
const canvas = document.createElement("canvas");
canvas.width = video.width;
canvas.height = video.height;
canvas
.getContext("2d")
.drawImage(video, 0, 0, video.width, video.height);
body.append(canvas);
if(canvasLoaded(canvas)) {
const ret = await worker.recognize(canvas, 'eng');
preTag.textContent = ret.data.text;
}
await worker.terminate();
}
// Ensure the video is loaded before calling setUp
setVideo();
video.addEventListener('loadeddata', async () => {
await setUp();
});
</script>
</body>
</html>