-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
43 lines (37 loc) · 1.3 KB
/
main.js
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
async function onGetTextFromImage() {
const files = document.getElementById("uploader").files;
console.log(files)
const ocrImg = new Image();
ocrImg.id = "ocr-img";
const reader = new FileReader();
reader.addEventListener(
"load",
async () => {
// convert image file to base64 string
ocrImg.src = reader.result;
const { data: { text } } = await Tesseract.recognize(reader.result)
console.log(text);
resultDiv = document.createElement("div")
resultDiv.innerText = text
document.getElementById("ocr-text").appendChild(resultDiv)
},
false
);
reader.readAsDataURL(files[0])
const imgContainer = document.getElementById("img-container")
imgContainer.children = []
// if (imgContainer.firstChild)
// imgContainer.replaceChild(imgContainer.firstChild, ocrImg)
// else
imgContainer.appendChild(ocrImg);
// const { data: { text } } = await Tesseract.recognize(files[0])
// console.log(text);
// document.getElementById("ocr-text").innerText = text;
}
// async function onLoadImage(event) {
// const url = document.getElementById("img-url").value;
// const ocrImg = new Image();
// ocrImg.src = url;
// ocrImg.id = "ocr-img";
// document.getElementById("img-container").appendChild(ocrImg);
// }