2.4 KiB
2.4 KiB
Optimize Performance
This guide covers techniques to improve Quagga2's barcode scanning performance.
Overview
Performance optimization in Quagga2 involves balancing accuracy against speed. The key areas to optimize are:
- Input resolution and scaling
- Locator configuration
- Reader selection
- Processing frequency
Input Resolution
Using inputStream.size
Reducing the processing resolution is the most effective way to improve performance:
Quagga.init({
inputStream: {
size: 640 // Process at 640px max dimension instead of full resolution
}
});
Recommended values:
- 1280px - High quality, slower (good for static images)
- 800px - Balanced (default for
decodeSingle) - 640px - Fast (recommended for live scanning)
- 480px - Very fast (may reduce accuracy)
Camera Constraints
Request only the resolution you need:
inputStream: {
constraints: {
width: { ideal: 1280 },
height: { ideal: 720 }
}
}
Locator Configuration
Half Sampling
Keep halfSample: true (default) for faster localization:
locator: {
halfSample: true // Processes at half resolution
}
Patch Size
Larger patch sizes are faster but may miss small barcodes:
locator: {
patchSize: "large" // Options: x-small, small, medium, large, x-large
}
Reader Selection
Only enable the barcode formats you need:
decoder: {
readers: ["code_128_reader"] // Don't enable all readers
}
Processing Frequency
Limit scan rate to reduce CPU usage:
Quagga.init({
frequency: 10 // Max 10 scans per second
});
Disable Localization
If barcode position is fixed, disable localization entirely:
Quagga.init({
locate: false,
inputStream: {
area: {
top: "25%",
right: "25%",
bottom: "25%",
left: "25%"
}
}
});
Related
- Configuration Reference - All configuration options
- How Barcode Localization Works - Understanding the algorithm