Array-frame conversion
araviq6.array2qvideoframe provides functions to convert numpy array to
QVideoFrame.
To convert QVideoFrame to numpy array, convert the frame to QImage by
QVideoFrame.toImage() and use qimage2ndarray package.
Note
This module imitates https://github.com/hmeine/qimage2ndarray.
- araviq6.array2qvideoframe.array2qvideoframe(array: ndarray, normalize: bool | int | Tuple[int, int] = False) araviq6.qt_compat.QtMultimedia.QVideoFrame[source]
Convert a 2D or 3D numpy array into 32-bit
QVideoFrame.The dimensions of a 3D array are
(width, height, channels), and the channels can be 1, 2, 3 or 4. 2D array with(width, height)dimension is converted to(width, height, 1).Number of the channels is interpreted as follows:
#channels
interpretation
1
scalar/gray
2
scalar/gray + alpha
3
RGB
4
RGB + alpha
Note that the scalar data will be converted into gray RGB triples.
The parameter normalize can be used to normalize an frame’s value range to 0-255.
- If normalize =
(nmin, nmax): Scale & clip frame values from
nmin..nmaxto0..255- If normalize =
nmax: Lets
nmindefault to zero, i.e. scale & clip the range0..nmaxto0..255- If normalize =
True: Scale frame values to
0..255, except for boolean arays, whereFalseandTrueare mapped to0and255. Same as passing(gray.min(), gray.max())
If array contains masked values, the corresponding pixels will be transparent in the result. Thus, the result be of
Format_BGRA8888if the input already contains an alhpa channel (i.e., has shape(H, W, 4)) or if there are masked pixels, andFormat_BGRX8888otherwise.- If normalize =