Skip to main content

Python package which combines OpenCV-Python and PySide6.

Introduction

PySide6 provides powerful tools to acquire video stream from file or device, and to display it on GUI. cv2 is a de facto standard module for image analysis with Python. It is natural to process the image with cv2 and display it using PySide6.

cv2PySide6 is a package to help build the video frame pipeline for this purpose. It provides the object to convert PySide6.QVideoFrame to numpy.ndarray, and widget to directly display the array.

Installation

Before you install, be careful for other Qt-dependent packages installed in your environment. For example, non-headless OpenCV-Python modifies the Qt dependency thus making PySide6 unavailable.

cv2PySide6 can be installed using pip.

$ pip install cv2PySide6

How to use

User can construct a pipeline which converts QVideoFrame to ndarray, performs any desired processing and displays to the widget.


Video display pipeline

QVideoFrame to ndarray

QVideoFrame is acquired from media file (PySide6.QMediaPlayer) or camera capture session (PySide6.QMediaCaptureSession) by setting PySide6.QVideoSink to them and listening to QVideoSink.videoFrameChanged signal.

To convert it, pass the video frame cv2PySide6.FrameToArrayConverter and listen to FrameToArrayConverter.arrayChanged signal.

(Note) If you want to convert a single PySide6.QImage to ndarray, qimage2ndarray package provides handy functions.

Displaying ndarray

cv2PySide6.NDArrayLabel is a widget to directly display ndarray. It can also scale the image with respect to the widget size, and user can select the scaling mode.

Convenience classes

For convenience, cv2PySide6 provides NDArrayVideoPlayer and NDArrayMediaCaptureSession which inherits their PySide6 counterparts and emits arrayChanged signal. NDArrayVideoPlayerWidget and NDArrayCameraWidget are the minimal implementation to display the video stream with them.

However, time-consuming image processing will block the GUI with these classes because they use a single thread. To build multithread pipeline, refer to the examples and build the pipeline yourself.

Examples

Use cases with multithreading are provided in examples directory. They can be found in documentation as well.

Documentation

Documentation can be found on Read the Docs:

https://cv2pyside6.readthedocs.io/

If you want to build the document yourself, clone the source code and install with [doc] option. Go to doc directory and build.

$ pip install cv2PySide6[doc]
$ cd doc
$ make html

Metadata

Release files for cv2PySide6 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cv2PySide6 3.1.0
File Size Uploaded
cv2PySide6-3.1.0.tar.gz 406.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cv2PySide6 3.1.0
File Interpreter ABI Platform
cv2PySide6-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 813.1 kB

Release files / cv2PySide6-3.1.0.tar.gz

Download URL cv2PySide6-3.1.0.tar.gz
Size 406.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c6dc9bd2f818beb4eb24ac829ae13eb357223c44be2706cf28640eeaffd53053
BLAKE2b-256 checksum
How to use checksums
bcb2976487ca3335bef1bb54b4864498e4a08e4bae5068fc5fc4dee1d0432d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / cv2PySide6-3.1.0-py3-none-any.whl

Download URL cv2PySide6-3.1.0-py3-none-any.whl
Size 406.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
756464b802e28947abebe34fdbab6e9fbb07e30c43da1ddd5a4713ce63e4807e
BLAKE2b-256 checksum
How to use checksums
c95b4807106c35a26be6dc353c281bc9f8c2c6c90514726baec67eba9d95d1d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

3.1.0 This release

2 release files

3.0.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page