Created
December 17, 2014 23:32
-
-
Save benjaminbojko/0bd9659b62f1bb181520 to your computer and use it in GitHub Desktop.
Display RTSP Stream in Cinder using OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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:[email protected]/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