summaryrefslogtreecommitdiff
path: root/offsetProject/src
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2014-02-19 11:38:01 +0000
committerComment <tim@gray.(none)>2014-02-19 11:38:01 +0000
commit4ee3054aa1af56d9fe00f70b62ab107f206e19b1 (patch)
tree1da07f5e77875da94ff676c98be280fd93c31061 /offsetProject/src
initial commit
Diffstat (limited to 'offsetProject/src')
-rw-r--r--offsetProject/src/main.cpp6
-rw-r--r--offsetProject/src/ofApp.cpp230
-rw-r--r--offsetProject/src/ofApp.h51
3 files changed, 287 insertions, 0 deletions
diff --git a/offsetProject/src/main.cpp b/offsetProject/src/main.cpp
new file mode 100644
index 0000000..d134fc9
--- /dev/null
+++ b/offsetProject/src/main.cpp
@@ -0,0 +1,6 @@
+#include "ofApp.h"
+
+int main() {
+ ofSetupOpenGL(1024, 768, OF_WINDOW);
+ ofRunApp(new ofApp());
+}
diff --git a/offsetProject/src/ofApp.cpp b/offsetProject/src/ofApp.cpp
new file mode 100644
index 0000000..1c61832
--- /dev/null
+++ b/offsetProject/src/ofApp.cpp
@@ -0,0 +1,230 @@
+#include "ofApp.h"
+
+
+//--------------------------------------------------------------
+void ofApp::setup() {
+ ofSetLogLevel(OF_LOG_VERBOSE);
+
+ // 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);
+
+ //how to draw a pyramid mosaic
+ //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
+
+ int min_w=ceil(kinect.width/(MAX_TILE_SIZE*2))*2;
+ int min_h=ceil(kinect.height/(MAX_TILE_SIZE*2))*2;
+
+ //get number of levels
+ int levels=0;
+ for (int i=MIN_TILE_SIZE;i>=MAX_TILE_SIZE;i*=2) {
+ levels++;
+ int w=ceil(kinect.width/(i*2))*2;
+ int h=ceil(kinect.height/(i*2))*2;
+ numTiles.push_back(make_pair(w,h));
+ cerr<<"level "<<levels<<" mipmap: "<<w<<"x"<<h<<endl;
+ }
+
+ numTiles.resiz
+
+ colourTiles.resize(levels);
+ depthTiles.resize(levels);
+
+}
+
+//--------------------------------------------------------------
+void ofApp::update() {
+
+ ofBackground(100, 100, 100);
+
+ kinect.update();
+
+ // there is a new frame and we are connected
+ if(kinect.isFrameNew()) {
+
+ depthImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
+ colourImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
+
+ depthImage.threshold(farThreshold);
+
+ depthImage.extend()
+
+ // mark pixels and texture dirty
+ depthImage.flagImageChanged();
+ colourImage.flagImageChanged();
+
+ ofxCvColorImage *prevCol=&colourImage;
+ ofxCvGrayscaleImage *prevDepth=&depthImage;
+
+ for (int i=MIN_TILE_SIZE,l=0;i>=MAX_TILE_SIZE;i*=2,l++){
+ colourTiles[l].allocate(numTiles[l].first,numTiles[l].second);
+ colourTiles[l].scaleIntoMe(*prevCol);
+ depthTiles[l].allocate(numTiles[l].first,numTiles[l].second);
+ depthTiles[l].scaleIntoMe(*prevDepth);
+ //extend borders to a whole number of tiles of the next size
+ if (l<colourTiles.size()-1){
+ colourTiles[l].extend(numTiles[l+1].first*2,numTiles[l+1].second*2);
+ depthTiles[l].extend(numTiles[l+1].first*2,numTiles[l+1].second*2);
+ }
+ prevCol=&colourTiles[l];
+ prevDepth=&depthTiles[l];
+ }
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::draw() {
+
+ ofSetColor(255, 255, 255);
+
+ // draw from the live kinect
+ kinect.drawDepth(10, 10, 400, 300);
+ kinect.draw(420, 10, 400, 300);
+
+ depthImage.draw(10, 320, 400, 300);
+
+
+ // draw instructions
+ ofSetColor(255, 255, 255);
+ stringstream reportStream;
+
+ reportStream << "press p to switch between images and point cloud, rotate the point cloud with the mouse" << endl
+ << "set far threshold " << farThreshold
+ << ", fps: " << ofGetFrameRate() << endl
+ << "press c to close the connection and o to open it again, connection is: " << kinect.isConnected() << endl;
+
+ if(kinect.hasCamTiltControl()) {
+ reportStream << "press UP and DOWN to change the tilt angle: " << angle << " degrees" << endl
+ << "press 1-5 & 0 to change the led mode" << endl;
+ }
+
+ ofDrawBitmapString(reportStream.str(), 20, 652);
+
+}
+
+
+
+//--------------------------------------------------------------
+void ofApp::exit() {
+ kinect.setCameraTiltAngle(0); // zero the tilt on exit
+ kinect.close();
+
+}
+
+//--------------------------------------------------------------
+void ofApp::keyPressed (int key) {
+ switch (key) {
+
+ case '>':
+ 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;
+ }
+}
+
+//--------------------------------------------------------------
+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/offsetProject/src/ofApp.h b/offsetProject/src/ofApp.h
new file mode 100644
index 0000000..57ee0d0
--- /dev/null
+++ b/offsetProject/src/ofApp.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxOpenCv.h"
+#include "ofxKinect.h"
+
+#define MIN_TILE_SIZE 4 //has to be a divisor of 320 and 240 as the tiles are centred
+#define MAX_TILE_SIZE 32 //has to be a power of 2 * MIN_TILE_SIZE
+
+class offsetCvColorImage : public ofxCvColorImage {
+ public:
+ void extend( int w, int h ) {
+ //cv::copyMakeBorder(cvImage,cvImage,(h-getHeight())/2,(h-getHeight())/2,(w-getWidth())/2,(w-getWidth())/2,cv::BORDER_REPLICATE);
+ }
+};
+
+class offsetCvGrayscaleImage : public ofxCvGrayscaleImage {
+ public:
+ void extend( int w, int h ) {
+ //cv::copyMakeBorder(cvImage,cvImage,(h-getHeight())/2,(h-getHeight())/2,(w-getWidth())/2,(w-getWidth())/2,cv::BORDER_REPLICATE);
+ }
+};
+
+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);
+
+ ofxKinect kinect;
+
+ offsetCvColorImage colourImage;
+ offsetCvGrayscaleImage depthImage;
+
+ vector<offsetCvColorImage> colourTiles;
+ vector<offsetCvGrayscaleImage> depthTiles;
+ vector<pair<int,int> > numTiles;
+
+ int farThreshold;
+ int angle;
+
+
+};