forked from DanyalAhmad2003/HCI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.html
More file actions
114 lines (94 loc) · 2.91 KB
/
scanner.html
File metadata and controls
114 lines (94 loc) · 2.91 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
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>EcoBin – Scanner</title>
<link rel="stylesheet" href="css/styles.css" />
<style>
#video {
width: 100%;
max-width: 400px;
border-radius: 0.75rem;
box-shadow:
0 0 8px rgba(0, 0, 0, 0.6),
0 0 16px rgba(0, 0, 0, 0.4),
0 0 24px rgba(0, 0, 0, 0.2);
background: #000;
}
.scan-status {
margin-top: 0.5rem;
font-size: 0.9rem;
color: black;
}
#take-photo {
margin-top: 1rem;
width: 100%;
max-width: 400px;
}
#captureCanvas {
display: none;
}
</style>
</head>
<body>
<div class="glow-box">
<header><h1>EcoBin Scanner</h1></header>
</div>
<main style="text-align:center;">
<div class="highlight">
<video id="video" autoplay muted playsinline></video>
<p class="scan-status" id="status">Initializing camera…</p>
<button class="btn" id="take-photo">Take Picture</button>
</div>
</main>
<canvas id="captureCanvas"></canvas>
<a href="index.html" class="back-btn">← Back to Menu</a>
<script>
(async () => {
const statusEl = document.getElementById('status');
const video = document.getElementById('video');
const button = document.getElementById('take-photo');
const canvas = document.getElementById('captureCanvas');
const ctx = canvas.getContext('2d');
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'environment' }
});
video.srcObject = stream;
statusEl.textContent = 'Point camera & tap “Take Picture”';
} catch (err) {
statusEl.textContent = '❌ Camera access denied';
console.error(err);
return;
}
let detector = null;
if ('BarcodeDetector' in window) {
detector = new BarcodeDetector({
formats: ['ean_13','code_128','qr_code']
});
}
button.addEventListener('click', async () => {
statusEl.textContent = 'Processing…';
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageData = canvas.toDataURL('image/png');
sessionStorage.setItem('capturedImage', imageData);
if (detector) {
try {
const barcodes = await detector.detect(video);
if (barcodes.length) {
sessionStorage.setItem('scannedCode', barcodes[0].rawValue);
}
} catch (e) {
console.warn('Barcode scan failed:', e);
}
}
video.srcObject.getTracks().forEach(t => t.stop());
window.location = 'scanner-confirm.html';
});
})();
</script>
</body>
</html>