diff options
Diffstat (limited to 'glitcher')
| -rw-r--r-- | glitcher/Makefile | 13 | ||||
| -rw-r--r-- | glitcher/addons.make | 2 | ||||
| -rw-r--r-- | glitcher/config.make | 1 | ||||
| -rw-r--r-- | glitcher/src/main.cpp | 6 | ||||
| -rw-r--r-- | glitcher/src/ofApp.cpp | 154 | ||||
| -rw-r--r-- | glitcher/src/ofApp.h | 24 |
6 files changed, 200 insertions, 0 deletions
diff --git a/glitcher/Makefile b/glitcher/Makefile new file mode 100644 index 0000000..7a7fe8b --- /dev/null +++ b/glitcher/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../.. +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/glitcher/addons.make b/glitcher/addons.make new file mode 100644 index 0000000..ab4486b --- /dev/null +++ b/glitcher/addons.make @@ -0,0 +1,2 @@ +ofxKinect +ofxOpenCv diff --git a/glitcher/config.make b/glitcher/config.make new file mode 100644 index 0000000..98bb09c --- /dev/null +++ b/glitcher/config.make @@ -0,0 +1 @@ +OF_ROOT=../../openFrameworks diff --git a/glitcher/src/main.cpp b/glitcher/src/main.cpp new file mode 100644 index 0000000..d134fc9 --- /dev/null +++ b/glitcher/src/main.cpp @@ -0,0 +1,6 @@ +#include "ofApp.h" + +int main() { + ofSetupOpenGL(1024, 768, OF_WINDOW); + ofRunApp(new ofApp()); +} diff --git a/glitcher/src/ofApp.cpp b/glitcher/src/ofApp.cpp new file mode 100644 index 0000000..6055485 --- /dev/null +++ b/glitcher/src/ofApp.cpp @@ -0,0 +1,154 @@ +#include "ofApp.h" + + +//-------------------------------------------------------------- +void ofApp::setup() { + ofSetLogLevel(OF_LOG_WARNING); + + ofSetFrameRate(60); + + buffer.allocate(ofGetWidth(),ofGetHeight()); + renderFBO.allocate(ofGetWidth(),ofGetHeight(),GL_RGB); + //buffer.clear(); +} + +//-------------------------------------------------------------- +void ofApp::update() { + ofSetWindowTitle(ofToString(ofGetFrameRate())); +} + +//-------------------------------------------------------------- +void ofApp::draw() { + + //rough out how it could be possible to perform an avs style glitch transform + //within a drawing + //drawing- to an fbo + //distorting- from an opencv texture + //how to get from an fbo to an opencv texture + ofSetColor(255, 255, 255); + + renderFBO.begin(); + buffer.draw(0,0); + + + ofNoFill(); + ofTranslate(ofGetWidth()/2,ofGetHeight()/2); + ofRect(-20,-20,40,40); + renderFBO.end(); + renderFBO.readToPixels(buffer.getPixelsRef()); + buffer.flagImageChanged(); + + cv::Mat buf = buffer.getCvImage(); + cv::Mat dstbuf; + + //create low res remap target + + cv::Mat dstX(32,24,CV_32FC1); + cv::Mat dstY(32,24,CV_32FC1); + cv::Mat srcX(32,24,CV_32FC1); + cv::Mat srcY(32,24,CV_32FC1); + + float xFactor=ofGetWidth()/dstX.rows; + float yFactor=ofGetHeight()/dstX.cols; + for (int i=0;i<dstX.cols;i++){ + for (int j=0;j<dstX.rows;j++){ + dstX.at<double>(i,j)=i*xFactor; + dstY.at<double>(i,j)=j*yFactor; + } + } + + //transform the low res matrix + float tX=0; //fraction of image + float tY=0; //fraction of image + float oX=0; //fraction of image + float oY=0; //fraction of image + float s=0.99; + float r=0.0; + + cv::Point2f srcTri[3], dstTri[3]; + cv::Mat rot_mat(2,3,CV_32FC1); + cv::Mat trans_mat(2,3,CV_32FC1); + cv::Mat out_mat(3,3,CV_32FC1); + + // Compute matrix by creating triangle and transforming + srcTri[0].x=0; + srcTri[0].y=0; + srcTri[1].x=dstX.rows-1; + srcTri[1].y=0; + srcTri[2].x=0; + srcTri[2].y=dstX.cols-1; + for (int i=0;i<3;i++){ + dstTri[i].x=srcTri[i].x+(tX*dstX.cols); + dstTri[i].y=srcTri[i].y+(tY*dstX.cols); //use cols for equiv coords + //rotate and scale around centre + //transform to centre + dstTri[i].x-=(oX*dstX.cols); + dstTri[i].y-=(oY*dstX.cols); + + dstTri[i].x*=s; + dstTri[i].y*=s; + + double dx=(dstTri[i].x*cos(r))-(dstTri[i].y*sin(r)); + double dy=(dstTri[i].x*sin(r))+(dstTri[i].y*cos(r)); + + dstTri[i].x=dx; + dstTri[i].y=dy; + + //transform back + dstTri[i].x+=(oX*dstX.cols); + dstTri[i].y+=(oY*dstX.cols); + } + trans_mat=getAffineTransform( srcTri, dstTri ); + warpAffine( srcX, dstX, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); + warpAffine( srcY, dstY, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); + + cv::Mat scaledstX; + cv::Mat scaledstY; + + cv::resize(dstX,scaledstX, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); + cv::resize(dstY,scaledstY, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); + + cv::remap(buf,dstbuf,scaledstX,scaledstY, cv::INTER_LINEAR, cv::BORDER_WRAP, cv::Scalar(0,0, 0) ); + IplImage *tmp = new IplImage(dstbuf); + + buffer=tmp; + delete tmp; + + renderFBO.draw(0,0); //eventually textured into a viewport + +} + + + +//-------------------------------------------------------------- +void ofApp::exit() { + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed (int key) { + switch (key) { + + case OF_KEY_UP: + break; + + case OF_KEY_DOWN: + break; + } +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button) +{} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button) +{} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button) +{} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h) +{} diff --git a/glitcher/src/ofApp.h b/glitcher/src/ofApp.h new file mode 100644 index 0000000..fd72e87 --- /dev/null +++ b/glitcher/src/ofApp.h @@ -0,0 +1,24 @@ +#pragma once + +#include "ofMain.h" +#include "ofxOpenCv.h" + + +class ofApp : public ofBaseApp { +public: + + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed(int key); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + + ofxCvColorImage buffer; + + ofFbo renderFBO; +}; |
