Skip to content

Instantly share code, notes, and snippets.

@dongalor
Forked from kylemcdonald/CameraImage.cpp
Created November 28, 2015 09:36
Show Gist options
  • Save dongalor/c3e8e0275d13f97b3235 to your computer and use it in GitHub Desktop.
Save dongalor/c3e8e0275d13f97b3235 to your computer and use it in GitHub Desktop.
openFrameworks app for sending images to disk for processing, and reading text back from disk. Used for "NeuralTalk and Walk".
#include "ofMain.h"
#include "ofxTiming.h"
class ofApp : public ofBaseApp {
public:
ofVideoGrabber grabber;
DelayTimer delay;
ofTrueTypeFont font;
string description;
void setup(){
ofBackground(0);
ofSetFrameRate(60);
grabber.setup(1280, 720);
delay.setFramerate(4);
font.load("Avenir Light", 64);
}
void update(){
grabber.update();
if(delay.tick()) {
ofPixels frame = grabber.getPixels();
frame.resize(640, 360);
ofSaveImage(frame, "feed.jpg");
description = ofBufferFromFile("../description.txt").getText();
}
}
void draw(){
ofPushMatrix();
ofTranslate(ofGetWidth() / 2, 0);
float scale = ofGetHeight() / grabber.getHeight();
ofScale(scale, scale);
ofTranslate(-grabber.getWidth() / 2, 0);
grabber.draw(0, 0);
ofPopMatrix();
ofPushStyle();
float padding = 16;
ofTranslate(padding, 2 * padding + 64);
ofSetColor(0, 128);
ofRectangle box = font.getStringBoundingBox(description, 0, 0);
box.width += padding * 2;
box.height += padding * 2;
ofDrawRectangle(box);
ofSetColor(255);
font.drawString(description, padding, padding);
ofPopStyle();
}
void keyPressed(int key){
if(key == 'f') {
ofToggleFullscreen();
}
}
};
int main( ){
ofSetupOpenGL(1280,720,OF_WINDOW);
ofRunApp(new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment