From 60b2973637d6150f3facb74eb9ae1d475071b915 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 22 Jan 2018 23:28:16 +0000 Subject: thresholding --- drawing/addons.make | 3 +- drawing/bin/data/lorenzo.svg | 201 +++++++++++++++++++++++-------------------- drawing/src/ofApp.cpp | 55 ++++++++++-- drawing/src/ofApp.h | 11 +++ 4 files changed, 173 insertions(+), 97 deletions(-) (limited to 'drawing') diff --git a/drawing/addons.make b/drawing/addons.make index f58784c..964322e 100644 --- a/drawing/addons.make +++ b/drawing/addons.make @@ -1,3 +1,4 @@ ofxSvg ofxClipper -ofxSyphon \ No newline at end of file +ofxSyphon +ofxOpenCV \ No newline at end of file diff --git a/drawing/bin/data/lorenzo.svg b/drawing/bin/data/lorenzo.svg index 193d208..1252cb3 100644 --- a/drawing/bin/data/lorenzo.svg +++ b/drawing/bin/data/lorenzo.svg @@ -1,41 +1,33 @@ - - image/svg+xml + + + + image/svg+xml + + lorenzo + + + + \ No newline at end of file + inkscape:window-maximized="0" + inkscape:current-layer="svg2" /> + + lorenzo + Created with Sketch. + + + + + + + + + + + + + + + + + + + + diff --git a/drawing/src/ofApp.cpp b/drawing/src/ofApp.cpp index 91daee1..8928df6 100644 --- a/drawing/src/ofApp.cpp +++ b/drawing/src/ofApp.cpp @@ -53,6 +53,12 @@ void ofApp::setup(){ mode=0; ofSetFrameRate(30); + + movie.load("clouds_flythrough.mp4"); + movie.setLoopState(OF_LOOP_NORMAL); + movie.play(); + + threshold=128; } //-------------------------------------------------------------- @@ -61,6 +67,8 @@ void ofApp::update(){ clipper.Clear(); clipper.addPolylines(mask, ClipperLib::ptClip); + + } ofPolyline ofApp::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){ @@ -83,6 +91,8 @@ void ofApp::draw(){ float phase=fmod(ofGetElapsedTimef()/2,1); + //movie.draw(0,0,ofGetWidth(),ofGetHeight()); + //transform points of segmenter before intersecting with mask switch (mode){ @@ -163,7 +173,12 @@ void ofApp::draw(){ break; } case 5:{ - vector clipped = clipper.getOffsets(maskpaths,(phase*20)+1,true); + //the N only fucks up when the other shapes are drawn! + vector clipped; + for (auto & maskpath:maskpaths){ + auto clips=clipper.getOffsets(maskpath,-((phase*20)+1),true); + clipped.insert(clipped.end(),clips.begin(),clips.end()); + } vector simplified = clipper.simplifyPolylines(clipped); @@ -177,11 +192,12 @@ void ofApp::draw(){ pointsdrawn+=clip.size(); } +/* float phase1=fmod(phase+0.5f,1.0f); clipped.clear(); - clipped = clipper.getOffsets(maskpaths,(phase1*20)+1,true); + clipped = clipper.getOffsets(maskpaths,-((phase*20)+1),true); simplified.clear(); @@ -197,7 +213,7 @@ void ofApp::draw(){ pointsdrawn+=clip.size(); } - +*/ break; } case 6:{ @@ -223,7 +239,28 @@ void ofApp::draw(){ break; } - case 7:{ + case 7: { + movie.update(); + if (movie.isFrameNew()){ + colorImg.setFromPixels(movie.getPixels()); + grayImage = colorImg; + grayImage.threshold(threshold); + contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true); + } + vector shapes; + for (int i = 0; i < contourFinder.nBlobs; i++){ + ofPolyline shape; + for (auto& point:contourFinder.blobs[i].pts){ + shape.addVertex(point); + } + shapes.push_back(shape); + segmentsdrawn++; + pointsdrawn+=shape.size(); + contourFinder.blobs[i].draw(0,0); + } + break; + } + case 8:{ int w=ofRandom(1000); segmenters[w%segmenters.size()].draw(); segmentsdrawn=1; @@ -284,7 +321,15 @@ void ofApp::keyReleased(int key){ break; } case 'p':{ - mode=(mode+1)%8; + mode=(mode+1)%9; + break; + } + case '-':{ + threshold=max(threshold-1,0); + break; + } + case '=':{ + threshold=min(threshold+1,255); break; } } diff --git a/drawing/src/ofApp.h b/drawing/src/ofApp.h index 4e8dc69..a6f03a6 100644 --- a/drawing/src/ofApp.h +++ b/drawing/src/ofApp.h @@ -5,6 +5,7 @@ #include "lineSegmenter.h" #include "ofxClipper.h" #include "ofxSyphon.h" +#include "ofxOpenCv.h" class ofApp : public ofBaseApp{ @@ -48,4 +49,14 @@ class ofApp : public ofBaseApp{ ofx::Clipper clipper; ofxSyphonServer mainOutputSyphonServer; + + ofVideoPlayer movie; + + ofxCvColorImage colorImg; + + ofxCvGrayscaleImage grayImage; + + ofxCvContourFinder contourFinder; + + int threshold; }; -- cgit v1.2.3