Skip to main content

Scanning documents from a live camera stream with the Windows Document Scanner

This example demonstrates how to scan documents 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 document detection.

The implementation is split into several small, reusable components.

Requirements​

Ensure the following are available:

  • Python 3 with pip on PATH
  • 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 (or opencv-python-headless for headless machines) and numpy
pip install opencv-python numpy

Camera helper​

The following helper opens the camera:

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.

Document scanner​

  • Creates a DocumentScanner instance with ProcessingMode.AUTO
document scanner
loading...

The following callback prints the status of each detection result to the console:

print result
loading...

Scanning loop​

The following function runs the 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​

The following helper opens the preview window:

  • 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:

draw frame
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.

example_usage
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.