Table of Contents
video_display_attach
Attach a video stream to the specified window.
Description
The video_display_attach function attaches a video stream to the specified window. Video frames should be written to the window at the given frame rate and dimensions, and with the given format and data type. If hardware_accelerated is true then GPU hardware acceleration will be used for the video. If no hardware acceleration is available then it should fall back to software rendering even if this flag is set, so it is highly recommended to enable hardware acceleration.
In the case of the IMAGE_FORMAT_COMPRESSED
image format, the frame_width and frame_height may be zero. They will be
set internally based on the image data. Images compressed as BMP, PNG, ICO, JPEG, TIFF, GIF and HD Photo should be
supported. The data_type in this case should always be IMAGE_DATA_TYPE_UINT8
.
Prototype
t_error video_display_attach(t_video_window window, t_double frame_rate, t_uint frame_width, t_uint frame_height, t_image_format format, t_image_data_type data_type, t_boolean hardware_accelerated, t_video_display * display);
Parameters
t_video_window window
The handle to the window returned by video_display_open.
t_double frame_rate
A real number specifying the frame rate at which video input will be captured in Hertz. A value such as 30 Hz or 60 Hz is typical.
t_uint frame_width
The width of the image to be captured in pixels (number of columns).
t_uint frame_height
The height of the image to be captured in pixels (number of rows).
t_image_format format
The format in which to provide video data. Valid video formats are listed in the table below. The format used by MATLAB for colour images is IMAGE_FORMAT_COL_MAJOR_PLANAR_RGB.
Format |
Description |
---|---|
IMAGE_FORMAT_COL_MAJOR_PLANAR_RGB |
A column major, planar, image format for colour images. The red, green and blue components of the image are stored as separate image planes rather than being interleaved. Within each image plane, each column is stored sequentially in memory. |
IMAGE_FORMAT_COL_MAJOR_GRAYSCALE |
A column major image format for grayscale images. Each column is stored sequentially in memory. |
IMAGE_FORMAT_ROW_MAJOR_INTERLEAVED_BGR |
A row major BGR image format for colour images that is suitable for OpenCV CV_8UC3 matrices (image data type must be IMAGE_DATA_TYPE_UINT8 in this case). Each row is stored sequentially in memory. |
IMAGE_FORMAT_ROW_MAJOR_GRAYSCALE |
A row major image format for grayscale images that is suitable for OpenCV CV_8UC1 matrices (image data type must be IMAGE_DATA_TYPE_UINT8 in this case). Each row is stored sequentially in memory. |
t_image_data_type data_type
The data type to use for each pixel component in the image. This parameter is typically IMAGE_DATA_TYPE_UINT8. The full set of possible data types is enumerated in the table below:
Data type |
Description |
---|---|
IMAGE_DATA_TYPE_UINT8 |
Each pixel component is an unsigned byte (8-bit) or t_uint8. Hence, pixel values range from 0 to 255. This data type is typically used. Image processing operations on this data type generally have the highest performance. |
IMAGE_DATA_TYPE_UINT16 |
Each pixel component is an unsigned short (16-bit) or t_uint16. Hence, pixel values range from 0 to 65535. |
IMAGE_DATA_TYPE_UINT32 |
Each pixel component is an unsigned integer (32-bit) or t_uint32. Hence, pixel values range from 0 to 4294967295.
Image processing operations on this data type are often slower than the |
IMAGE_DATA_TYPE_SINGLE |
Each pixel component is a single-precision (32-bit) floating-point value or t_single. Pixel values range from 0 to 1. Pixel values outside that range are not supported. |
IMAGE_DATA_TYPE_DOUBLE |
Each pixel component is a double-precision (64-bit) floating-point value or t_double. Pixel values range from 0 to 1.
Pixel values outside that range are not supported. This data type is not recommended as operations on this data type are generally slowest.
Use |
t_boolean hardware_accelerated
A boolean value indicating whether hardware acceleration should be used or not. If this parameter is true but no hardware acceleration is available, it will revert to software rendering.
t_video_display * display
The address of a t_video_display
variable in which the display handle will be stored.
Return value
The return value is 0 if the attachment is successfully. Otherwise a negative
error code is returned. Error codes are
defined in quanser_errors.h
. A suitable error message
may be retrieved using msg_get_error_message.
Error codes
QERR_INVALID_ARGUMENT
One of the arguments is invalid.
QERR_NOT_SUPPORTED
This function is not supported on this platform.
QERR_OUT_OF_MEMORY
There is not enough memory to complete the operation.
Requirements
Include Files |
Libraries |
---|---|
quanser_video.h |
quanser_media.lib;quanser_communications.lib;quanser_runtime.lib;quanser_common.lib |
Examples
t_video_window window; /* Open a video display window for displaying the captured video */ result = video_display_open("Video Capture", NULL, &window); if (result >= 0) { t_video_display display; /* Attach a display object to the window for receiving the video stream */ result = video_display_attach(window, 30.0, 640, 480, IMAGE_FORMAT_COL_MAJOR_PLANAR_RGB, IMAGE_DATA_TYPE_UINT8, true, &display); if (result >= 0) { ... /* Write the frame to the display */ video_display_write(display, image, frame_width * frame_height * 3); ... /* Detach the video stream from the display */ video_display_detach(display); } /* Close the video display window */ video_display_close(window); }
See Also
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.