class GVA::VideoFrame#

Overview#

This class represents video frame - object for working with RegionOfInterest and Tensor objects which belong to this video frame (image). RegionOfInterest describes detected object (bounding boxes) and its Tensor objects (inference results on RegionOfInterest level). Tensor describes inference results on VideoFrame level. VideoFrame also provides access to underlying GstBuffer and GstVideoInfo describing frame’s video information (such as image width, height, channels, strides, etc.). You also can get cv::Mat object representing this video frame. More…

#include <video_frame.h>

class VideoFrame {
public:
    // construction

    VideoFrame(GstBuffer* buffer, GstVideoInfo* info);
    VideoFrame(GstBuffer* buffer, const GstCaps* caps);
    VideoFrame(GstBuffer* buffer);

    // methods

    GstVideoMeta* video_meta();
    GstVideoInfo* video_info();
    std::vector<RegionOfInterest> regions();
    const std::vector<RegionOfInterest> regions() const;
    std::vector<Tensor> tensors();
    const std::vector<Tensor> tensors() const;
    std::vector<std::string> messages();

    RegionOfInterest add_region(
        double x,
        double y,
        double w,
        double h,
        std::string label = std::string(),
        double confidence = 0.0,
        bool normalized = false
    );

    Tensor add_tensor();
    void add_message(const std::string& message);
    void remove_region(const RegionOfInterest& roi);
    void remove_tensor(const Tensor& tensor);
};

Detailed Documentation#

This class represents video frame - object for working with RegionOfInterest and Tensor objects which belong to this video frame (image). RegionOfInterest describes detected object (bounding boxes) and its Tensor objects (inference results on RegionOfInterest level). Tensor describes inference results on VideoFrame level. VideoFrame also provides access to underlying GstBuffer and GstVideoInfo describing frame’s video information (such as image width, height, channels, strides, etc.). You also can get cv::Mat object representing this video frame.

Construction#

VideoFrame(GstBuffer* buffer, GstVideoInfo* info)

Construct VideoFrame instance from GstBuffer and GstVideoInfo. This is preferred way of creating VideoFrame.

Parameters:

buffer

GstBuffer* to which metadata is attached and retrieved

info

GstVideoInfo* containing video information

VideoFrame(GstBuffer* buffer, const GstCaps* caps)

Construct VideoFrame instance from GstBuffer and GstCaps.

Parameters:

buffer

GstBuffer* to which metadata is attached and retrieved

caps

GstCaps* from which video information is obtained

VideoFrame(GstBuffer* buffer)

Construct VideoFrame instance from GstBuffer. Video information will be obtained from buffer. This is not recommended way of creating VideoFrame, because it relies on GstVideoMeta which can be absent for the buffer.

Parameters:

buffer

GstBuffer* to which metadata is attached and retrieved

Methods#

GstVideoMeta* video_meta()

Get video metadata of buffer.

Returns:

GstVideoMeta of buffer, nullptr if no GstVideoMeta available

GstVideoInfo* video_info()

Get GstVideoInfo of this VideoFrame. This is preferrable way of getting any image information.

Returns:

GstVideoInfo of this VideoFrame

std::vector<RegionOfInterest> regions()

Get RegionOfInterest objects attached to VideoFrame.

Returns:

vector of RegionOfInterest objects attached to VideoFrame

const std::vector<RegionOfInterest> regions() const

Get RegionOfInterest objects attached to VideoFrame.

Returns:

vector of RegionOfInterest objects attached to VideoFrame

std::vector<Tensor> tensors()

Get Tensor objects attached to VideoFrame.

Returns:

vector of Tensor objects attached to VideoFrame

const std::vector<Tensor> tensors() const

Get Tensor objects attached to VideoFrame.

Returns:

vector of Tensor objects attached to VideoFrame

std::vector<std::string> messages()

Get messages attached to this VideoFrame.

Returns:

messages attached to this VideoFrame

RegionOfInterest add_region(
    double x,
    double y,
    double w,
    double h,
    std::string label = std::string(),
    double confidence = 0.0,
    bool normalized = false
)

Attach RegionOfInterest to this VideoFrame. This function takes ownership of region_tensor, if passed.

Parameters:

x

x coordinate of the upper left corner of bounding box

y

y coordinate of the upper left corner of bounding box

w

width of the bounding box

h

height of the bounding box

label

object label

confidence

detection confidence

normalized

if False, bounding box coordinates are pixel coordinates in range from 0 to image width/height. if True, bounding box coordinates normalized to [0,1] range.

Returns:

new RegionOfInterest instance

Tensor add_tensor()

Attach empty Tensor to this VideoFrame.

Returns:

new Tensor instance

void add_message(const std::string& message)

Attach message to this VideoFrame.

Parameters:

message

message to attach to this VideoFrame

void remove_region(const RegionOfInterest& roi)

Remove RegionOfInterest.

Parameters:

roi

the RegionOfInterest to remove

void remove_tensor(const Tensor& tensor)

Remove Tensor.

Parameters:

tensor

the Tensor to remove