Camera-based barcode scanner using ZXing for decoding. Requests wide video (256x2048), rotates to landscape for decoding, applies contrast boost and tries both HybridBinarizer and GlobalHistogramBinarizer. Includes camera selector, manual/auto focus controls, and focus slider. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
171 lines
3.4 KiB
HTML
171 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<title>Barcode Scanner</title>
|
|
<style>
|
|
*, *::before, *::after {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
:root {
|
|
--accent: #00e87a;
|
|
--dim: #5a6475;
|
|
--surface: #12161c;
|
|
}
|
|
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
background: #000;
|
|
font-family: 'Courier New', monospace;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#app {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
#camera-view {
|
|
position: relative;
|
|
width: 100%;
|
|
flex: 1;
|
|
background: #000;
|
|
}
|
|
|
|
video {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: contain;
|
|
}
|
|
|
|
/* Transparent overlay — only draws scan lines */
|
|
#overlay {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
#debug {
|
|
position: absolute;
|
|
top: 6px;
|
|
left: 8px;
|
|
font-size: 11px;
|
|
color: rgba(255,255,255,0.6);
|
|
text-shadow: 0 1px 2px #000;
|
|
pointer-events: none;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
/* Bottom result panel */
|
|
#bottom-panel {
|
|
flex-shrink: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 12px 16px 18px;
|
|
background: var(--surface);
|
|
border-top: 1px solid #1e2530;
|
|
}
|
|
|
|
#result {
|
|
width: 100%;
|
|
min-height: 44px;
|
|
padding: 10px 14px;
|
|
border-radius: 8px;
|
|
background: #181e28;
|
|
border: 1px solid #1e2a38;
|
|
font-size: 14px;
|
|
color: var(--dim);
|
|
text-align: center;
|
|
word-break: break-all;
|
|
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
#result.found {
|
|
color: var(--accent);
|
|
border-color: var(--accent);
|
|
background: #0d1f15;
|
|
font-weight: bold;
|
|
font-size: 16px;
|
|
}
|
|
|
|
#result.error {
|
|
color: #ff5555;
|
|
border-color: #ff5555;
|
|
}
|
|
|
|
#focus-row {
|
|
display: none;
|
|
width: 100%;
|
|
align-items: center;
|
|
gap: 8px;
|
|
color: #dce4ef;
|
|
font-size: 13px;
|
|
}
|
|
|
|
#focus-slider {
|
|
flex: 1;
|
|
accent-color: var(--accent);
|
|
}
|
|
|
|
#focus-val {
|
|
min-width: 40px;
|
|
text-align: right;
|
|
color: var(--accent);
|
|
}
|
|
|
|
#start-btn {
|
|
padding: 13px 30px;
|
|
background: var(--accent);
|
|
color: #000;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-family: inherit;
|
|
font-size: 15px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<div id="camera-view">
|
|
<video id="video" autoplay playsinline muted></video>
|
|
<canvas id="overlay"></canvas>
|
|
<div id="debug"></div>
|
|
</div>
|
|
<div id="bottom-panel">
|
|
<div id="cam-info" style="width:100%;font-size:11px;color:#5a6475;word-break:break-all;"></div>
|
|
<div id="result">Point camera at a barcode</div>
|
|
<div id="focus-row">
|
|
<label style="display:flex;align-items:center;gap:4px;cursor:pointer;">
|
|
<input id="focus-auto" type="checkbox" checked>
|
|
Auto
|
|
</label>
|
|
<input id="focus-slider" type="range" min="0" max="1.62" step="0.01" value="0.3" disabled>
|
|
<span id="focus-val">0.30m</span>
|
|
</div>
|
|
<select id="camera-select" style="display:none; width:100%; padding:8px; background:#181e28; color:#dce4ef; border:1px solid #1e2a38; border-radius:8px; font-family:inherit;"></select>
|
|
<button id="start-btn">Start Camera</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="vendor/zxing.min.js"></script>
|
|
<script type="module" src="app.mjs"></script>
|
|
</body>
|
|
</html>
|