forked from mdh30/OCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite.html
59 lines (44 loc) · 1.56 KB
/
website.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
<!DOCTYPE html>
<html>
<head>
<title>OCR Website</title>
<style type="text/css"></style>
</head>
<body>
<center>
<input id="inputFileToLoad" type="file" onchange="encodeImageFileAsURL();" />
<div id="imgTest"></div>
<h3>OCR Output</h3>
<p id="ocrOutput">OCR Result</p>
<h3>Spanish translate</h3>
<p id="translate">Spanish text</p>
</center>
<script type='text/javascript'>
function encodeImageFileAsURL() {
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0) {
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result; // <--- data: base64
var newImage = document.createElement('img');
newImage.src = srcData;
document.getElementById("imgTest").innerHTML = newImage.outerHTML;
console.log(srcData);
var request = new XMLHttpRequest();
request.open('GET', "http:localhost:5000/ocr?img="+srcData, true);
request.onload = function(){
var data = JSON.parse(this.response);
document.getElementById("ocrOutput").innerHTML = data.ocrText;
document.getElementById("translate").innerHTML = data.trans;
console.log(data.ocrText);
console.log(data.trans);
}
request.send();
}
fileReader.readAsDataURL(fileToLoad);
}
}
</script>
</body>
</html>