From c81d13d3c2d4a89d9cac3ca54cca69650ec3a52d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 11 Mar 2014 13:15:31 +0000 Subject: sizing image library --- test-kinect/src/ofApp.cpp | 324 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) create mode 100644 test-kinect/src/ofApp.cpp (limited to 'test-kinect/src/ofApp.cpp') diff --git a/test-kinect/src/ofApp.cpp b/test-kinect/src/ofApp.cpp new file mode 100644 index 0000000..02875f2 --- /dev/null +++ b/test-kinect/src/ofApp.cpp @@ -0,0 +1,324 @@ +#include "ofApp.h" + + +//-------------------------------------------------------------- +void ofApp::setup() { + ofSetLogLevel(OF_LOG_WARNING); + + // enable depth->video image calibration + kinect.setRegistration(true); + + kinect.init(); + //kinect.init(true); // shows infrared instead of RGB video image + //kinect.init(false, false); // disable video image (faster fps) + + kinect.open(); // opens first available kinect + //kinect.open(1); // open a kinect by id, starting with 0 (sorted by serial # lexicographically)) + //kinect.open("A00362A08602047A"); // open a kinect using it's unique serial # + + // print the intrinsic IR sensor values + if(kinect.isConnected()) { + ofLogNotice() << "sensor-emitter dist: " << kinect.getSensorEmitterDistance() << "cm"; + ofLogNotice() << "sensor-camera dist: " << kinect.getSensorCameraDistance() << "cm"; + ofLogNotice() << "zero plane pixel size: " << kinect.getZeroPlanePixelSize() << "mm"; + ofLogNotice() << "zero plane dist: " << kinect.getZeroPlaneDistance() << "mm"; + } + + + colourImage.allocate(kinect.width, kinect.height); + depthImage.allocate(kinect.width, kinect.height); + + farThreshold = 70; + + ofSetFrameRate(60); + + // zero the tilt on startup + angle = 0; + kinect.setCameraTiltAngle(angle); + + //start with the largest size square + //get the depth, if below a certain size, subdivide and repeat + + //OR start at the smallest size, if adjacent squares are the same, work up + + //1 - create a pyramid of mip maps of depth + //2 - work upwards + + //a find layout of largest tiles + //b extend captured frame to this ratio + //c mip map this down into prepared containers + + int tiles_w=ceil((float)kinect.width/(MAX_TILE_SIZE*2))*2; + int tiles_h=ceil((float)kinect.height/(MAX_TILE_SIZE*2))*2; + extend_w=(tiles_w)*MAX_TILE_SIZE; + extend_h=(tiles_h)*MAX_TILE_SIZE; + + //get number of levels + levels=0; + for (int i=MIN_TILE_SIZE;i<=MAX_TILE_SIZE;i*=2) { + levels++; + } + + colourTiles.resize(levels); + depthTiles.resize(levels); + + for (int i=MIN_TILE_SIZE,l=0;i<=MAX_TILE_SIZE;i*=2,l++) { + colourTiles[l].allocate(extend_w/i,extend_h/i); + depthTiles[l].allocate(extend_w/i,extend_h/i); + cerr<<"level "<0&&max(0,depthTiles[level].getPixels()[y*((int)depthTiles[level].getWidth())+x]-128)>level*levels_factor){ + for (int i=0;i<2;i++){ + for (int j=0;j<2;j++){ + checktile(level-1,x*2+i,y*2+j,size/2); + } + } + } + else { + ofSetColor(colourTiles[level].getPixels()[(y*((int)colourTiles[level].getWidth())+x)*3], + colourTiles[level].getPixels()[(y*((int)colourTiles[level].getWidth())+x)*3+1], + colourTiles[level].getPixels()[(y*((int)colourTiles[level].getWidth())+x)*3+2]); + ofRect(x*size,y*size,size,size); + } +} + +//-------------------------------------------------------------- +void ofApp::draw() { + + ofBackground(0,0,0); + + ofSetColor(255, 255, 255); + + int pixelsize=ofGetWidth()/colourTiles[levels-1].getWidth(); + + + switch(mode){ + case MODE_COLOURTILES: + + //recursively draw pixels + + //int yoffset= + + for (int i=0;i': + case '.': + farThreshold ++; + if (farThreshold > 255) farThreshold = 255; + break; + + case '<': + case ',': + farThreshold --; + if (farThreshold < 0) farThreshold = 0; + break; + + + case 'w': + kinect.enableDepthNearValueWhite(!kinect.isDepthNearValueWhite()); + break; + + case 'o': + kinect.setCameraTiltAngle(angle); // go back to prev tilt + kinect.open(); + break; + + case 'c': + kinect.setCameraTiltAngle(0); // zero the tilt + kinect.close(); + break; + + case '1': + kinect.setLed(ofxKinect::LED_GREEN); + break; + + case '2': + kinect.setLed(ofxKinect::LED_YELLOW); + break; + + case '3': + kinect.setLed(ofxKinect::LED_RED); + break; + + case '4': + kinect.setLed(ofxKinect::LED_BLINK_GREEN); + break; + + case '5': + kinect.setLed(ofxKinect::LED_BLINK_YELLOW_RED); + break; + + case '0': + kinect.setLed(ofxKinect::LED_OFF); + break; + + case OF_KEY_UP: + angle++; + if(angle>30) angle=30; + kinect.setCameraTiltAngle(angle); + break; + + case OF_KEY_DOWN: + angle--; + if(angle<-30) angle=-30; + kinect.setCameraTiltAngle(angle); + break; + + case OF_KEY_LEFT: + mode--; + if (mode<0) mode==NUM_MODES-1; + break; + + case OF_KEY_RIGHT: + mode=(mode+1)%NUM_MODES; + break; + + case ' ': + fullscreen=!fullscreen; + ofSetFullscreen(fullscreen); + 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) +{} -- cgit v1.2.3