void BasicApp::setup() { gl::enable( GL_TEXTURE_2D ); mFrameRate = 0.0f; mFullScreen = false; mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->connectBodyIndexEventHandler( [ & ]( const Kinect2::BodyIndexFrame& frame ) { mChannelBodyIndex = frame.getChannel(); } ); mDevice->connectColorEventHandler( [ & ]( const Kinect2::ColorFrame& frame ) { mSurfaceColor = frame.getSurface(); } ); mDevice->connectDepthEventHandler( [ & ]( const Kinect2::DepthFrame& frame ) { mChannelDepth = frame.getChannel(); } ); mDevice->connectInfraredEventHandler( [ & ]( const Kinect2::InfraredFrame& frame ) { mChannelInfrared = frame.getChannel(); } ); mParams = params::InterfaceGl::create( "Params", ivec2( 200, 100 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addButton( "Quit", [ & ]() { quit(); } , "key=q" ); }
void FaceApp::setup() { gl::enableAlphaBlending(); mEnabledFace2d = true; mEnabledFace3d = true; mFrameRate = 0.0f; mFullScreen = false; mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->enableFaceMesh(); mDevice->connectBodyEventHandler( [ & ]( const Kinect2::BodyFrame frame ) { } ); mDevice->connectColorEventHandler( [ & ]( const Kinect2::ColorFrame frame ) { mSurface = frame.getSurface(); } ); mParams = params::InterfaceGl::create( "Params", Vec2i( 230, 130 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addParam( "2d face tracking", &mEnabledFace2d ).key( "2" ); mParams->addParam( "3d face tracking", &mEnabledFace3d ).key( "3" ); mParams->addButton( "Quit", [ & ]() { quit(); } , "key=q" ); }
void PointCloudApp::update() { mFrameRate = getAverageFps(); if ( mFullScreen != isFullScreen() ) { setFullScreen( mFullScreen ); mFullScreen = isFullScreen(); } if ( !mSurfaceDepthToCameraTable ) { mSurfaceDepthToCameraTable = mDevice->mapDepthToCameraTable(); } if ( ( mTimeStamp != mTimeStampPrev ) && mSurfaceColor && mChannelDepth ) { mTimeStampPrev = mTimeStamp; mSurfaceDepthToColorTable = Surface32f::create( mChannelDepth->getWidth(), mChannelDepth->getHeight(), false, SurfaceChannelOrder::RGB ); vector<ivec2> positions = mDevice->mapDepthToColor( mChannelDepth ); vec2 sz( Kinect2::ColorFrame().getSize() ); Surface32f::Iter iter = mSurfaceDepthToColorTable->getIter(); vector<ivec2>::iterator v = positions.begin(); while ( iter.line() ) { while ( iter.pixel() ) { iter.r() = (float)v->x / sz.x; iter.g() = 1.0f - (float)v->y / sz.y; iter.b() = 0.0f; ++v; } } } }
void _TBOX_PREFIX_App::setup() { mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->connectDepthEventHandler( [ & ]( const Kinect2::DepthFrame& frame ) { mChannel = frame.getChannel(); } ); }
void PointCloudApp::setup() { mCamUi = CameraUi(&mCam); gl::enable( GL_TEXTURE_2D ); mFrameRate = 0.0f; mFullScreen = false; mTimeStamp = 0L; mTimeStampPrev = mTimeStamp; loadGlsl(); mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->connectColorEventHandler( [ & ]( const Kinect2::ColorFrame& frame ) { mSurfaceColor = frame.getSurface(); } ); mDevice->connectDepthEventHandler( [ & ]( const Kinect2::DepthFrame& frame ) { mChannelDepth = frame.getChannel(); mTimeStamp = frame.getTimeStamp(); } ); ////////////////////////////////////////////////////////////////////////////////////////////// ivec2 sz = Kinect2::DepthFrame().getSize(); vector<vec2> vertices; for ( int32_t x = 0; x < sz.x; ++x ) { for ( int32_t y = 0; y < sz.y; ++y ) { vertices.push_back( vec2( x, y ) / vec2( sz ) ); } } gl::VboRef vbo = gl::Vbo::create( GL_ARRAY_BUFFER, vertices.size() * sizeof( vec2 ), &vertices[ 0 ], GL_STATIC_DRAW ); geom::BufferLayout layout; layout.append( geom::Attrib::POSITION, 2, sizeof( vec2 ), 0 ); vector<pair<geom::BufferLayout, gl::VboRef>> vertexArrayBuffers = { make_pair( layout, vbo ) }; mVboMesh = gl::VboMesh::create( vertices.size(), GL_POINTS, vertexArrayBuffers ); ////////////////////////////////////////////////////////////////////////////////////////////// mParams = params::InterfaceGl::create( "Params", ivec2( 200, 120 ) ); mParams->addParam( "Frame rate", &mFrameRate, "", true ); mParams->addParam( "Full screen", &mFullScreen ).key( "f" ); mParams->addButton( "Load GLSL", [ & ]() { loadGlsl(); }, "key=g" ); mParams->addButton( "Quit", [ & ]() { quit(); }, "key=q" ); resize(); }
void FaceApp::update() { mFrameRate = getAverageFps(); // Toggles streams by connecting and disconnecting events if ( mEnabledFace2d && !mDevice->isFace2dEventHandlerConnected() ) { mDevice->connectFace2dEventHandler( [ & ]( const Kinect2::Face2dFrame& frame ) { if ( !frame.getFaces().empty() ) { mFaces2d = frame.getFaces(); } } ); } else if ( !mEnabledFace2d && mDevice->isFace2dEventHandlerConnected() ) { mDevice->disconnectFace2dEventHandler(); mFaces2d.clear(); } if ( mEnabledFace3d && !mDevice->isFace3dEventHandlerConnected() ) { mDevice->connectFace3dEventHandler( [ & ]( const Kinect2::Face3dFrame& frame ) { if ( !frame.getFaces().empty() ) { mFaces3d = frame.getFaces(); } } ); } else if ( !mEnabledFace3d && mDevice->isFace3dEventHandlerConnected() ) { mDevice->disconnectFace3dEventHandler(); mFaces3d.clear(); } if ( mFullScreen != isFullScreen() ) { setFullScreen( mFullScreen ); mFullScreen = isFullScreen(); } }
void RibbonApp::setup() { // setup kinect mDevice = Kinect2::Device::create(); mDevice->start(); mDevice->connectBodyEventHandler( [ & ]( const Kinect2::BodyFrame frame ) { mBodyFrame = frame; } ); Rand::randomize(); mTrackingID = 0; mHand = Vec3f(0, 0, 0); mPoints.push_back(mHand); }
void FaceApp::draw() { gl::setViewport( getWindowBounds() ); gl::clear(); gl::setMatricesWindow( getWindowSize() ); if ( mSurface ) { gl::color( Colorf::white() ); gl::enable( GL_TEXTURE_2D ); gl::TextureRef tex = gl::Texture::create( mSurface ); gl::draw( tex, tex->getBounds(), Rectf( getWindowBounds() ) ); gl::disable( GL_TEXTURE_2D ); gl::pushMatrices(); gl::scale( Vec2f( getWindowSize() ) / Vec2f( mSurface.getSize() ) ); for ( const Kinect2::Face3d& face : mFaces3d ) { const TriMesh& mesh = face.getMesh(); if ( mesh.getNumIndices() > 0 ) { vector<Vec2f> verts; for ( const Vec3f& i : mesh.getVertices() ) { Vec2f v = mDevice->mapCameraToColor( i ); verts.push_back( v ); } gl::lineWidth( 0.5f ); gl::enableWireframe(); TriMesh2d mesh2d; mesh2d.appendIndices( &mesh.getIndices()[ 0 ], mesh.getNumIndices() ); mesh2d.appendVertices( &verts[ 0 ], mesh.getNumVertices() ); gl::draw( mesh2d ); gl::disableWireframe(); } } if ( mEnabledFace3d ) { gl::color( Colorf( 1.0f, 0.0f, 0.0f ) ); } else { gl::lineWidth( 2.0f ); } for ( const Kinect2::Face2d& face : mFaces2d ) { if ( face.isTracked() ) { gl::drawStrokedRect( face.getBoundsColor() ); for ( const Vec2f& i : face.getPointsColor() ) { gl::drawSolidCircle( i, 3.0f, 16 ); } } } gl::popMatrices(); } mParams->draw(); }