Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ofTheo/ofxKinect into feature-til…
Browse files Browse the repository at this point in the history
…troll

Conflicts:
	src/ofxKinect.h
  • Loading branch information
arturoc committed Mar 16, 2012
2 parents 04069ca + 5f167af commit 61a191a
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 115 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Expand Up @@ -69,7 +69,7 @@ Xcode4: Open the Xcode project, select the "ofxKinectExample" scheme, and hit "R

Install the libusb-1.0 library. On Ubuntu, you can do this with:
<pre>
sudo apt-get install libusb1.0-0-dev
sudo apt-get install libusb-1.0-0-dev
</pre>

Open the Code::Blocks .cbp and hit F9 to build. Optionally, you can build the example with the Makefile.
Expand Down Expand Up @@ -99,6 +99,8 @@ libs/libusb/win/inf

You may need to manually update each driver individually if you've plugged it in before. ofxKinect will not work if the drivers are not installed.

**NOTE**: You cannot use the OpenNI drivers and the libfreenect drivers included with ofxKinect at the same time. You must manually uninstall one and reinstall the other in the Device Manager. Sorry, that's just how it is. :P

How to Create a New ofxKinect Project
-----------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion example/src/testApp.cpp
Expand Up @@ -5,7 +5,7 @@
void testApp::setup() {
ofSetLogLevel(OF_LOG_VERBOSE);

// enable depth->rgb image calibration
// enable depth->video image calibration
kinect.setRegistration(true);

kinect.init();
Expand Down
4 changes: 2 additions & 2 deletions example/src/testApp.h
Expand Up @@ -17,7 +17,7 @@ class testApp : public ofBaseApp {

void drawPointCloud();

void keyPressed (int key);
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);
Expand Down Expand Up @@ -45,6 +45,6 @@ class testApp : public ofBaseApp {

int angle;

// used for viewing the point cloud
// used for viewing the point cloud
ofEasyCam easyCam;
};
Binary file modified libs/libfreenect/lib/vs2010/freenect.dll
Binary file not shown.
Binary file modified libs/libfreenect/lib/vs2010/freenect.lib
Binary file not shown.
91 changes: 45 additions & 46 deletions src/ofxKinect.cpp
Expand Up @@ -52,6 +52,9 @@ ofxKinect::ofxKinect() {
bNeedsUpdate = false;
bUpdateTex = false;
bIsFrameNew = false;

bIsVideoInfrared = false;
videoBytesPerPixel = 3;

kinectDevice = NULL;

Expand Down Expand Up @@ -80,20 +83,31 @@ bool ofxKinect::init(bool infrared, bool video, bool texture) {

clear();

bInfrared = infrared;
bIsVideoInfrared = infrared;
bGrabVideo = video;
bytespp = infrared?1:3;
videoBytesPerPixel = infrared?1:3;

bUseTexture = texture;

depthPixelsRaw.allocate(width,height,1);
depthPixelsBack.allocate(width,height,1);
// allocate
depthPixelsRaw.allocate(width, height, 1);
depthPixelsRawBack.allocate(width, height, 1);

videoPixels.allocate(width, height, videoBytesPerPixel);
videoPixelsBack.allocate(width, height, videoBytesPerPixel);

depthPixels.allocate(width, height, 1);
distancePixels.allocate(width, height, 1);

// set
depthPixelsRaw.set(0);
depthPixelsRawBack.set(0);

videoPixels.allocate(width,height,bytespp);
videoPixelsBack.allocate(width,height,bytespp);
videoPixels.set(0);
videoPixelsBack.set(0);

depthPixels.allocate(width,height,1);
distancePixels.allocate(width,height,1);
depthPixels.set(0);
distancePixels.set(0);

if(bUseTexture) {
depthTex.allocate(width, height, GL_LUMINANCE);
Expand Down Expand Up @@ -126,7 +140,7 @@ void ofxKinect::clear() {
}

depthPixelsRaw.clear();
depthPixelsBack.clear();
depthPixelsRawBack.clear();

videoPixels.clear();
videoPixelsBack.clear();
Expand Down Expand Up @@ -163,7 +177,7 @@ bool ofxKinect::open(int id){

freenect_set_user(kinectDevice, this);
freenect_set_depth_callback(kinectDevice, &grabDepthFrame);
freenect_set_video_callback(kinectDevice, &grabRgbFrame);
freenect_set_video_callback(kinectDevice, &grabVideoFrame);

startThread(true, false); // blocking, not verbose

Expand Down Expand Up @@ -212,7 +226,7 @@ void ofxKinect::update() {
if(this->lock()) {
int n = width * height;

depthPixelsRaw = depthPixelsBack;
depthPixelsRaw = depthPixelsRawBack;
videoPixels = videoPixelsBack;

//we have done the update
Expand All @@ -224,8 +238,8 @@ void ofxKinect::update() {
}

if(bUseTexture) {
depthTex.loadData(depthPixels);
videoTex.loadData(videoPixels);
depthTex.loadData(depthPixels.getPixels(), width, height, GL_LUMINANCE);
videoTex.loadData(videoPixels.getPixels(), width, height, bIsVideoInfrared?GL_LUMINANCE:GL_RGB);
bUpdateTex = false;
}
}
Expand Down Expand Up @@ -254,11 +268,11 @@ ofVec3f ofxKinect::getWorldCoordinateAt(float cx, float cy, float wz) {

//------------------------------------
ofColor ofxKinect::getColorAt(int x, int y) {
int index = (y * width + x) * bytespp;
int index = (y * width + x) * videoBytesPerPixel;
ofColor c;
c.r = videoPixels[index + 0];
c.g = videoPixels[index + (bytespp-1)/2];
c.b = videoPixels[index + (bytespp-1)];
c.g = videoPixels[index + (videoBytesPerPixel-1)/2];
c.b = videoPixels[index + (videoBytesPerPixel-1)];
c.a = 255;

return c;
Expand Down Expand Up @@ -512,51 +526,36 @@ void ofxKinect::grabDepthFrame(freenect_device *dev, void *depth, uint32_t times

ofxKinect* kinect = kinectContext.getKinect(dev);

if(kinect->kinectDevice == dev && kinect->lock()) {
try {
freenect_frame_mode curMode = freenect_get_current_depth_mode(dev);
kinect->depthPixelsBack.setFromPixels((unsigned short*)depth,width, height, 1);
kinect->bNeedsUpdate = true;
}
catch(...) {
ofLog(OF_LOG_ERROR, "ofxKinect: Depth memcpy failed for device %d", kinect->getDeviceId());
}
if(kinect->kinectDevice == dev) {
kinect->lock();
freenect_frame_mode curMode = freenect_get_current_depth_mode(dev);
kinect->depthPixelsRawBack.setFromPixels((unsigned short*) depth, width, height, 1);
kinect->bNeedsUpdate = true;
kinect->unlock();
}
else {
ofLog(OF_LOG_WARNING, "ofxKinect: grabDepthFrame unable to lock mutex");
}
}
}

//---------------------------------------------------------------------------
void ofxKinect::grabRgbFrame(freenect_device *dev, void *rgb, uint32_t timestamp) {
void ofxKinect::grabVideoFrame(freenect_device *dev, void *video, uint32_t timestamp) {

ofxKinect* kinect = kinectContext.getKinect(dev);

if(kinect->kinectDevice == dev && kinect->lock()) {
try {
freenect_frame_mode curMode = freenect_get_current_video_mode(dev);
kinect->videoPixelsBack.setFromPixels((unsigned char*)rgb, width, height, curMode.data_bits_per_pixel/8);
kinect->bNeedsUpdate = true;
}
catch (...) {
ofLog(OF_LOG_ERROR, "ofxKinect: Rgb memcpy failed for device %d",
kinect->getDeviceId());
}
if(kinect->kinectDevice == dev) {
kinect->lock();
freenect_frame_mode curMode = freenect_get_current_video_mode(dev);
kinect->videoPixelsBack.setFromPixels((unsigned char*)video, width, height, curMode.data_bits_per_pixel/8);
kinect->bNeedsUpdate = true;
kinect->unlock();
}
else {
ofLog(OF_LOG_ERROR, "ofxKinect: grabRgbFrame unable to lock mutex");
}
}

//---------------------------------------------------------------------------
void ofxKinect::threadedFunction(){

freenect_set_led(kinectDevice, LED_GREEN);
freenect_frame_mode videoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, bInfrared ? FREENECT_VIDEO_IR_8BIT : FREENECT_VIDEO_RGB);
freenect_frame_mode videoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, bIsVideoInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_RGB);
freenect_set_video_mode(kinectDevice, videoMode);
freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, bUseRegistration ? FREENECT_DEPTH_REGISTERED : FREENECT_DEPTH_MM);
freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, bUseRegistration?FREENECT_DEPTH_REGISTERED:FREENECT_DEPTH_MM);
freenect_set_depth_mode(kinectDevice, depthMode);

ofLog(OF_LOG_VERBOSE, "ofxKinect: Device %d connection opened", kinectContext.getId(*this));
Expand Down Expand Up @@ -589,7 +588,7 @@ void ofxKinect::threadedFunction(){
freenect_get_mks_accel(tilt, &dx, &dy, &dz);
mksAccel.set(dx, dy, dz);

// ... and $0.02 for the scheduler
// ... and $0.02 for the scheduler
ofSleepMillis(10);
}

Expand Down

0 comments on commit 61a191a

Please sign in to comment.