Scanning barcodes from a live camera stream with the Windows Barcode Scanner
This example demonstrates how to scan barcodes from a live camera stream on Windows using the Scanbot SDK. It uses OpenCV for camera capture and display, and the Scanbot SDK for real-time barcode detection.
The implementation is split into several small, reusable components.
Requirements
Ensure the following are available:
- Python 3 with
piponPATH - A camera device (USB webcam attached to the machine)
- The Scanbot Python SDK wheel installed for your platform (see the Python quick start)
opencv-python(oropencv-python-headlessfor headless machines) andnumpy
pip install opencv-python numpy
Camera helper
The following helper opens the camera:
loading...
The same helper is used on Linux and Windows. On Windows it selects the correct OpenCV capture backend automatically:
- Media Foundation (
cv.CAP_MSMF) is tried first. - DirectShow (
cv.CAP_DSHOW) is used as a fallback if Media Foundation can't open the device.
Device strings on Windows:
"0","1"— index of the camera as enumerated by Windows.
The helper requests 1280×720 at 30 fps; the actual resolution and frame rate depend on the connected device.
Barcode Scanner
The following function creates the scanner:
loading...
- Creates a BarcodeScanner instance with
ProcessingMode.AUTO - Enables common barcode formats
The following callback prints each result to the console:
loading...
Scanning loop
The following function runs the scanning loop:
loading...
- Each captured frame is wrapped in an
ImageRefwithlive_source=Truefor maximum FPS - Continuously reads frames from the camera
- Sends them to the scanner
- Passes results to an
on_resultcallback
Optional: Live preview window
The following helper opens the preview window:
loading...
- Displays the processed frame in a real-time window
- Press ESC or close the window to stop
The following callback draws each result on the frame:
loading...
Running the example
The barcode_live function combines all components into a runnable demo.
It opens the camera, creates the Barcode Scanner, and starts the scanning loop with or without a live preview window.
loading...
Try the full example
To run a complete working demo, clone the official example repository and follow the Python instructions:
Get in touch
If you need further information or are interested in licensing the Scanbot SDK, please get in touch with our solution experts.
Scanbot SDK is part of the Apryse SDK product family
A mobile scan is just the start. With Apryse SDKs, you can expand mobile workflows into full cross‑platform document processing. Whether you need to edit PDFs, add secure digital signatures, or use a fast, customizable document viewer and editor, Apryse gives you the tools to build powerful features quickly.
Learn more
