Skip to content

Instantly share code, notes, and snippets.

@bakercp
Last active November 20, 2015 20:03
Show Gist options
  • Save bakercp/409b8cc6f2f226672cbd to your computer and use it in GitHub Desktop.
Save bakercp/409b8cc6f2f226672cbd to your computer and use it in GitHub Desktop.
VideoBuffer
ofVideoGrabber grabber;
ofPixels filteredPixels;
ofTexture filteredTexture;
std::vector<ofTexture> buffer;
int numFramesInBuffer;
ofEasyCam cam;
void setup() {
ofEnableDepthTest();
ofSetWindowShape(1280, 720);
grabber.initGrabber(1280, 720);
filteredPixels.allocate(1280, 720, OF_IMAGE_COLOR_ALPHA);
filteredTexture.allocate(1280, 720, OF_IMAGE_COLOR_ALPHA);
numFramesInBuffer = 30;
}
void update() {
grabber.update();
if (grabber.isFrameNew())
{
ofPixels& grabberPixels = grabber.getPixelsRef();
ofTexture tex;
tex.loadData(grabberPixels);
buffer.push_back(tex);
while (buffer.size() > numFramesInBuffer)
{
buffer.erase(buffer.begin());
}
// filteredPixels.clear();
// ofPixels& grabberPixels = grabber.getPixelsRef();
// for (int x = 0; x < grabber.getWidth(); x++)
// {
// for (int y = 0; y < grabber.getHeight(); y++)
// {
// ofColor grabberPixelColor = grabberPixels.getColor(x, y);
// if (grabberPixelColor.getBrightness() > 127)
// {
// filteredPixels.setColor(x, y, grabberPixelColor);
// }
// }
// }
// filteredTexture.loadData(grabberPixels);
}
}
void draw() {
cam.begin();
ofPushMatrix();
ofTranslate(-grabber.getWidth() / 2, -grabber.getHeight() / 2);
// grabber.draw(0, 0);
for (int i = 0; i < buffer.size(); i++)
{
buffer[i].draw(0, 0, i * 100);
}
ofPopMatrix();
cam.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment