@zimecode/scanner
v1.0.32
Published
Browser scanner utilities for detecting and decoding Zimecode markers.
Maintainers
Readme
@zimecode/scanner
@zimecode/scanner provides browser utilities to detect and decode Zimecode markers from a live camera stream.
Installation
npm install @zimecode/scannerWhat this package exports
import { startCameraAndDetect, decode } from "@zimecode/scanner";startCameraAndDetect(...)starts camera capture, scans frames with OpenCV.js, and returns detection candidates.decode(...)converts a candidate matrix into a Zime ID string.
Requirements
This package is designed for browsers and needs:
- A camera-capable browser (
navigator.mediaDevices.getUserMedia) - OpenCV.js loaded globally as
window.cv - DOM elements for video and canvases
Example OpenCV.js include:
<script async src="https://docs.opencv.org/4.x/opencv.js"></script>Quick start
<video id="video" playsinline muted></video>
<canvas id="srcCanvas"></canvas>
<canvas id="dbgCanvas"></canvas>import { startCameraAndDetect, decode } from "@zimecode/scanner";
const settings = {
video: document.getElementById("video"),
srcCanvas: document.getElementById("srcCanvas"),
dbgCanvas: document.getElementById("dbgCanvas"),
scanWindow: {
enabled: true,
sizeRatio: 0.5,
},
invertBeforeScan: false,
scanBothPolarities: false,
};
startCameraAndDetect({
settings,
callback: (candidates) => {
for (const candidate of candidates) {
const zimeId = decode({ matrix: candidate.matrix });
if (zimeId) {
console.log("Decoded Zime ID:", zimeId, "dimension:", candidate.dimension);
}
}
},
}).catch(console.error);API
startCameraAndDetect({ settings, callback })
Starts a continuous detection loop.
settings.video:<video>elementsettings.srcCanvas: hidden/processing canvassettings.dbgCanvas: visible canvas for rendered camera output and overlayssettings.scanWindow(optional): visual square guide overlayenabled(boolean): show/hide guide overlaysizeRatio(number, default0.5): square side relative to viewport short edgeshadeColor(string, defaultrgba(0, 0, 0, 0.5)): color for darkened outside areaborderColor(string, defaultrgba(255, 255, 255, 0.9)): guide border colorborderWidth(number, default2): guide border width in CSS pixels
settings.invertBeforeScan(optional, defaultfalse): inverts camera frame colors before detection and matrix sampling (useful for testing color-inverted Zimecodes)settings.scanBothPolarities(optional, defaultfalse): scans each frame sequentially in normal colors and then inverted colors; when enabled, this takes precedence overinvertBeforeScancallback(candidates): called per frame with detected candidates
Each candidate includes (among others):
quad: detected marker corner points in video coordinatesquadCanvas: mapped corner points in debug-canvas coordinatesdimension: estimated Zimecode dimensionscore: detection quality scorematrix: sampled2S x 2Sbit matrix for decodingscanInverted:trueif the candidate came from the inverted scan pass, otherwisefalse
decode({ matrix })
Decodes a sampled matrix and returns a decimal Zime ID (string) when redundancy checks pass.
If decoding fails, it returns undefined.
Notes
- The package is browser-focused (not intended for plain Node.js runtime).
- Camera permission is required.
- Detection quality depends on focus, lighting, and marker size.
