libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches

OpenCV video capture source that renders via an OpenGL sprite. More...

#include <gl_cv.hpp>

Collaboration diagram for mx::MXCapture:
[legend]

Public Member Functions

 MXCapture ()=default
 Default constructor.
 ~MXCapture ()=default
 Destructor.
MXCapture & operator= (const MXCapture &)=delete
MXCapture & operator= (MXCapture &&)=delete
 MXCapture (const MXCapture &)=delete
 MXCapture (MXCapture &&)=delete
bool open (const std::string &filename)
 Open a video file for capture.
bool open (int id, int mode=0)
 Open a camera device for capture.
void close ()
 Close the video source.
bool is_open () const
 Check whether the capture source is open.
bool createImage (gl::GLWindow *window, size_t width, size_t height, const std::string &vert, const std::string &frag)
 Create the backing sprite/texture for displaying frames.
gl::GLSprite * getSprite ()
 Access the internal sprite.
void draw (int x, int y, int width, int height)
 Draw the most recently captured frame.
void draw (int x, int y)
 Draw using the sprite's native dimensions.
bool reload (const std::string &vert, const std::string &frag)
 Replace the shader pair without reopening the source.
bool read ()
 Grab and decode the next frame from the source.
bool read (cv::Mat &frame)
 Grab and decode the next frame into a cv::Mat.
void set (unsigned int option, double value)
 Set a VideoCapture property.
double get (unsigned int option)
 Query a VideoCapture property.
 MXCapture ()=default
 Default constructor.
 ~MXCapture ()=default
 Destructor.
MXCapture & operator= (const MXCapture &)=delete
MXCapture & operator= (MXCapture &&)=delete
 MXCapture (const MXCapture &)=delete
 MXCapture (MXCapture &&)=delete
bool open (const std::string &filename)
 Open a video file.
bool open (int id, int mode=0)
 Open a camera device.
void close ()
 Close the capture device.
bool is_open () const
 Check whether the capture device is open.
bool createImage (VKWindow *window, size_t width, size_t height, const std::string &vert, const std::string &frag)
 Allocate the VKSprite and upload the initial texture.
VKSprite * getSprite ()
 Access the backing sprite.
void draw (int x, int y, int width, int height)
 Draw the current frame at a specified position and size.
void draw (int x, int y)
 Draw using the sprite's native dimensions.
bool reload (size_t width, size_t height, const std::string &vert, const std::string &frag)
 Replace the vertex/fragment shaders.
bool read ()
 Capture and upload the next video frame.
bool read (cv::Mat &frame)
 Capture the next frame into a cv::Mat.
void set (unsigned int option, double value)
 Set a VideoCapture property.
double get (unsigned int option)
 Query a VideoCapture property.

Private Attributes

gl::GLSprite sprite
 Rendering sprite.
std::unique_ptr< gl::ShaderProgram > shader
 Active shader program.
gl::GLWindow * window = nullptr
 Parent GL window.
cv::VideoCapture cap
 OpenCV capture device.
cv::Mat frame
 Most recent decoded frame.
VKSprite * sprite = nullptr
 Backing Vulkan sprite.

Detailed Description

OpenCV video capture source that renders via an OpenGL sprite.

Vulkan OpenCV video capture source.

Opens a video file or camera device, reads frames frame-by-frame, and uploads each frame to a gl::GLSprite texture for display inside a gl::GLWindow with a custom GLSL shader.

Opens a video file or camera, decodes frames, and uploads them to a VKSprite texture for Vulkan-accelerated rendering inside a VKWindow.

Definition at line 26 of file gl_cv.hpp.

Constructor & Destructor Documentation

◆ MXCapture() [1/6]

mx::MXCapture::MXCapture ( )
default

Default constructor.

Referenced by MXCapture(), MXCapture(), operator=(), and operator=().

◆ ~MXCapture() [1/2]

mx::MXCapture::~MXCapture ( )
default

Destructor.

◆ MXCapture() [2/6]

mx::MXCapture::MXCapture ( const MXCapture & )
delete

References MXCapture().

◆ MXCapture() [3/6]

mx::MXCapture::MXCapture ( MXCapture && )
delete

References MXCapture().

◆ MXCapture() [4/6]

mx::MXCapture::MXCapture ( )
default

Default constructor.

◆ ~MXCapture() [2/2]

mx::MXCapture::~MXCapture ( )
default

Destructor.

◆ MXCapture() [5/6]

mx::MXCapture::MXCapture ( const MXCapture & )
delete

References MXCapture().

◆ MXCapture() [6/6]

mx::MXCapture::MXCapture ( MXCapture && )
delete

References MXCapture().

Member Function Documentation

◆ close() [1/2]

void mx::MXCapture::close ( )

Close the video source.

Definition at line 25 of file gl_cv.cpp.

References cap.

◆ close() [2/2]

void mx::MXCapture::close ( )

Close the capture device.

◆ createImage() [1/2]

bool mx::MXCapture::createImage ( gl::GLWindow * window,
size_t width,
size_t height,
const std::string & vert,
const std::string & frag )

Create the backing sprite/texture for displaying frames.

Parameters
windowOpenGL window context.
widthFrame display width.
heightFrame display height.
vertPath to the vertex shader GLSL file.
fragPath to the fragment shader GLSL file.
Returns
true on success.

Definition at line 29 of file gl_cv.cpp.

References gl::createTexture(), shader, sprite, and window.

◆ createImage() [2/2]

bool mx::MXCapture::createImage ( VKWindow * window,
size_t width,
size_t height,
const std::string & vert,
const std::string & frag )

Allocate the VKSprite and upload the initial texture.

Parameters
windowParent VKWindow.
widthDisplay width.
heightDisplay height.
vertVertex shader path.
fragFragment shader path.
Returns
true on success.

Definition at line 28 of file vk_cv.cpp.

References sprite, and window.

◆ draw() [1/4]

void mx::MXCapture::draw ( int x,
int y )

Draw using the sprite's native dimensions.

Parameters
xDestination X position.
yDestination Y position.

Definition at line 74 of file gl_cv.cpp.

References sprite, and window.

◆ draw() [2/4]

void mx::MXCapture::draw ( int x,
int y )

Draw using the sprite's native dimensions.

Parameters
xDestination X.
yDestination Y.

◆ draw() [3/4]

void mx::MXCapture::draw ( int x,
int y,
int width,
int height )

Draw the most recently captured frame.

Parameters
xDestination X position.
yDestination Y position.
widthDisplay width.
heightDisplay height.

Definition at line 67 of file gl_cv.cpp.

References sprite, and window.

◆ draw() [4/4]

void mx::MXCapture::draw ( int x,
int y,
int width,
int height )

Draw the current frame at a specified position and size.

Parameters
xWidth destination X.
yWidth destination Y.
widthDisplay width.
heightDisplay height.

◆ get() [1/2]

double mx::MXCapture::get ( unsigned int option)

Query a VideoCapture property.

Parameters
optioncv::VideoCaptureProperties constant.
Returns
Current property value.

Definition at line 85 of file gl_cv.cpp.

References cap.

◆ get() [2/2]

double mx::MXCapture::get ( unsigned int option)

Query a VideoCapture property.

Parameters
optioncv::VideoCaptureProperties constant.
Returns
Current value.

◆ getSprite() [1/2]

gl::GLSprite * mx::MXCapture::getSprite ( )
inline

Access the internal sprite.

Returns
Pointer to the backing gl::GLSprite.

Definition at line 76 of file gl_cv.hpp.

References sprite.

◆ getSprite() [2/2]

VKSprite * mx::MXCapture::getSprite ( )
inline

Access the backing sprite.

Returns
Pointer to the VKSprite.

Definition at line 75 of file vk_cv.hpp.

References sprite.

◆ is_open() [1/2]

bool mx::MXCapture::is_open ( ) const
inline

Check whether the capture source is open.

Returns
true if the VideoCapture is opened.

Definition at line 59 of file gl_cv.hpp.

References cap.

◆ is_open() [2/2]

bool mx::MXCapture::is_open ( ) const
inline

Check whether the capture device is open.

Returns
true if the VideoCapture is opened.

Definition at line 58 of file vk_cv.hpp.

References cap.

◆ open() [1/4]

bool mx::MXCapture::open ( const std::string & filename)

Open a video file for capture.

Parameters
filenamePath to the video file.
Returns
true on success.

Definition at line 11 of file gl_cv.cpp.

References cap.

◆ open() [2/4]

bool mx::MXCapture::open ( const std::string & filename)

Open a video file.

Parameters
filenamePath to the video file.
Returns
true on success.

◆ open() [3/4]

bool mx::MXCapture::open ( int id,
int mode = 0 )

Open a camera device for capture.

Parameters
idCamera device index.
modeOptional backend hint (0 = auto).
Returns
true on success.

Definition at line 15 of file gl_cv.cpp.

References cap.

◆ open() [4/4]

bool mx::MXCapture::open ( int id,
int mode = 0 )

Open a camera device.

Parameters
idCamera index.
modeBackend hint (0 = auto).
Returns
true on success.

◆ operator=() [1/4]

MXCapture & mx::MXCapture::operator= ( const MXCapture & )
delete

References MXCapture().

◆ operator=() [2/4]

MXCapture & mx::MXCapture::operator= ( const MXCapture & )
delete

References MXCapture().

◆ operator=() [3/4]

MXCapture & mx::MXCapture::operator= ( MXCapture && )
delete

References MXCapture().

◆ operator=() [4/4]

MXCapture & mx::MXCapture::operator= ( MXCapture && )
delete

References MXCapture().

◆ read() [1/4]

bool mx::MXCapture::read ( )

Grab and decode the next frame from the source.

Returns
true if a new frame was available.

Definition at line 56 of file gl_cv.cpp.

References cap, frame, and sprite.

◆ read() [2/4]

bool mx::MXCapture::read ( )

Capture and upload the next video frame.

Returns
true if a frame was available.

◆ read() [3/4]

bool mx::MXCapture::read ( cv::Mat & frame)

Grab and decode the next frame into a cv::Mat.

Parameters
frameOutput matrix.
Returns
true if a new frame was available.

Definition at line 52 of file gl_cv.cpp.

References cap, and frame.

◆ read() [4/4]

bool mx::MXCapture::read ( cv::Mat & frame)

Capture the next frame into a cv::Mat.

Parameters
frameOutput matrix.
Returns
true if a frame was available.

References frame.

◆ reload() [1/2]

bool mx::MXCapture::reload ( const std::string & vert,
const std::string & frag )

Replace the shader pair without reopening the source.

Parameters
vertNew vertex shader path.
fragNew fragment shader path.
Returns
true on success.

Definition at line 44 of file gl_cv.cpp.

References shader.

◆ reload() [2/2]

bool mx::MXCapture::reload ( size_t width,
size_t height,
const std::string & vert,
const std::string & frag )

Replace the vertex/fragment shaders.

Parameters
widthDisplay width.
heightDisplay height.
vertNew vertex shader path.
fragNew fragment shader path.
Returns
true on success.

Definition at line 40 of file vk_cv.cpp.

References sprite.

◆ set() [1/2]

void mx::MXCapture::set ( unsigned int option,
double value )

Set a VideoCapture property.

Parameters
optioncv::VideoCaptureProperties constant.
valueDesired value.

Definition at line 81 of file gl_cv.cpp.

References cap.

◆ set() [2/2]

void mx::MXCapture::set ( unsigned int option,
double value )

Set a VideoCapture property.

Parameters
optioncv::VideoCaptureProperties constant.
valueDesired value.

Member Data Documentation

◆ cap

cv::VideoCapture mx::MXCapture::cap
private

OpenCV capture device.

Definition at line 132 of file gl_cv.hpp.

Referenced by close(), get(), is_open(), open(), open(), read(), read(), and set().

◆ frame

cv::Mat mx::MXCapture::frame
private

Most recent decoded frame.

Definition at line 133 of file gl_cv.hpp.

Referenced by read(), and read().

◆ shader

std::unique_ptr<gl::ShaderProgram> mx::MXCapture::shader
private

Active shader program.

Definition at line 130 of file gl_cv.hpp.

Referenced by createImage(), and reload().

◆ sprite [1/2]

gl::GLSprite mx::MXCapture::sprite
private

Rendering sprite.

Definition at line 129 of file gl_cv.hpp.

Referenced by createImage(), createImage(), draw(), draw(), getSprite(), read(), and reload().

◆ sprite [2/2]

VKSprite* mx::MXCapture::sprite = nullptr
private

Backing Vulkan sprite.

Definition at line 130 of file vk_cv.hpp.

◆ window

gl::GLWindow* mx::MXCapture::window = nullptr
private

Parent GL window.

Definition at line 131 of file gl_cv.hpp.

Referenced by createImage(), createImage(), draw(), and draw().


The documentation for this class was generated from the following files: