Skip to content

Instantly share code, notes, and snippets.

@madc
Created August 17, 2013 14:30
Show Gist options
  • Save madc/6257141 to your computer and use it in GitHub Desktop.
Save madc/6257141 to your computer and use it in GitHub Desktop.
Import a picture from cam to ofImage when using a separate thread. (openFrameworks) Example: http://github.com/wirbrennen/ofxDocuApp
#ifndef _THREADED_CAM
#define _THREADED_CAM
#include "ofMain.h"
class threadedCam : public ofThread{
public:
ofVideoGrabber vidGrabber;
ofImage exportImage;
void start(){
vidGrabber.initGrabber(1280, 720, false);
exportImage.setUseTexture(false);
startThread(true, false);
}
void stop(){
stopThread();
vidGrabber.close();
}
void threadedFunction(){
while( isThreadRunning() != 0 ){
vidGrabber.update();
if (vidGrabber.isFrameNew()){
exportImage.setFromPixels(vidGrabber.getPixelsRef());
// Do something, like saving the picture:
exportImage.saveImage(ofGetTimestampString() + ".tiff");
}
}
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment