12 return cap.open(filename);
18 if(
cap.open(
id, mode)) {
19 cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc(
'M',
'J',
'P',
'G'));
31 if(!
shader->loadProgram(vert, frag)) {
32 throw mx::Exception(
">> MXCapture: Could not load shader.\n");
37 cv::Mat mat = cv::Mat::zeros(width, height, CV_8UC4);
39 sprite.initWithTexture(
shader.get(), texture, 0.0f, 0.0f,
40 static_cast<int>(width),
static_cast<int>(height));
46 if(!
shader->loadProgram(vert, frag)) {
47 throw mx::Exception(
">> MXCapture: could not load shader: " + vert +
"/" + frag);
61 cv::cvtColor(
frame, rgba, cv::COLOR_BGR2RGBA);
62 cv::flip(rgba, rgba, 0);
63 sprite.updateTexture(rgba.ptr(),rgba.cols, rgba.rows);
71 sprite.draw(x, y, width, height);
82 cap.set(option, value);
86 return cap.get(option);
SDL2 + OpenGL/ES window with event loop and console support.
GLSL shader program wrapper (shared-ownership).
General-purpose exception class for the mx library.
void close()
Close the video source.
double get(unsigned int option)
Query a VideoCapture property.
void set(unsigned int option, double value)
Set a VideoCapture property.
bool reload(const std::string &vert, const std::string &frag)
Replace the shader pair without reopening the source.
bool open(const std::string &filename)
Open a video file for capture.
cv::Mat frame
Most recent decoded frame.
gl::GLWindow * window
Parent GL window.
void draw(int x, int y, int width, int height)
Draw the most recently captured frame.
cv::VideoCapture cap
OpenCV capture device.
gl::GLSprite sprite
Rendering sprite.
std::unique_ptr< gl::ShaderProgram > shader
Active shader program.
bool read()
Grab and decode the next frame from the source.
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.
OpenCV video-capture integration for the OpenGL backend.
GLuint createTexture(SDL_Surface *surface, bool flip)
Create a new GL texture from an SDL_Surface.