Created
September 23, 2020 08:18
-
-
Save eighteight/ed7d68f480cc433c94a6950b4ee63a69 to your computer and use it in GitHub Desktop.
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/App.h" | |
#include "cinder/app/RendererGl.h" | |
#include "cinder/gl/gl.h" | |
#include "cinder/Capture.h" | |
#include "CinderOpenCV.h" | |
using namespace ci; | |
using namespace ci::app; | |
static std::string const VideoStreamAddress = "rtsp://192.168.1.188/live/live"; | |
class ocvCaptureApp : public App { | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
CaptureRef mCapture; | |
gl::TextureRef mTexture; | |
protected: | |
cv::VideoCapture mVideoCapture; | |
cv::Mat mCurrentVideoFrame; | |
}; | |
void ocvCaptureApp::setup() | |
{ | |
// try { | |
// mCapture = Capture::create( 640, 480 ); | |
// mCapture->start(); | |
// } | |
// catch( ... ) { | |
// console() << "Failed to initialize capture" << std::endl; | |
// } | |
try { | |
if (!mVideoCapture.open(VideoStreamAddress)) { | |
console() << "couldn't open stream" << std::endl; | |
} | |
} | |
catch( ... ) { | |
console() << "Failed to initialize capture" << std::endl; | |
} | |
} | |
void ocvCaptureApp::update() | |
{ | |
if( mCapture && mCapture->checkNewFrame() ) { | |
cv::Mat input( toOcv( *mCapture->getSurface() ) ), output; | |
cv::Sobel( input, output, CV_8U, 1, 0 ); | |
// cv::threshold( input, output, 128, 255, CV_8U ); | |
// cv::Laplacian( input, output, CV_8U ); | |
// cv::circle( output, toOcv( Vec2f(200, 200) ), 300, toOcv( Color( 0, 0.5f, 1 ) ), -1 ); | |
// cv::line( output, cv::Point( 1, 1 ), cv::Point( 30, 30 ), toOcv( Color( 1, 0.5f, 0 ) ) ); | |
mTexture = gl::Texture::create( fromOcv( output ), gl::Texture::Format().loadTopDown() ); | |
} | |
} | |
void ocvCaptureApp::draw() | |
{ | |
gl::clear(); | |
if( mTexture ) | |
gl::draw( mTexture ); | |
} | |
CINDER_APP( ocvCaptureApp, RendererGl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment