Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complications w/ openframeworks 007 #2

Open
cindyloo opened this issue Mar 16, 2012 · 1 comment
Open

complications w/ openframeworks 007 #2

cindyloo opened this issue Mar 16, 2012 · 1 comment

Comments

@cindyloo
Copy link

hi there-
I got this working last fall, and just recently updated your new version. However, it isn't working. There were still references to deprecated or removed ofxKinect calls eg
kinect.getCalibration().setClippingInCentimeters(clippingNear, clippingFar);
etc
the picture resolves, but the kinect map does not. My ofxKinect example runs fine however

Let me know if there are any known issues. thanks, cindy

mac os 10.8

@cindyloo
Copy link
Author

ok, I had to update the code to reflect the 007 ofxKinect example and it worked, although could still use some tweaking. here's an updated testApp.cpp if you want to confirm and then update GitHub

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup() {

ofSetLogLevel(OF_LOG_VERBOSE);
//ofSetFrameRate(60);
//ofSetVerticalSync(true);
ofHideCursor();

ofBackground(0, 0, 0);

width = 1280;
height = 720;
numPixels = width * height;

currentMovie = 0;

status = 0;

showInfo = true;

refreshInterval = 30 * 60 * 1000;
nextRefresh = refreshInterval;

alphaBlend = 0.7;
blur = 4;


//kinect.init(true);  //shows infrared image
// enable depth->video image calibration
kinect.setRegistration(true);
kinect.init();

//kinect.setVerbose();
kinect.open();

clippingNear = 60;
clippingFar = 230;
camTilt = 0;

kinect.setCameraTiltAngle(camTilt);

grayImage.allocate(kinect.width, kinect.height);
grayImageScaled.allocate(width, height);

grayThreshNear.allocate(kinect.width, kinect.height);
grayThreshFar.allocate(kinect.width, kinect.height);

nearThreshold = 230;
farThreshold = 60;
bThreshWithOpenCV = true;

ofSetFrameRate(60);


dest.allocate(width, height, OF_IMAGE_COLOR);

numMovies = DIR.listDir("movies");


frames = new unsigned char[256*numPixels*3];

}

//--------------------------------------------------------------
void testApp::update() {

ofBackground(100, 100, 100);

kinect.update();
if(kinect.isFrameNew()) // there is a new frame and we are connected
{

    // use this instead of the following for temporal blending
    // kinectImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
    // cvAddWeighted(kinectImage.getCvImage(), alphaBlend, grayImage.getCvImage(), (1-alphaBlend), 0, grayImage.getCvImage());
    // grayImage.flagImageChanged();
    grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);



    if(bThreshWithOpenCV) {
        grayThreshNear = grayImage;
        grayThreshFar = grayImage;
        grayThreshNear.threshold(nearThreshold, true);
        grayThreshFar.threshold(farThreshold);

//interestingly, the cvAnd will throw this off entirely
//cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);

        grayImageScaled.scaleIntoMe(grayImage, CV_INTER_NN);
    } else {

        // or we do it ourselves - show people how they can work with the pixels
        unsigned char * pix = grayImage.getPixels();

        int numPixels = grayImage.getWidth() * grayImage.getHeight();
        for(int i = 0; i < numPixels; i++) {
            if(pix[i] < nearThreshold && pix[i] > farThreshold) {
                pix[i] = 255;
            } else {
                pix[i] = 0;
            }
        }
    }


    // uncomment for blur control
    // grayImageScaled.blurGaussian(blur);
    grayImage.flagImageChanged();

}

}

//--------------------------------------------------------------
void testApp::draw() {
ofSetColor(255, 255, 255);

//grayImage.draw(10, 320, 400, 300);

if (status == 0) {
    dest.draw(300, 300);

    ofEnableAlphaBlending();
    ofSetColor(0, 0, 0, 200);
    ofRect(0, 0, width, height);
    ofDisableAlphaBlending();

    ofSetColor(255, 255, 255);
    stringstream reportStream;
    reportStream << "Loading\n" << DIR.getName(currentMovie);
    ofDrawBitmapString(reportStream.str(), width / 2, height / 2);
    status++;
} else if (status == 1) {
    ofVideoPlayer video;
    video.loadMovie(DIR.getPath(currentMovie));

    //float nFrames = video.nFrames;
    float nFrames = video.getTotalNumFrames();
    unsigned char* pixels;
    for (int i = 0; i < 256; i++) {
        video.setFrame(nFrames * (float) i / 256.0 + 3);
        pixels = video.getPixels();
        memcpy(frames + i*numPixels*3, pixels, numPixels*3);
    }

    video.closeMovie();

    status++;
} else if (status == 2) {
    unsigned char* destPixels = dest.getPixels();
    unsigned char* grayPixels = grayImageScaled.getPixels();

    for (int i = 0; i < numPixels; i++) {
        int depth = grayPixels[i];

        int destOffset = i*3;
        int framesOffset = depth*numPixels*3 + destOffset; //sometimes I divide depth by a factor depending on video length..

        destPixels[destOffset] = frames[framesOffset];
        destPixels[destOffset+1] = frames[framesOffset+1];
        destPixels[destOffset+2] = frames[framesOffset+2];


    }

    dest.update();

    dest.draw(0, 0);

    // refresh if elapsed time long enough
    if (ofGetElapsedTimeMillis() > nextRefresh) {
        nextRefresh = ofGetElapsedTimeMillis() + refreshInterval;
        currentMovie = (currentMovie + 1) % numMovies;
        status = 0;
    }

}
//kinect.drawDepth(10, 10, 400, 300);
//kinect.draw(420, 10, 400, 300);

if (showInfo) {
    stringstream reportStream;
    reportStream
    << "toggle this information display (press: ?)" << endl
    << endl
    << "next video (press: spacebar)" << endl
    << "toggle fullscreen (press: f)" << endl
    << "save a snapshot (press: s)" << endl
    << endl
    << "set near threshold " << clippingNear << " (press: + -)" << endl
    << "set far threshold " << clippingFar << " (press: < >)" << endl
    << "set camera tilt " << camTilt << " (press: DOWN UP)" << endl
    << endl
    // << "set alpha blend " << alphaBlend << " (press: a A)" << endl
    // << "set blur " << blur << " (press: b B)" << endl
    << endl
    << "next auto-refresh in: " << (nextRefresh-ofGetElapsedTimeMillis())/1000 << endl
    << "fps: " << ofGetFrameRate() << endl;
    ofDrawBitmapString(reportStream.str(),20,500);
}

}

//--------------------------------------------------------------
void testApp::exit() {
kinect.setCameraTiltAngle(0); // zero the tilt on exit
kinect.close();
}

//--------------------------------------------------------------
void testApp::keyPressed (int key) {
switch (key) {
case ' ':
nextRefresh = ofGetElapsedTimeMillis() + refreshInterval;
currentMovie = (currentMovie + 1) % numMovies;
status = 0;
break;

    case '/':
    case '?':
        showInfo = !showInfo;
        break;

    case 'f':
        ofToggleFullscreen();
        break;

    case 's':
        static char fileName[255];
        sprintf(fileName, "snapshots/%i-%i-%i-%i-%i-%i.png", ofGetYear(), ofGetMonth(), ofGetDay(), ofGetHours(), ofGetMinutes(), ofGetSeconds());
        dest.saveImage(fileName);
        break;

    case 'a':
        alphaBlend -= 0.05;
        break;
    case 'A':
        alphaBlend += 0.05;
        break;

    case 'b':
        blur -= 1;
        break;
    case 'B':
        blur += 1;
        break;

    case '>':
    case '.':
        farThreshold ++;
        if (farThreshold > 255) farThreshold = 255;
        break;

    case '<':
    case ',':
        farThreshold --;
        if (farThreshold < 0) farThreshold = 0;
        break;

    case '+':
    case '=':
        nearThreshold ++;
        if (nearThreshold > 255) nearThreshold = 255;
        break;

    case '-':
        nearThreshold --;
        if (nearThreshold < 0) nearThreshold = 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 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 testApp::mouseMoved(int x, int y) {
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{}

//--------------------------------------------------------------
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)
{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant