Scanning documents from a live camera stream with the Linux Document Scanner
This example demonstrates how to scan documents 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 document 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_csiorlibcamerapipelines - 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
loading...
- 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)
Document scanner
- Creates a DocumentScanner instance with
ProcessingMode.AUTO
loading...
loading...
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
loading...
- Displays the processed frame in a real-time window
- Press ESC or close the window to stop
loading...
Running the example
The document_live function combines all components into a runnable demo.
It opens the camera, creates the document scanner, and starts the scanning loop with or without a live preview window.
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.
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
