Handle Difficult Barcodes
This guide provides techniques for improving barcode detection in challenging conditions.
Common Challenges
- Poor lighting or shadows
- Blurry or out-of-focus images
- Small or distant barcodes
- Damaged or partially obscured barcodes
- Low contrast between bars and background
Improving Detection
Adjust Patch Size
For small or distant barcodes, use a smaller patch size:
locator: {
patchSize: "small" // or "x-small" for very small barcodes
}
Increase Resolution
Higher resolution provides more detail:
inputStream: {
size: 1280, // Larger processing size
constraints: {
width: { ideal: 1920 },
height: { ideal: 1080 }
}
}
Disable Half Sampling
For fine details, process at full resolution:
locator: {
halfSample: false
}
Handling False Positives
Validate Results
Check result confidence and format:
Quagga.onDetected(function(result) {
// Check if result has expected format
if (result.codeResult.format !== 'ean_13') {
return; // Ignore unexpected formats
}
// Validate checksum externally if needed
if (!validateBarcode(result.codeResult.code)) {
return;
}
processBarcode(result.codeResult.code);
});
Require Multiple Reads
Confirm detection across multiple frames:
let lastCode = null;
let readCount = 0;
Quagga.onDetected(function(result) {
const code = result.codeResult.code;
if (code === lastCode) {
readCount++;
if (readCount >= 3) {
// Confirmed detection
processBarcode(code);
readCount = 0;
}
} else {
lastCode = code;
readCount = 1;
}
});
Using Debug Flags
Enable visual debugging to understand detection issues:
Quagga.init({
debug: true,
decoder: {
debug: {
drawBoundingBox: true,
drawScanline: true
}
},
locator: {
debug: {
showFoundPatches: true
}
}
});
See Use Debug Flags for complete details.
Related
- Configuration Reference - All configuration options
- Optimize Performance - Balance accuracy vs speed
- Use Debug Flags - Diagnostic tools