Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created November 11, 2019 02:30
Show Gist options
  • Save dasl-/9174d009d524aca686670c85e56c6f30 to your computer and use it in GitHub Desktop.
Save dasl-/9174d009d524aca686670c85e56c6f30 to your computer and use it in GitHub Desktop.
#include "ofApp.h"
void ofApp::setup(){
ofDisableArbTex();
ofEnableSmoothing();
ofEnableAlphaBlending();
_video.initGrabber(640, 480);
_currentFilter = 0;
int myWidth = ofGetWindowWidth();//_video.getWidth();;
int myHeight = ofGetWindowHeight();//_video.getHeight();
// here's a simple filter chain
FilterChain * charcoal = new FilterChain(myWidth, myHeight, "Charcoal");
//charcoal->addFilter(new BilateralFilter(myWidth, myHeight, 4, 4));
charcoal->addFilter(new GaussianBlurFilter(myWidth, myHeight, 2.f ));
charcoal->addFilter(new DoGFilter(myWidth, myHeight, 12, 1.2, 8, 0.99, 4));
_filters.push_back(charcoal);
// FilterChain * green = new FilterChain(myWidth, myHeight, "green");
// green->addFilter(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
// _filters.push_back(green);
//
// FilterChain * dark_green = new FilterChain(myWidth, myHeight, "dark_green");
// dark_green->addFilter(new LookupFilter(myWidth, myHeight, "img/dark_green_lut.png"));
// _filters.push_back(dark_green);
FilterChain * amatorka_green = new FilterChain(myWidth, myHeight, "amatorka_green");
amatorka_green->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_amatorka.png"));
amatorka_green->addFilter(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
_filters.push_back(amatorka_green);
// FilterChain * green_amatorka = new FilterChain(myWidth, myHeight, "green_amatorka");
// green_amatorka->addFilter(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
// green_amatorka->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_amatorka.png"));
// _filters.push_back(green_amatorka);
//
// FilterChain * amatorka_dark_green = new FilterChain(myWidth, myHeight, "amatorka_dark_green");
// amatorka_dark_green->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_amatorka.png"));
// amatorka_dark_green->addFilter(new LookupFilter(myWidth, myHeight, "img/dark_green_lut.png"));
// _filters.push_back(amatorka_dark_green);
//
// FilterChain * dark_green_amatorka = new FilterChain(myWidth, myHeight, "dark_green_amatorka");
// dark_green_amatorka->addFilter(new LookupFilter(myWidth, myHeight, "img/dark_green_lut.png"));
// dark_green_amatorka->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_amatorka.png"));
// _filters.push_back(dark_green_amatorka);
// Basic filter examples
FilterChain * elegance_green = new FilterChain(myWidth, myHeight, "elegance_green");
elegance_green->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_soft_elegance_1.png"));
elegance_green->addFilter(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
_filters.push_back(elegance_green);
// FilterChain * green_elegance = new FilterChain(myWidth, myHeight, "green_elegance");
// green_elegance->addFilter(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
// green_elegance->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_soft_elegance_1.png"));
// _filters.push_back(green_elegance);
//
// FilterChain * elegance_dark_green = new FilterChain(myWidth, myHeight, "elegance_dark_green");
// elegance_dark_green->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_soft_elegance_1.png"));
// elegance_dark_green->addFilter(new LookupFilter(myWidth, myHeight, "img/dark_green_lut.png"));
// _filters.push_back(elegance_dark_green);
//
// FilterChain * dark_green_elegance = new FilterChain(myWidth, myHeight, "dark_green_elegance");
// dark_green_elegance->addFilter(new LookupFilter(myWidth, myHeight, "img/dark_green_lut.png"));
// dark_green_elegance->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_soft_elegance_1.png"));
// _filters.push_back(dark_green_elegance);
_filters.push_back(new HalftoneFilter(myWidth, myHeight, 0.01));
_filters.push_back(new CrosshatchFilter(myWidth, myHeight));
_filters.push_back(new KuwaharaFilter(6));
_filters.push_back(new SobelEdgeDetectionFilter(myWidth, myHeight));
_filters.push_back(new BilateralFilter(myWidth, myHeight));
_filters.push_back(new SketchFilter(myWidth, myHeight));
_filters.push_back(new DilationFilter(myWidth, myHeight));
_filters.push_back(new PerlinPixellationFilter(myWidth, myHeight));
_filters.push_back(new XYDerivativeFilter(myWidth, myHeight));
_filters.push_back(new ZoomBlurFilter());
_filters.push_back(new EmbossFilter(myWidth, myHeight, 2.f));
_filters.push_back(new SmoothToonFilter(myWidth, myHeight));
_filters.push_back(new TiltShiftFilter(_video.getTextureReference()));
_filters.push_back(new VoronoiFilter(_video.getTextureReference()));
_filters.push_back(new CGAColorspaceFilter());
_filters.push_back(new ErosionFilter(myWidth, myHeight));
_filters.push_back(new LookupFilter(myWidth, myHeight, "img/lookup_amatorka.png"));
_filters.push_back(new LookupFilter(myWidth, myHeight, "img/lookup_miss_etikate.png"));
_filters.push_back(new LookupFilter(myWidth, myHeight, "img/lookup_soft_elegance_1.png"));
_filters.push_back(new LookupFilter(myWidth, myHeight, "img/green_lut.png"));
_filters.push_back(new VignetteFilter());
_filters.push_back(new PosterizeFilter(8));
_filters.push_back(new LaplacianFilter(myWidth, myHeight, ofVec2f(1, 1)));
_filters.push_back(new PixelateFilter(myWidth, myHeight));
_filters.push_back(new HarrisCornerDetectionFilter(_video.getTextureReference()));
_filters.push_back(new MotionDetectionFilter(_video.getTextureReference()));
_filters.push_back(new LowPassFilter(myWidth, myHeight, 0.9));
// blending examples
ofImage wes = ofImage("img/wes.jpg");
ChromaKeyBlendFilter * chroma = new ChromaKeyBlendFilter(ofVec3f(0.f, 1.f, 0.f), 0.4);
chroma->setSecondTexture(wes.getTextureReference());
_filters.push_back(chroma);
_filters.push_back(new DisplacementFilter("img/mandel.jpg", myWidth, myHeight, 25.f));
_filters.push_back(new PoissonBlendFilter(wes.getTextureReference(), myWidth, myHeight, 2.0));
_filters.push_back(new DisplacementFilter("img/glass/3.jpg", myWidth, myHeight, 40.0));
_filters.push_back(new ExclusionBlendFilter(wes.getTextureReference()));
// here's how you use Convolution filters
Abstract3x3ConvolutionFilter * convolutionFilter1 = new Abstract3x3ConvolutionFilter(myWidth, myHeight);
convolutionFilter1->setMatrix(-1, 0, 1, -2, 0, 2, -1, 0, 1);
_filters.push_back(convolutionFilter1);
Abstract3x3ConvolutionFilter * convolutionFilter2 = new Abstract3x3ConvolutionFilter(myWidth, myHeight);
convolutionFilter2->setMatrix(4, 4, 4, 4, -32, 4, 4, 4, 4);
_filters.push_back(convolutionFilter2);
Abstract3x3ConvolutionFilter * convolutionFilter3 = new Abstract3x3ConvolutionFilter(myWidth, myHeight);
convolutionFilter3->setMatrix(1.2, 1.2, 1.2, 1.2, -9.0, 1.2, 1.2, 1.2, 1.2);
_filters.push_back(convolutionFilter3);
// and here's how you might daisy-chain a bunch of filters
FilterChain * foggyTexturedGlassChain = new FilterChain(myWidth, myHeight, "Weird Glass");
foggyTexturedGlassChain->addFilter(new PerlinPixellationFilter(myWidth, myHeight, 13.f));
foggyTexturedGlassChain->addFilter(new EmbossFilter(myWidth, myHeight, 0.5));
foggyTexturedGlassChain->addFilter(new GaussianBlurFilter(myWidth, myHeight, 3.f));
_filters.push_back(foggyTexturedGlassChain);
// here's another unimaginative filter chain
FilterChain * watercolorChain = new FilterChain(myWidth, myHeight, "Monet");
watercolorChain->addFilter(new KuwaharaFilter(9));
watercolorChain->addFilter(new LookupFilter(myWidth, myHeight, "img/lookup_miss_etikate.png"));
watercolorChain->addFilter(new BilateralFilter(myWidth, myHeight));
watercolorChain->addFilter(new PoissonBlendFilter("img/canvas_texture.jpg", myWidth, myHeight, 2.0));
watercolorChain->addFilter(new VignetteFilter());
_filters.push_back(watercolorChain);
// and here's a random gradient map for posterity
vector<GradientMapColorPoint> colors;
for (float percent=0.0; percent<=1.0; percent+= 0.1)
colors.push_back( GradientMapColorPoint(ofRandomuf(),ofRandomuf(),ofRandomuf(),percent) );
_filters.push_back(new GradientMapFilter(colors));
}
void ofApp::update(){
_video.update();
}
void ofApp::draw(){
ofBackground(0, 0, 0);
ofSetColor(255);
ofPushMatrix();
ofScale(-1, 1);
ofTranslate(-ofGetWindowWidth(), 0);
_filters[_currentFilter]->begin();
_video.draw(0,0,ofGetWidth(), ofGetHeight());
_filters[_currentFilter]->end();
ofPopMatrix();
ofSetColor(255);
ofDrawBitmapString( _filters[_currentFilter]->getName() + " Filter\n(press SPACE to change filters)", ofPoint(40, 20));
}
void ofApp::keyPressed(int key){
if (key==' ') {
_currentFilter ++;
if (_currentFilter>=_filters.size()) _currentFilter = 0;
} else if (key == 'b') {
_currentFilter--;
if (_currentFilter < 0) {
_currentFilter = _filters.size() - 1;
}
}
else if (key=='f') ofToggleFullscreen();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment