Skip to content

Python API Reference

The VideoCapture class is the only entry point for the QPyCam Python API.

qpycam.VideoCapture

Main class for managing video capture pipeline and related operations.

__init__(name='gst_pipeline', camera_type=CAMERA_TYPE_CSI, device_id=0, input_rtsp_url=None, source_width=1920, source_height=1080, fps=30, rotate=0, flip_horizontal=False, flip_vertical=False, output_file=None, timeout=0, display=False, fullscreen=False, display_width=1920, display_height=1080, output_ip=None, output_port=8900, mqtt_topic=None, mqtt_host=None, mqtt_port=1883, mqtt_config=None)

Parameters:

Name Type Description Default
name str

The name of the pipeline.

'gst_pipeline'
camera_type Literal[0, 1, 2]

The type of camera to use (0: CSI, 1: USB, 2: RTSP).

CAMERA_TYPE_CSI
device_id int

The device ID (only for USB cameras).

0
input_rtsp_url Optional[str]

The RTSP stream URL (only for RTSP cameras).

None
source_width int

The desired video width.

1920
source_height int

The desired video height.

1080
fps int

The desired frame rate of the video.

30
rotate Literal[0, 1, 2, 3]

The rotation option for the video (0: 0 degrees, 1: 90 degrees clockwise, 2: 90 degrees counterclockwise, 3: 180 degrees).

0
flip_horizontal bool

Whether to flip the video horizontally.

False
flip_vertical bool

Whether to flip the video vertically.

False
output_file Optional[str]

The file path to save the video. Only MP4 format is supported.

None
timeout int

The stream duration (in milliseconds). 0 means no timeout.

0
display bool

Whether to display the video on screen.

False
fullscreen bool

Whether to display the video in fullscreen mode.

False
display_width int

The width of the display video frame.

1920
display_height int

The height of the display video frame.

1080
output_ip Optional[str]

The RTSP server IP address to send the video stream.

None
output_port int

The RTSP server port to send the video stream.

8900
mqtt_topic Optional[str]

The MQTT topic to publish the AI inference results.

None
mqtt_host Optional[str]

The MQTT broker IP address.

None
mqtt_port int

The MQTT broker port number.

1883
mqtt_config Optional[str]

The MQTT configuration file path.

None

detect(detect_type='segmentation', delegate='gpu', module='deeplab-argmax', model=None, labels=None, threshold=0, results=0, constants=None)

Enable detection mode and configure related elements.

Parameters:

Name Type Description Default
detect_type Literal['classification', 'detection', 'segmentation', 'pose', 'superresolution']

The type of detection to perform. Can be one of classification, detection, segmentation, pose, superresolution.

'segmentation'
delegate Literal['cpu', 'gpu', 'xnnpack']

The backend for the model inference. Can be one of cpu, gpu, xnnpack.

'gpu'
module str

The AI model module to use (e.g., yolo-nas, mobilenet, posenet).

'deeplab-argmax'
model Optional[str]

The path to the AI model file.

None
labels Optional[str]

The path to the label file.

None
threshold float

The confidence threshold for the detection.

0
results int

The number of detection results to display.

0
constants Optional[str]

The additional constants for the model.

None

start()

Start the video capture pipeline.

stop()

Stop the video capture pipeline and cleanup resources.