ofDocsdocumentation video ofVideoGrabber

ofVideoGrabber

The ofVideoGrabber class wraps QuickTime's sequence grabbing component to provide low level access to live cameras. On Microsoft Windows it now uses the DirectShow based videoInput library which offers mainy performance advantages over QuickTime and does not require QuickTime or WinVDig to be installed. A #define in ofConstants.h allows you to choose whether to use QuickTime or DirectShow (default) for Microsoft Windows. In Linux it uses by default unicap, although you can change to V4L through a #define in ofConstants in case some V4L devices don't work properly with unicap.


bind( )

void bind()

close( )

void close()

Closes the sequence grabber and de-allocates any allocated resources. Call this only when you want to stop the video grabber finally. See also initGrabber()


draw( ... )

void draw(float x, float y)

Draws the internal texture of the movie grabber class at the position (x,y) with the internal width and height of the movie grabber. It uses the native size of the grabber, so if you initialize the grabber at 320 x 240, it will draw a rectangle at x,y with a width and height of 320 x 240. Please note, ofSetRectMode() can have an effect on if the x,y is the top left corner or center point.


draw( ... )

void draw(float x, float y, float w, float h)

Draws the internal texture of the movie grabber class at the position (x,y) with the given width (w) and height (h). As the video grabber operates, it grabs pixel data and uploads it to it's internal texture (ie, on the GPU), unless you call setUseTexture(false), which disables the texture uploading. This draws that internal texture on screen.


getHeight( )

float getHeight()

Returns the height of the video grabber object. If you initialize the object at 320x240, it will return 240;


getPixelFormat( )

ofPixelFormat getPixelFormat()

Returns the height of the video grabber object. If you initialize the object at 320x240, it will return 240;


getPixels( )

ofPixels & getPixels()

Returns the pointer to the array of pixels that represents the current frame of live video. the data is stored interleaved as RGB, and in an array which is the size: widthheight3. This function returns a pointer to an unsigned char array -- it's up to the user to deal with this memory correctly. Functions like getWidth() and getHeight() can help.


getPixels( )

const ofPixels & getPixels()

getTexture( )

ofTexture & getTexture()

getTexture( )

const ofTexture & getTexture()

getTexturePlanes( )

int & getTexturePlanes()

getTexturePlanes( )

const int & getTexturePlanes()

getWidth( )

float getWidth()

Returns the width of the video grabber object. If you initialize the object at 320x240, it will return 320.


initGrabber( ... )

bool initGrabber(int w, int h)

Initializes either the default capture device or the capture device specified by setDeviceID. Attempts to setup capture at the width and height specified. If the capture dimensions are not available it will setup capture for the next closest dimensions available. It is good to check what the actual size is before you start processing the pixels.


myGrabber.setVerbose(true);
myGrabber.setDeviceID(1);
myGrabber.initGrabber(320,240);
int grabW = myGrabber.getWidth();
int grabH = myGrabber.getHeight();
printf("asked for 320 by 240 - actual size is %i by %i", grabW, grabH);

isFrameNew( )

bool isFrameNew()

This function can be called after calling ofImage::update() (or alternatively, ofImage::ofIdleGrabber()) to figure out if a frame is new, ie. if there is a new pixel data. This is typically because your main frame rate might not be in sync with the video grabber, and you can skip processing on frames where there is no new data.


void testApp::update(){

	grabber.update();  // call this once per update
	if (grabber.isFrameNew()){
		; // do computer vision / process the pixels
	}

}


isInitialized( )

bool isInitialized()

Returns a boolean if the video grabber is properly initialized.


isUsingTexture( )

bool isUsingTexture()

listDevices( )

int listDevices()

Prints to the console a list of available capture devices with the device ID of each device. The device ID can then be used with setDeviceID() to specify a specific device to capture from. This is especially useful if you have multiple devices, or want to see what kind of cameras openframeworks sees.


ofVideoGrabber( )

ofVideoGrabber()

Initializes the video grabber. This function doesn't really do any real allocation, which happens in ofVideoGrabber::initGrabber(). In openframeworks we typically use empty constructors so that objects can be defined in h files, ie, you don't need to do dynamic allocation or use pointers as much in your code.


resetAnchor( )

void resetAnchor()

This removes any anchor positioning, meaning that the ofVideoGrabber will be draw with the upper left hand corner at the point passed into draw().


setAnchorPercent( ... )

void setAnchorPercent(float xPct, float yPct)

Adjusts ofVideoGrabbers anchor for more drawing control. See ofImage::setAnchorPercent() for info.


setAnchorPoint( ... )

void setAnchorPoint(float x, float y)

Adjusts ofVideoGrabbers anchor for more drawing control. See ofImage::setAnchorPoint(x,y) for info.


setDesiredFrameRate( ... )

void setDesiredFrameRate(int framerate)

Set's the desired frame rate of the grabber. This should be called before initGrabber(), which will try to initialize at the desired frame rate. Not all frame rates will be supported, but this at least gives you some abilitity to try grab at different rates.


setDeviceID( ... )

void setDeviceID(int _deviceID)

Choose to capture from a specific capture device specified by _deviceID. Use listDevices() to see a list of available capture devices and their device IDs. This should be called before initGrabber(), which will use this info to choose the device you want.


setPixelFormat( ... )

bool setPixelFormat(ofPixelFormat pixelFormat)

Some video grabbers allow you to adjust the pixel format, which might help for optimization. At the moment, this seems to only apply to the Linux video grabber (GST). For all other grabbers, the only format accepted is OF_PIXELS_RGB.


setUseTexture( ... )

void setUseTexture(bool bUse)

Set the usage of texture inside this object. Typically, you will want to draw the movie grabber on screen, and so it will be necessary to use a texture, but there may be cases where it helps to not use a texture in order to save memory or for better performance. To disable the internal use of the texture, you can initialize the sequence grabber like this:


myGrabber.setUseTexture(false);
myGrabber.initGrabber(320,240);

setVerbose( ... )

void setVerbose(bool bTalkToMe)

Sets the verbosity - this can be useful for debugging the video grabber interface. you can set the verbosity and then try initGrabber();

From 0.06 this method has no effect. Use ofSetLogLevel(OF_LOG_VERBOSE) to enable verbose messages.


myGrabber.setVerbose(true);
myGrabber.initGrabber(320,240);

setup( ... )

bool setup(int w, int h)

setup( ... )

bool setup(int w, int h, bool bTexture)

unbind( )

void unbind()

update( )

void update()

Calls grabframe function.


videoSettings( )

void videoSettings()

Loads the video settings on screen. If your OpenGL application is full screen, this window might appear underneath the main window the first time you call this. Note: in QTKit grabbers (10.7+), this video settings panel is not available.


~ofVideoGrabber( )

~ofVideoGrabber()

Destructor for the video grabber, will release any allocated memory.