Import a picture from cam to ofImage when using a separate thread.

threadedCam.h:

#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

Tested with openFrameworks 0.8.0

Reference

Date: 2013-08-17 | Tags: openFrameworks, Video