Skip to main content

Scanning barcodes from a live camera stream with the Linux Barcode Scanner

This example demonstrates how to scan barcodes from a live camera stream on Linux 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

Make sure you have these packages installed:

pip install scanbotsdk opencv-python numpy

Your system must also provide:

  • GStreamer plugins if using jetson_csi or libcamera pipelines
  • A camera device (USB webcam, Jetson CSI, or libcamera-compatible camera)

Optional: Install CUDA + TensorRT

Requires Jetpack 6.1, CUDA 12.6, and TensorRT 10.3 for GPU acceleration.

sudo apt install -y nvidia-l4t-cuda libnvinfer10 libnvinfer-plugin10 libnvonnxparsers10

Camera helper

  • Opens a camera using V4L2 (numeric index like "0") or GStreamer ("jetson_csi" / "libcamera")
  • Requests 1280×720 @ 30fps

Device strings:

  • "0", "1" — USB webcams via V4L2
  • "jetson_csi" — Jetson CSI camera (nvarguscamerasrc)
  • "libcamera" — modern libcamera-based pipeline (e.g. Raspberry Pi OS Bookworm)

Barcode Scanner

barcode scanner
loading...
  • Creates a BarcodeScanner instance with ProcessingMode.AUTO
  • Enables common barcode formats
  • Optional: enable TensorRT (use_tensorrt=True) for hardware acceleration on Jetson or other supported devices
print result
loading...

Scanning loop

  • Each captured frame is wrapped in an ImageRef with live_source=True for maximum FPS
  • Continuously reads frames from the camera
  • Sends them to the scanner
  • Passes results to an on_result callback

Optional: Live preview window

  • Displays the processed frame in a real-time window
  • Press ESC or close the window to stop
draw 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.

example usage
loading...

Performance tip (Jetson):

To avoid throttling, set max GPU/CPU/memory clocks:

sudo jetson_clocks --store
sudo jetson_clocks

Restore defaults later:

sudo jetson_clocks --restore

Try the full example

To run a complete working demo, clone the official example repository:

Get in touch

If you need further information or are interested in licensing the Scanbot SDK, please get in touch with our solution experts.