Skip to content

Instantly share code, notes, and snippets.

@benjaminbojko
Created December 17, 2014 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminbojko/0bd9659b62f1bb181520 to your computer and use it in GitHub Desktop.
Save benjaminbojko/0bd9659b62f1bb181520 to your computer and use it in GitHub Desktop.
Display RTSP Stream in Cinder using OpenCV
#include "cinder/app/AppNative.h"
#include "cinder/gl/Texture.h"
#include "CinderOpenCV.h"
using namespace ci;
using namespace ci::app;
static std::string const VideoStreamAddress = "rtsp://user:pass@domain.com/path/to/stream";
class CinderOpenCV : public AppNative {
public:
void setup();
void update();
void draw();
protected:
cv::VideoCapture mVideoCapture;
cv::Mat mCurrentVideoFrame;
gl::Texture mTexture;
};
void CinderOpenCV::setup() {
if (!mVideoCapture.open(VideoStreamAddress)) {
console() << "couldn't open stream" << std::endl;
}
}
void CinderOpenCV::update() {
if (!mVideoCapture.read(mCurrentVideoFrame)) {
console() << "couldn't read current frame from video" << std::endl;
}
}
void CinderOpenCV::draw() {
gl::clear();
mTexture = gl::Texture(fromOcv(mCurrentVideoFrame));
if (!mTexture) {
console() << "couldn't load current frame into texture" << std::endl;
return;
}
gl::draw(mTexture, getWindowBounds());
}
CINDER_APP_NATIVE(CinderOpenCV, RendererGl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment