-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
101 lines (65 loc) · 2.38 KB
/
main.js
File metadata and controls
101 lines (65 loc) · 2.38 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
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
class Main {
constructor() {
this.worker = new Tesseract.TesseractWorker();
this.image = new Image();
this.image.src = "./alt_text_example.jpg";
this.image.onload = () => {
console.log(this.image);
this.canvas = document.createElement("canvas");
document.body.appendChild(this.canvas);
this.videoElement = document.querySelector('video');
this.canvas.width = this.image.width;
this.canvas.height = this.image.height;
this.ctx = this.canvas.getContext("2d");
this.ctx.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height);
navigator.mediaDevices.getUserMedia({ video: true })
.then(this.handleCameraFeed)
// this.convertToImage();
}
// this.convertToImage();
console.log("here")
}
handleCameraFeed = (stream) => {
this.videoElement.srcObject = stream;
this.videoElement.onplay = () => {
this.canvas.height = (this.videoElement.videoHeight)
this.canvas.width = (this.videoElement.videoWidth)
this.videoElement.style.display = "none";
requestAnimationFrame(this.render.bind(this));
}
}
convertToImage() {
let imageData = this.canvas.toDataURL();
// let imageO = new Image();
// imageO.src = imageData;
// imageO.onload = ()=> {
// document.body.append(imageO)
// }
this.worker.recognize(imageData, "eng")
.progress((packet) => {
this.started = true;
// document.querySelector(".label").innerHTML = packet.status
console.log(packet)
})
.then(data => {
this.started = false;
document.querySelector(".label").innerHTML = data.text
console.log(data)
})
}
lasTick = Date.now();
started = false;
render(ts) {
if (!this.started) {
this.started = true;
console.log("do");
this.convertToImage();
this.lasTick = Date.now();
}
this.ctx.drawImage(this.videoElement, 0, 0, this.canvas.width, this.canvas.height);
requestAnimationFrame(this.render.bind(this));
}
}
window.onload = () => {
window.app = new Main();
}