Capturing from the camera
In this recipe we will learn how to capture and display frames from a camera.
Getting ready
Include the necessary files to capture images from a camera and draw them to OpenGL textures:
#include "cinder/gl/gl.h" #include "cinder/gl/Texture.h" #include "cinder/Capture.h"
Also add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
How to do it…
We will now capture and draw frames from the camera.
Declare the following members in your application class:
Capture mCamera; gl::Texture mTexture;
In the
setup
method we will initializemCamera
:try{ mCamera = Capture( 640, 480 ); mCamera.start(); } catch( ... ){ console() << "Could not initialize the capture" << endl;
In the
update
method, we will check ifmCamera
was successfully initialized. Also if there is any new frame available, copy the camera's image intomTexture
:if( mCamera ){ if( mCamera.checkNewFrame() ){ ...