-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
130 lines (120 loc) · 4.01 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QR Code and Text Scanner</title>
<link rel="stylesheet" href="styles.css" />
<link rel="icon" href="image.png" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css"
/>
</head>
<body>
<header>
<h1>
Smart Attendance
<i class="fa-solid fa-clipboard-user" style="font-size: 4.5vh"></i>
</h1>
</header>
<main>
<section class="attendance-container">
<h2 class="green-text">
Scan Your ID <i class="fa-solid fa-id-card"></i>
</h2>
<!-- QR Scanner container -->
<div id="qr-reader" class="qr-scanner"></div>
<br />
<p class="green-text" id="result">Waiting for ID scan...</p>
<button id="ocr-button" class="submit-btn">Scan Text</button>
<input
type="file"
id="image-input"
accept="image/*"
style="display: none"
/>
<p id="ocr-result" class="green-text"></p>
</section>
</main>
<footer>
<p>© Attendance System</p>
</footer>
<script src="https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js"></script>
<script src="https://cdn.rawgit.com/naptha/tesseract.js/0.2.0/tesseract.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const qrResult = document.getElementById("result");
const ocrResult = document.getElementById("ocr-result");
const imageInput = document.getElementById("image-input");
const ocrButton = document.getElementById("ocr-button");
if (typeof Html5Qrcode === "undefined") {
qrResult.innerHTML = "QR code scanner not initialized.";
return;
}
const html5QrCode = new Html5Qrcode("qr-reader");
const qrCodeSuccessCallback = (decodedText) => {
qrResult.innerHTML = `Scanned ID: ${decodedText}`;
html5QrCode
.stop()
.then(() => {
console.log("QR Code scanning stopped.");
})
.catch((err) => {
console.error("Error stopping QR scanner:", err);
});
};
const qrCodeErrorCallback = (errorMessage) => {
console.log(`QR Code scan error: ${errorMessage}`);
};
const config = {
fps: 10,
qrbox: { width: 250, height: 250 },
};
html5QrCode
.start(
{ facingMode: { exact: "environment" } },
config,
qrCodeSuccessCallback,
qrCodeErrorCallback
)
.catch(() => {
html5QrCode
.start(
{ facingMode: "user" },
config,
qrCodeSuccessCallback,
qrCodeErrorCallback
)
.catch((err) => {
qrResult.innerHTML = `Error starting QR scanner: ${err}`;
});
});
ocrButton.addEventListener("click", function () {
imageInput.click();
});
imageInput.addEventListener("change", function (event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
const img = new Image();
img.src = e.target.result;
img.onload = function () {
// Perform OCR using Tesseract.js
Tesseract.recognize(img.src, "eng")
.then(({ data: { text } }) => {
ocrResult.innerHTML = `Recognized Text: ${text}`;
})
.catch((err) => {
ocrResult.innerHTML = `OCR Error: ${err.message}`;
});
};
};
reader.readAsDataURL(file);
}
});
});
</script>
</body>
</html>