Beispiel #1
0
void UserApp::setup()
{
    mBones.push_back( Bone( nite::JOINT_HEAD,			nite::JOINT_NECK ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_LEFT_ELBOW ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_ELBOW,		nite::JOINT_LEFT_HAND ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_SHOULDER, nite::JOINT_RIGHT_ELBOW ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_ELBOW,	nite::JOINT_RIGHT_HAND ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_RIGHT_SHOULDER ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_TORSO ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_SHOULDER, nite::JOINT_TORSO ) );
    mBones.push_back( Bone( nite::JOINT_TORSO,			nite::JOINT_LEFT_HIP ) );
    mBones.push_back( Bone( nite::JOINT_TORSO,			nite::JOINT_RIGHT_HIP ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_HIP,		nite::JOINT_RIGHT_HIP ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_HIP,		nite::JOINT_LEFT_KNEE ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_KNEE,		nite::JOINT_LEFT_FOOT ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_HIP,		nite::JOINT_RIGHT_KNEE ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_KNEE,		nite::JOINT_RIGHT_FOOT ) );

    mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f, 1.0f, 5000.0f );
    mCamera.lookAt( Vec3f::zero(), Vec3f::zAxis(), Vec3f::yAxis() );

    mDeviceManager = OpenNI::DeviceManager::create();
    try {
        mDevice = mDeviceManager->createDevice( OpenNI::DeviceOptions().enableUserTracking() );
    } catch ( OpenNI::ExcDeviceNotAvailable ex ) {
        console() << ex.what() << endl;
        quit();
        return;
    }

    mDevice->getUserTracker().setSkeletonSmoothingFactor( 0.5f );
    mDevice->connectUserEventHandler( &UserApp::onUser, this );
    mDevice->start();
}
Beispiel #2
0
void UserApp::onUser( nite::UserTrackerFrameRef frame, const OpenNI::DeviceOptions& deviceOptions )
{
    mChannel	= OpenNI::toChannel16u( frame.getDepthFrame() );
    mUsers		= OpenNI::toVector( frame.getUsers() );
    for ( vector<nite::UserData>::iterator iter = mUsers.begin(); iter != mUsers.end(); ++iter ) {
        if ( iter->isNew() ) {
            mDevice->getUserTracker().startSkeletonTracking( iter->getId() );
        } else if ( iter->isLost() ) {
            mDevice->getUserTracker().stopSkeletonTracking( iter->getId() );
        }
    }
}
void MotionTrackingTestApp::setup(){
    mDeviceManager = OpenNI::DeviceManager::create();
    
    shapeUID = 0;
    mTrackedShapes.clear();
    
    if( mDeviceManager->isInitialized() ){
        try{
            mDevice = mDeviceManager->createDevice( OpenNI::DeviceOptions().enableColor() );
        } catch( OpenNI::ExcDeviceNotAvailable ex) {
            console() << ex.what() << endl;
            quit();
            return;
        }
        
        if( mDevice ){
            mDevice->connectDepthEventHandler( &MotionTrackingTestApp::onDepth, this );
            mDevice->connectColorEventHandler( &MotionTrackingTestApp::onColor, this );
         //   mBackground = cv::Mat( 240,320, CV_16UC1 );
         //   mPreviousFrame = cv::Mat( 240,320, CV_16UC1 );
            mDevice->start();
        }
    }
    
    mThresh = 0.0;
    mMaxVal = 255.0;
    mNearLimit = 30;
    mFarLimit = 4000;
    
    mParams = params::InterfaceGl::create("Threshold", Vec2i( 255, 200 ) );
    mParams->addParam("Thresh", &mThresh, "min=0.0f max=255.0f step=1.0 keyIncr=a keyDecr=s");
    mParams->addParam("Maxval", &mMaxVal, "min=0.0f max=255.0f step=1.0 keyIncr=q keyDecr=w");
    //mParams->addParam( "Black near", &mNearLimit, "min=10 max=100 step=1 keyIncr=t keyDecr=y" );
//    mParams->addParam( "Black far", &mFarLimit, "min=200 max=1000 step=1 keyIncr=g keyDecr=h" );
    mStepSize = 10;
    mBlurAmount = 10;
}
Beispiel #4
0
void UserApp::setup()
{
    mShapeDetection = ShapeDetection();
    
    //	mBones.push_back( Bone( nite::JOINT_HEAD,			nite::JOINT_NECK ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_LEFT_ELBOW ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_ELBOW,		nite::JOINT_LEFT_HAND ) );
    //	mBones.push_back( Bone( nite::JOINT_RIGHT_SHOULDER, nite::JOINT_RIGHT_ELBOW ) );
    //	mBones.push_back( Bone( nite::JOINT_RIGHT_ELBOW,	nite::JOINT_RIGHT_HAND ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_RIGHT_SHOULDER ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_TORSO ) );
    //	mBones.push_back( Bone( nite::JOINT_RIGHT_SHOULDER, nite::JOINT_TORSO ) );
    //	mBones.push_back( Bone( nite::JOINT_TORSO,			nite::JOINT_LEFT_HIP ) );
    //	mBones.push_back( Bone( nite::JOINT_TORSO,			nite::JOINT_RIGHT_HIP ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_HIP,		nite::JOINT_RIGHT_HIP ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_HIP,		nite::JOINT_LEFT_KNEE ) );
    //	mBones.push_back( Bone( nite::JOINT_LEFT_KNEE,		nite::JOINT_LEFT_FOOT ) );
    //	mBones.push_back( Bone( nite::JOINT_RIGHT_HIP,		nite::JOINT_RIGHT_KNEE ) );
    //	mBones.push_back( Bone( nite::JOINT_RIGHT_KNEE,		nite::JOINT_RIGHT_FOOT ) );
    
    // POINTS
    mBones.push_back( Bone( nite::JOINT_HEAD,			nite::JOINT_HEAD ) );                //0
    mBones.push_back( Bone( nite::JOINT_NECK,			nite::JOINT_NECK ) );                //1
    mBones.push_back( Bone( nite::JOINT_LEFT_SHOULDER,	nite::JOINT_LEFT_SHOULDER ) );       //2
    mBones.push_back( Bone( nite::JOINT_LEFT_ELBOW,     nite::JOINT_LEFT_ELBOW ) );          //3
    mBones.push_back( Bone( nite::JOINT_LEFT_HAND,		nite::JOINT_LEFT_HAND ) );           //4
    mBones.push_back( Bone( nite::JOINT_RIGHT_SHOULDER, nite::JOINT_RIGHT_SHOULDER ) );      //5
    mBones.push_back( Bone( nite::JOINT_RIGHT_ELBOW,    nite::JOINT_RIGHT_ELBOW ) );         //6
    mBones.push_back( Bone( nite::JOINT_RIGHT_HAND,     nite::JOINT_RIGHT_HAND ) );          //7
    mBones.push_back( Bone( nite::JOINT_TORSO,          nite::JOINT_TORSO ) );               //8
    mBones.push_back( Bone( nite::JOINT_LEFT_HIP,		nite::JOINT_LEFT_HIP ) );            //9
    mBones.push_back( Bone( nite::JOINT_LEFT_KNEE,		nite::JOINT_LEFT_KNEE ) );          //10
    mBones.push_back( Bone( nite::JOINT_LEFT_FOOT,		nite::JOINT_LEFT_FOOT ) );          //11
    mBones.push_back( Bone( nite::JOINT_RIGHT_HIP,		nite::JOINT_RIGHT_HIP ) );          //12
    mBones.push_back( Bone( nite::JOINT_RIGHT_KNEE,		nite::JOINT_RIGHT_KNEE ) );         //13
    mBones.push_back( Bone( nite::JOINT_RIGHT_FOOT,		nite::JOINT_RIGHT_FOOT ) );         //14
    
    // DISTANCE LINES
    
    // hand to hand
    mBones.push_back( Bone( nite::JOINT_LEFT_HAND,	nite::JOINT_RIGHT_HAND ) );
    
    // limbs
    mBones.push_back( Bone( nite::JOINT_LEFT_HAND,	nite::JOINT_TORSO ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_HAND,	nite::JOINT_TORSO ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_FOOT,	nite::JOINT_RIGHT_HAND ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_FOOT,	nite::JOINT_LEFT_HAND ) );
    
    //surrounding body
    mBones.push_back( Bone( nite::JOINT_RIGHT_FOOT,	nite::JOINT_LEFT_FOOT ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_FOOT,	nite::JOINT_LEFT_HAND ) );
    mBones.push_back( Bone( nite::JOINT_LEFT_HAND,	nite::JOINT_HEAD ) );
    mBones.push_back( Bone( nite::JOINT_HEAD,	nite::JOINT_RIGHT_HAND ) );
    mBones.push_back( Bone( nite::JOINT_RIGHT_HAND,	nite::JOINT_RIGHT_FOOT) );
    
    mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f, 1.0f, 5000.0f );
    mCamera.lookAt( Vec3f::zero(), Vec3f::zAxis(), Vec3f::yAxis() );
    
    mDeviceManager = OpenNI::DeviceManager::create();
    try {
        mDevice = mDeviceManager->createDevice( OpenNI::DeviceOptions().enableUserTracking() );
    } catch ( OpenNI::ExcDeviceNotAvailable ex ) {
        console() << "exception with openni: " << ex.what() << endl;
        quit();
        return;
    }
    
    mDevice->getUserTracker().setSkeletonSmoothingFactor( 0.5f );
    mDevice->connectUserEventHandler( &UserApp::onUser, this );
    mDevice->start();
    
    // vector of trails
    for( int i=0; i<15; i++ ){
        mTrails.push_back(TrailPoint());
        mShowJoints.push_back(false);
//        mShowJoints[i] = false;
    }
    mShowJoints[0] = true;
    mColors.push_back( Color( 0.0f, 0.75f, 1.0f ) );
    mColors.push_back( Color( 1.0f, 0.08f, 0.58f) );
    mColors.push_back( Color( 1.0f, 0.0f, 1.0f ) );
    mColors.push_back( Color( 0.0f, 1.0f, 1.0f ) );
    mColors.push_back( Color( 0.0f, 1.0f, 0.0f ) );
    mColors.push_back( Color( 0.48f, 0.41f, 0.93f ) );
    mColors.push_back( Color( 0.6f, 0.2f, 0.8f ) );
    mColors.push_back( Color( 0.12f, 0.56f, 1.0f ) );
    mColors.push_back( Color( 0.0f, 0.81f, 0.82f ) );
    mColors.push_back( Color( 0.75f, 0.75f, 0.75f ) );
    mColors.push_back( Color( 0.54f, 0.17f, 0.87f ) );
    mColors.push_back( Color( 1.0f, 0.08f, 0.58f ) );
    mColors.push_back( Color( 1.0f, 1.0f, 1.0f ) );
    mColors.push_back( Color( 0.29f, 0.0f, 0.51f ) );
    mColors.push_back( Color( 0.0f, 0.0f, 1.0f ) );
    
    // params window
    mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 500 ), ColorA( 0.0f, 0.0f, 0.0f, 0.5f ) );
    mParams.addParam( "On Balance", &mUseBalance );
    mParams.addParam( "Negative Space", &mShowNegativeSpace );
    mParams.addParam( "Distance Lines", &mShowDistanceLines );
    
    
    //mParams.addText("the distance between A and B is" , dist);
    

    mParams.addText( " ");
    mParams.addText( "Follow joints:");
    
    vector<string> joints = { "Head", "Neck", "Left Shoulder", "Left Elbow", "Left Hand", "Right Shoulder", "Right Elbow", "Right Hand", "Torso", "Left Hip", "Left Knee", "Left Foot", "Right Hip",  "Right Knee",  "Right Foot" };
    for ( int i=0; i<joints.size(); i++ ) {
        Boolean *thing = &mShowJoints[i];
        mParams.addParam(joints[i], &mShowJoints[i]);
    }
    
}