class methods
- bind()
- close()
- draw()
- getGrabber()
- getHeight()
- getPixelFormat()
- getPixels()
- getTexture()
- getTexturePlanes()
- getWidth()
- initGrabber()
- isFrameNew()
- isInitialized()
- isUsingTexture()
- listDevices()
- setAnchorPoint()
- setDesiredFrameRate()
- setDeviceID()
- setGrabber()
- setPixelFormat()
- setUseTexture()
- setVerbose()
- setup()
- unbind()
- update()
- videoSettings()
Extends
This class extends others, you can call their methods on an instance of ofVideoGrabber too:
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.
close()
void ofVideoGrabber::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 ofVideoGrabber::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 ofVideoGrabber::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.
getGrabber()
shared_ptr< ofBaseVideoGrabber > ofVideoGrabber::getGrabber()
getGrabber returns a pointer (ofPtr) to the internally running video grabber. Since the ofVideoGrabber object has different potential systems for grabbing (QuickTime, QTKit, DirectShow), this ptr gives you access to the underlying video grabber that's running inside of ofVideoGrabber. Note: use this only if you need low level access to an internal grabbing object, such as to call a specific function.
getHeight()
float ofVideoGrabber::getHeight()
Returns the height of the video grabber object. If you initialize the object at 320x240, it will return 240;
getPixelFormat()
ofPixelFormat ofVideoGrabber::getPixelFormat()
Returns the height of the video grabber object. If you initialize the object at 320x240, it will return 240;
getPixels()
ofPixels & ofVideoGrabber::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.
getWidth()
float ofVideoGrabber::getWidth()
Returns the width of the video grabber object. If you initialize the object at 320x240, it will return 320.
initGrabber(...)
bool ofVideoGrabber::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 ofVideoGrabber::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 ofVideoGrabber::isInitialized()
Returns a boolean if the video grabber is properly initialized.
listDevices()
int ofVideoGrabber::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.
setAnchorPoint(...)
void ofVideoGrabber::setAnchorPoint(float x, float y)
Adjusts ofVideoGrabbers anchor for more drawing control. See ofImage::setAnchorPoint(x,y) for info.
setDesiredFrameRate(...)
void ofVideoGrabber::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 ofVideoGrabber::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.
setGrabber(...)
void ofVideoGrabber::setGrabber(shared_ptr< ofBaseVideoGrabber > newGrabber)
This function, similar to getGrabber, allows for low level access to the internal grabber object. This is useful if you want to adjust the internal grabber that ofVideoGrabber is using.
setPixelFormat(...)
bool ofVideoGrabber::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 ofVideoGrabber::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 ofVideoGrabber::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);
videoSettings()
void ofVideoGrabber::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.
Last updated Saturday, 17 August 2024 20:46:48 UTC - 99bfb4fd7929e233b87b05758efc36f91505592e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue