Advanced barcode and QR code scanner with real-time image processing for POSAwesome.
- High Resolution: Supports up to 1920x1080 (Full HD) with minimum 1280x720
- Rear Camera Preference: Automatically selects environment-facing camera for better barcode scanning
- Advanced Constraints: Continuous autofocus, exposure, and white balance control
- Enhanced Mode: Specialized settings for dark/black barcodes and difficult scanning conditions
Real-time image enhancement using OpenCV.js in a separate Web Worker to prevent UI blocking:
- Non-Blocking Processing: Heavy image processing runs in Web Worker thread
- Local Loading: OpenCV.js loads from local bundle for reliability and speed
- Gaussian Blur: Light noise reduction (3x3 kernel for speed)
- Adaptive Thresholding: Better contrast for varying lighting conditions
- Unsharp Masking: Advanced sharpening technique for edge enhancement
- Morphological Operations: Light image cleanup (3x3 kernel for speed)
- Quick Process: Real-time processing with essential filters (default)
- Full Process: Complete pipeline for damaged or low-contrast barcodes
- Fallback Mode: Basic processing when device constraints are not supported
- Enhanced Camera Mode: Always uses optimized camera settings for best performance
- High-Quality Constraints: Full HD resolution with enhanced contrast, brightness, and sharpness
- OpenCV On: Real-time image preprocessing enabled (recommended)
- OpenCV Off: Basic scanning without image enhancement
- Flash/Torch: Toggle camera flash for low-light scanning
- Camera Switch: Switch between front and rear cameras if multiple available
- QR Code
- EAN-13, EAN-8
- Code 128, Code 39, Code 93
- UPC-A, UPC-E
- Codabar
- ITF (Interleaved 2 of 5)
- HTTPS Required: Camera access requires secure context (HTTPS protocol)
- SSL Certificate: Ensure valid SSL certificate is installed
- Mixed Content: Avoid loading scanner over HTTP on HTTPS sites
- Chrome/Edge: Full feature support
- Firefox: Good support for most features
- Safari: Basic support (some advanced constraints may not work)
- Mobile Browsers: Optimized for mobile device cameras
- Ensure site is served over HTTPS
- Grant camera permission when prompted
- Point camera at barcode/QR code within the scanning frame
- Use controls to optimize for specific scanning conditions
- OpenCV Processing is automatically optimized for dark/black barcodes
- Use Flash in low-light conditions
- Try different Camera angles or distances
- Hold steady for better focus
- Web Worker Processing: Heavy OpenCV operations run in separate thread, keeping UI responsive
- Local Loading: OpenCV.js loads from local bundle for fast, reliable initialization
- Frame Skipping: Only processes every 3rd frame to prevent queue buildup
- Processing Lock: Prevents multiple simultaneous operations
- Enhanced Camera Settings: Always uses best available camera constraints
- Automatic Fallback: Gracefully handles worker failures and initialization issues
Camera Permission Denied
Solution: Allow camera access in browser settings and refresh page
No Camera Found
Solution: Ensure device has working camera and no other apps are using it
HTTPS Required
Solution: Access the application over HTTPS instead of HTTP
Constraints Not Supported
Solution: Scanner will automatically try fallback settings
// Listen for successful scans
@barcode-scanned="onBarcodeScanned"
// Listen for scanner close
@scanner-closed="onScannerClosed"
// Component props
:scan-type="'Both'" // 'QR Code', 'Barcode', 'Both'methods: {
onBarcodeScanned(result) {
console.log('Scanned:', result);
// Handle scanned barcode
},
onScannerClosed() {
console.log('Scanner closed');
// Handle scanner close
}
}- Main Component:
frontend/src/posapp/components/pos/CameraScanner.vue - OpenCV Processor:
frontend/src/posapp/utils/opencvProcessor.js - Web Worker Manager:
frontend/src/posapp/utils/opencvWorkerManager.js - OpenCV Worker:
frontend/src/posapp/workers/opencvWorker.js - Dependencies:
@techstark/opencv-js(bundled locally),vue-qrcode-reader
- Main Thread: Camera handling, UI updates, barcode detection
- Worker Thread: Heavy OpenCV image processing operations
- Communication: Message passing with promise-based API
- Error Handling: Graceful fallback to main thread processing
- Automatic cleanup of OpenCV matrices in Worker thread
- Proper disposal of camera streams in main thread
- Worker cleanup on component unmount
- Error recovery and fallback handling
- Frame Capture: Get video frame from camera (every 3rd frame)
- Worker Transfer: Send ImageData to Web Worker via message passing
- Noise Reduction: Light Gaussian blur (3x3 kernel for speed)
- Edge Enhancement: Unsharp masking for better definition
- Thresholding: Adaptive binary conversion (optimized parameters)
- Cleanup: Light morphological operations (3x3 kernel)
- Result Transfer: Send processed ImageData back to main thread
- Detection: Barcode/QR code recognition on main thread
- Minimum: 720p camera resolution
- Recommended: 1080p camera with autofocus
- Optimal: Rear camera with macro focus capability
- OpenCV.js library: ~11MB (bundled locally, no network dependency)
- Real-time processing: Complete offline capability
- No external dependencies: Works without internet connection
- Web Worker: Separate thread prevents POS UI blocking
- Enhanced mode increases power consumption
- OpenCV processing uses more CPU
- Flash usage significantly drains battery
Check browser console for:
- OpenCV initialization status
- Camera configuration details
- Processing pipeline errors
- Disable OpenCV processing temporarily
- Switch to Standard mode
- Close other camera-using applications
- Try different browser
- Ensure good lighting conditions
- Hold steady at appropriate distance
- Clean camera lens
- Try Enhanced mode for difficult barcodes
- Camera access requires user permission
- No image data is transmitted or stored
- Processing happens entirely client-side
- Scanned results are handled by parent component
For technical issues:
- Check browser console for error messages
- Verify HTTPS is enabled
- Test camera with other applications
- Try different browsers for compatibility