diff options
Diffstat (limited to 'tshirtmapping')
| -rwxr-xr-x | tshirtmapping/Makefile | 2 | ||||
| -rwxr-xr-x | tshirtmapping/addons.make | 1 | ||||
| -rwxr-xr-x | tshirtmapping/config.make | 56 | ||||
| -rwxr-xr-x | tshirtmapping/src/main.cpp | 16 | ||||
| -rwxr-xr-x | tshirtmapping/src/testApp.cpp | 291 | ||||
| -rwxr-xr-x | tshirtmapping/src/testApp.h | 45 | ||||
| -rwxr-xr-x | tshirtmapping/tshirtmapping.cbp | 78 | ||||
| -rwxr-xr-x | tshirtmapping/tshirtmapping.layout | 22 | ||||
| -rwxr-xr-x | tshirtmapping/tshirtmapping.workspace | 9 |
9 files changed, 520 insertions, 0 deletions
diff --git a/tshirtmapping/Makefile b/tshirtmapping/Makefile new file mode 100755 index 0000000..2d83a77 --- /dev/null +++ b/tshirtmapping/Makefile @@ -0,0 +1,2 @@ +include config.make +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples diff --git a/tshirtmapping/addons.make b/tshirtmapping/addons.make new file mode 100755 index 0000000..514ac62 --- /dev/null +++ b/tshirtmapping/addons.make @@ -0,0 +1 @@ +ofxOpenNI diff --git a/tshirtmapping/config.make b/tshirtmapping/config.make new file mode 100755 index 0000000..821a73a --- /dev/null +++ b/tshirtmapping/config.make @@ -0,0 +1,56 @@ +# add custom variables to this file + +# OF_ROOT allows to move projects outside apps/* just set this variable to the +# absoulte path to the OF root folder + +OF_ROOT = ../../openFrameworks + + +# USER_CFLAGS allows to pass custom flags to the compiler +# for example search paths like: +# USER_CFLAGS = -I src/objects + +USER_CFLAGS = -I $(OF_ROOT)/addons/ofxOpenNI/include/openni -I $(OF_ROOT)/addons/ofxOpenNI/include/nite -I $(OF_ROOT)/addons/ofxOpenNI/src + + +# USER_LDFLAGS allows to pass custom flags to the linker +# for example libraries like: +# USER_LDFLAGS = libs/libawesomelib.a + +USER_LDFLAGS = -lOpenNI + + +EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj" + +# change this to add different compiler optimizations to your project + +USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os + + +# android specific, in case you want to use different optimizations +USER_LIBS_ARM = +USER_LIBS_ARM7 = +USER_LIBS_NEON = + +# android optimizations + +ANDROID_COMPILER_OPTIMIZATION = -Os + +NDK_PLATFORM = android-8 + +# uncomment this for custom application name (if the folder name is different than the application name) +#APPNAME = folderName + +# uncomment this for custom package name, must be the same as the java package that contains OFActivity +#PKGNAME = cc.openframeworks.$(APPNAME) + + + + + +# linux arm flags + +LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp + + + diff --git a/tshirtmapping/src/main.cpp b/tshirtmapping/src/main.cpp new file mode 100755 index 0000000..6a32c6a --- /dev/null +++ b/tshirtmapping/src/main.cpp @@ -0,0 +1,16 @@ +#include "ofMain.h" +#include "testApp.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new testApp()); + +} diff --git a/tshirtmapping/src/testApp.cpp b/tshirtmapping/src/testApp.cpp new file mode 100755 index 0000000..0172617 --- /dev/null +++ b/tshirtmapping/src/testApp.cpp @@ -0,0 +1,291 @@ +#include "testApp.h" +//texture binding with normalised coords +void bindTexture(ofBaseHasTexture &t) { + ofTexture &tex = t.getTextureReference(); + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTexture(ofBaseHasTexture &t) { + t.getTextureReference().unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} +void bindTex(ofTexture &tex) { + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTex(ofTexture &tex) { + tex.unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} + +//-------------------------------------------------------------- +void testApp::setup(){ + draw3D=true; + + isLive = true; + isTracking = false; + isFiltering = false; + isCloud = false; + isCPBkgnd = true; + isMasking = true; + + nearThreshold = 500; + farThreshold = 1000; + + filterFactor = 10.0f; + + recordContext.setup(); + recordDepth.setup(&recordContext); + recordImage.setup(&recordContext); + recordUser.setup(&recordContext); + recordUser.setSmoothing(filterFactor); // built in openni skeleton smoothing... + recordUser.setUseMaskPixels(isMasking); + recordUser.setUseCloudPoints(draw3D); + recordUser.setMaxNumberOfUsers(2); + + target.setUseTexture(true); + target.loadImage("target.png"); + + camRotationY=0; + + ofBackground(0,0,0); +} + +//-------------------------------------------------------------- +void testApp::update(){ + // update all nodes + recordContext.update(); + recordDepth.update(); + recordImage.update(); + recordUser.update(); +} + +//-------------------------------------------------------------- +void testApp::draw(){ + ofSetColor(255, 255, 255); + + if(draw3D) { + //recordDepth.draw(0,0,ofGetWidth(),ofGetHeight()); + recordUser.draw(ofGetWidth(),ofGetHeight()); + ofSetColor(255,255,255); + ofSetLineWidth(5); + bindTexture(target); + ofEnableAlphaBlending(); + glPushMatrix(); + glScalef(ofGetWidth()/640.0f,ofGetHeight()/480.0f, 1); + for (int i=0;i<recordUser.getNumberOfTrackedUsers();i++){ + ofxTrackedUser* u=(recordUser.getTrackedUser(i+1)); + + if (u->neck.found) { + + float ratio=16.0f/9.0f; + float heightratio=0.8f; + float widthratio=0.8f; + + float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip width x + float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); //hip width y + + float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips + float cy=(float)(u->hip.position[0].Y)+(ay*0.5f); + + float hx=(((float)(u->left_shoulder.position[0].X))-cx); //height of torso + float hy=(((float)(u->left_shoulder.position[0].Y))-cy); + + float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom + float p1y=cy+(hy*(1.0f-heightratio)*0.5f); + + float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top + float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f))); + + ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio),0); + ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio),0); + ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio),0); + ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio),0); + + ofMesh targ; + targ.addVertex(c1); + targ.addTexCoord(ofVec2f(0,0)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c4); + targ.addTexCoord(ofVec2f(1,1)); + targ.draw(); + + } + } + glPopMatrix(); + unbindTexture(target); + } + else { //3D + glPushMatrix(); + + int w = recordUser.getWidth(); + int h = recordUser.getHeight(); + + glTranslatef(w, h/2, -500); + ofRotateY(camRotationY); + + glBegin(GL_POINTS); + + int step = 1; + + for(int y = 0; y < h; y += step) { + for(int x = 0; x < w; x += step) { + ofPoint pos = recordUser.getWorldCoordinateAt(x, y, 0); //userID); + if (pos.z == 0 ) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd + ofColor color = recordUser.getWorldColorAt(x,y, 0); //userID); + glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + glVertex3f(pos.x, pos.y, pos.z); + } + } + + glEnd(); + + glColor3f(1.0f, 1.0f, 1.0f); + + + bindTexture(target); + ofEnableAlphaBlending(); + glPushMatrix(); + //glScalef(ofGetWidth()/640.0f,ofGetHeight()/480.0f, 1); + for (int i=0;i<recordUser.getNumberOfTrackedUsers();i++){ + ofxTrackedUser* u=(recordUser.getTrackedUser(i+1)); + + if (u->neck.found) { + + float ratio=16.0f/9.0f; + float heightratio=0.8f; + float widthratio=0.8f; + + float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip vector + float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); + float az=((float)(u->hip.position[1].Z-u->hip.position[0].Z)); + + float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips + float cy=(float)(u->hip.position[0].Y)+(ay*0.5f); + float cz=(float)(u->hip.position[0].Z)+(az*0.5f); + + float hx=(((float)(u->left_shoulder.position[0].X))-cx); //torso vector + float hy=(((float)(u->left_shoulder.position[0].Y))-cy); + float hz=(((float)(u->left_shoulder.position[0].Z))-cz); + + float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom + float p1y=cy+(hy*(1.0f-heightratio)*0.5f); + float p1z=cz+(hz*(1.0f-heightratio)*0.5f); + + float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top + float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f))); + float p2z=cz+(hz*(1.0f-((1.0f-heightratio)*0.5f))); + + ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio), p2z-(az*0.5*widthratio)); + ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio), p2z+(az*0.5*widthratio)); + ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio), p1z-(az*0.5*widthratio)); + ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio), p1z+(az*0.5*widthratio)); + + ofMesh targ; + targ.addVertex(c1); + targ.addTexCoord(ofVec2f(0,0)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c4); + targ.addTexCoord(ofVec2f(1,1)); + targ.draw(); + + } + } + glPopMatrix(); + unbindTexture(target); + + + glPopMatrix(); + + } + +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + camRotationY = x; +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void testApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void testApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/tshirtmapping/src/testApp.h b/tshirtmapping/src/testApp.h new file mode 100755 index 0000000..c18b950 --- /dev/null +++ b/tshirtmapping/src/testApp.h @@ -0,0 +1,45 @@ +#pragma once + +#include "ofxOpenNI.h" +#include "ofMain.h" + +void bindTexture(ofBaseHasTexture &t); +void unbindTexture(ofBaseHasTexture &t); +void bindTex(ofTexture &tex); +void unbindTex(ofTexture &tex); + +class testApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + void keyPressed (int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + 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); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + bool isLive, isTracking, isCloud, isCPBkgnd, isMasking, isFiltering; + + ofxOpenNIContext recordContext; + ofxDepthGenerator recordDepth; + ofxImageGenerator recordImage; + ofxUserGenerator recordUser; + + int nearThreshold, farThreshold; + float filterFactor; + + int mode; + + ofImage target; + + bool draw3D; + float camRotationY; + +}; diff --git a/tshirtmapping/tshirtmapping.cbp b/tshirtmapping/tshirtmapping.cbp new file mode 100755 index 0000000..0024ab0 --- /dev/null +++ b/tshirtmapping/tshirtmapping.cbp @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="tshirtmapping" /> + <Option makefile_is_custom="1" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Option virtualFolders="src/;build config/;" /> + <Build> + <Target title="Debug"> + <Option output="bin/$(PROJECT_NAME)_debug" prefix_auto="1" extension_auto="1" /> + <Option working_dir="bin" /> + <Option object_output="obj/Debug/" /> + <Option external_deps="../../../../libs/openFrameworksCompiled/lib/linux/libopenFrameworksDebug.a;" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Option projectLinkerOptionsRelation="2" /> + </Target> + <Target title="Release"> + <Option output="bin/$(PROJECT_NAME)" prefix_auto="1" extension_auto="1" /> + <Option working_dir="bin" /> + <Option object_output="obj/Release/" /> + <Option external_deps="../../../../libs/openFrameworksCompiled/lib/linux/libopenFrameworks.a;" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Option projectLinkerOptionsRelation="2" /> + </Target> + </Build> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxDepthGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxDepthGenerator.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxGestureGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxGestureGenerator.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxHandGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxHandGenerator.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxHardwareDriver.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxHardwareDriver.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxIRGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxIRGenerator.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxImageGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxImageGenerator.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNI.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNIContext.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNIContext.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNIMacros.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNIRecorder.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxOpenNIRecorder.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxTrackedHand.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxTrackedHand.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxTrackedUser.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxTrackedUser.h" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxUserGenerator.cpp" /> + <Unit filename="../../openFrameworks/addons/ofxOpenNI/src/ofxUserGenerator.h" /> + <Unit filename="Makefile"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="addons.make"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="config.make"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="src/main.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/testApp.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/testApp.h"> + <Option virtualFolder="src/" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/tshirtmapping/tshirtmapping.layout b/tshirtmapping/tshirtmapping.layout new file mode 100755 index 0000000..ffdc99c --- /dev/null +++ b/tshirtmapping/tshirtmapping.layout @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="Debug" /> + <File name="../../openFrameworks/addons/ofxOpenNI/src/ofxUserGenerator.h" open="0" top="0" tabpos="0"> + <Cursor position="2398" topLine="66" /> + </File> + <File name="Makefile" open="1" top="0" tabpos="4"> + <Cursor position="20" topLine="0" /> + </File> + <File name="addons.make" open="1" top="0" tabpos="5"> + <Cursor position="0" topLine="0" /> + </File> + <File name="config.make" open="1" top="0" tabpos="1"> + <Cursor position="185" topLine="0" /> + </File> + <File name="src/testApp.cpp" open="1" top="1" tabpos="3"> + <Cursor position="8925" topLine="80" /> + </File> + <File name="src/testApp.h" open="1" top="0" tabpos="2"> + <Cursor position="987" topLine="11" /> + </File> +</CodeBlocks_layout_file> diff --git a/tshirtmapping/tshirtmapping.workspace b/tshirtmapping/tshirtmapping.workspace new file mode 100755 index 0000000..f32685a --- /dev/null +++ b/tshirtmapping/tshirtmapping.workspace @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_workspace_file> + <Workspace title="openNI-demoAllFeatures"> + <Project filename="openNI-demoAllFeatures.cbp" active="1"> + <Depends filename="../../../../libs/openFrameworksCompiled/project/linux/libopenFrameworks.cbp" /> + </Project> + <Project filename="../../../../libs/openFrameworksCompiled/project/linux/libopenFrameworks.cbp" /> + </Workspace> +</CodeBlocks_workspace_file> |
