Last active
October 21, 2019 01:23
-
-
Save prisonerjohn/42cbc92be72fbf70b7b498d41e06e686 to your computer and use it in GitHub Desktop.
Kinect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
kinect.init(); | |
kinect.open(); | |
} | |
void ofApp::update() | |
{ | |
kinect.update(); | |
} | |
void ofApp::draw() | |
{ | |
if (kinect.isFrameNew()) | |
{ | |
kinect.getDepthTexture().draw(0, 0); | |
// Get the point distance using the SDK function. | |
float distAtMouse = kinect.getDistanceAt(ofGetMouseX(), ofGetMouseY()); | |
ofDrawBitmapStringHighlight(ofToString(distAtMouse, 3), ofGetMouseX(), ofGetMouseY() - 10); | |
// Get the point depth using the texture directly. | |
ofShortPixels rawDepthPix = kinect.getRawDepthPixels(); | |
int depthAtMouse = rawDepthPix.getColor(ofGetMouseX(), ofGetMouseY()).r; | |
ofDrawBitmapStringHighlight(ofToString(depthAtMouse), ofGetMouseX() + 16, ofGetMouseY() + 10); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxKinect.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofxKinect kinect; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
ofSetWindowShape(1280, 480); | |
// Start the depth sensor. | |
kinect.setRegistration(true); | |
kinect.init(); | |
kinect.open(); | |
// Setup the parameters. | |
nearThreshold.set("Near Threshold", 0.01f, 0.0f, 0.1f); | |
farThreshold.set("Far Threshold", 0.02f, 0.0f, 0.1f); | |
// Setup the gui. | |
guiPanel.setup("Depth Threshold", "settings.json"); | |
guiPanel.add(nearThreshold); | |
guiPanel.add(farThreshold); | |
} | |
void ofApp::update() | |
{ | |
kinect.update(); | |
} | |
void ofApp::draw() | |
{ | |
if (kinect.isFrameNew()) | |
{ | |
kinect.getDepthTexture().draw(0, 0); | |
// Get the point distance using the SDK function. | |
float distAtMouse = kinect.getDistanceAt(ofGetMouseX(), ofGetMouseY()); | |
ofDrawBitmapStringHighlight(ofToString(distAtMouse, 3), ofGetMouseX(), ofGetMouseY()); | |
// Threshold the depth. | |
ofFloatPixels rawDepthPix = kinect.getRawDepthPixels(); | |
ofFloatPixels thresholdNear, thresholdFar, thresholdResult; | |
ofxCv::threshold(rawDepthPix, thresholdNear, nearThreshold); | |
ofxCv::threshold(rawDepthPix, thresholdFar, farThreshold, true); | |
ofxCv::bitwise_and(thresholdNear, thresholdFar, thresholdResult); | |
// Upload pixels to image. | |
thresholdImg.setFromPixels(thresholdResult); | |
// Draw the result image. | |
thresholdImg.draw(640, 0); | |
} | |
// Draw the gui. | |
guiPanel.draw(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxCv.h" | |
#include "ofxGui.h" | |
#include "ofxKinect.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofxKinect kinect; | |
ofImage thresholdImg; | |
ofParameter<float> nearThreshold; | |
ofParameter<float> farThreshold; | |
ofxPanel guiPanel; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
kinect.open(); | |
kinect.initDepthSource(); | |
kinect.initColorSource(); | |
} | |
void ofApp::update() | |
{ | |
kinect.update(); | |
} | |
void ofApp::draw() | |
{ | |
if (kinect.isFrameNew()) | |
{ | |
std::shared_ptr<ofxKFW2::Source::Depth> depthSource = kinect.getDepthSource(); | |
// Clamp the mouse coordinate to ensure it stays within the data bounds. | |
int readX = ofClamp(ofGetMouseX(), 0, depthSource->getWidth() - 1); | |
int readY = ofClamp(ofGetMouseY(), 0, depthSource->getHeight() - 1); | |
// Get the point depth using the texture directly. | |
ofShortPixels rawDepthPix = depthSource->getPixels(); | |
int depthAtMouse = rawDepthPix.getColor(readX, readY).r; | |
ofDrawBitmapStringHighlight(ofToString(depthAtMouse), ofGetMouseX(), ofGetMouseY()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofxKinectForWindows2.h" | |
class ofApp : 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 mouseEntered(int x, int y); | |
void mouseExited(int x, int y); | |
void windowResized(int w, int h); | |
void dragEvent(ofDragInfo dragInfo); | |
void gotMessage(ofMessage msg); | |
ofxKFW2::Device kinect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment