//-------------------------------------------------------------- void ofApp::setup(){ kinect.open(); kinect.initDepthSource(); kinect.initColorSource(); kinect.initInfraredSource(); kinect.initBodyIndexSource(); kinect.initBodySource(); gui.init(); //setup a gui panel for the 3D view auto worldView = gui.addWorld("World"); worldView->onDrawWorld += [this](ofCamera &) { this->kinect.drawWorld(); }; //setup a gui panel for every kinect source auto sources = kinect.getSources(); for(auto source : sources) { auto sourceWithTexture = dynamic_pointer_cast<ofBaseHasTexture>(source); if (sourceWithTexture) { auto panel = gui.add(sourceWithTexture->getTexture(), source->getTypeName()); //if it's the colour panel, let's do something special by writing some info on top auto colorSource = dynamic_pointer_cast<ofxKFW2::Source::Color>(source); if (colorSource) { panel->onDraw += [colorSource] (ofxCvGui::DrawArguments &) { stringstream message; message << "Exposure : " << colorSource->getExposure() << "us" << endl; message << "FrameInterval : " << colorSource->getFrameInterval() << "us" << endl; message << "Gain : " << colorSource->getGain() << endl; message << "Gamma : " << colorSource->getGamma() << endl; ofxCvGui::Utils::drawText(message.str(), 20, 60); }; } //if it's the depth panel, set some scaling auto depthSource = dynamic_pointer_cast<ofxKFW2::Source::Depth>(source); if (depthSource) { auto style = make_shared<ofxCvGui::Panels::Texture::Style>(); style->rangeMaximum = 0.25f; panel->setStyle(style); } //if it's the body index panel, let's draw the joints on top auto bodyIndexSource = dynamic_pointer_cast<ofxKFW2::Source::BodyIndex>(source); if(bodyIndexSource) { panel->onDrawImage += [this](ofxCvGui::DrawImageArguments & args) { auto bodySource = this->kinect.getBodySource(); const auto & bodies = bodySource->getBodies(); ofPushStyle(); { ofColor color(200, 100, 100); int index = 0; for (const auto & body : bodies) { color.setHueAngle((index * 50) % 360); ofSetColor(color); for (const auto & joint : body.joints) { ofDrawCircle(joint.second.getPositionInDepthMap(), 5); } index++; } } ofPopStyle(); }; } } } //if we press the 'c' key on the World panel, then toggle the camera's cursor. This works best when you fullscreen that panel worldView->onKeyboard += [this, worldView] (ofxCvGui::KeyboardArguments & args) { if (args.action == ofxCvGui::KeyboardArguments::Action::Pressed && args.key =='c') { worldView->getCamera().toggleCursorDrawEnabled(); } }; }
//-------------------------------------------------------------- void ofApp::setup() { kinect.open(); kinect.initDepth(); kinect.initColor(); kinect.initInfrared(); kinect.initBodyIndex(); gui.init(); //setup a gui panel for every kinect source auto sources = kinect.getSources(); for(auto source : sources) { auto drawingSource = dynamic_pointer_cast<ofBaseDraws>(source); ofxCvGui::PanelPtr panel; if (drawingSource) { panel = gui.add(*drawingSource, source->getTypeName()); auto colorSource = dynamic_pointer_cast<ofxKFW2::Source::Color>(source); if (colorSource) { panel->onDraw += [colorSource] (ofxCvGui::DrawArguments &) { stringstream message; message << "Exposure : " << colorSource->getExposure() << "us" << endl; message << "FrameInterval : " << colorSource->getFrameInterval() << "us" << endl; message << "Gain : " << colorSource->getGain() << endl; message << "Gamma : " << colorSource->getGamma() << endl; ofxCvGui::Utils::drawText(message.str(), 20, 60); }; } } } auto worldView = gui.addWorld("World"); worldView->onDrawWorld += [this] (ofCamera &) { //setup some point cloud properties for kicks glPushAttrib(GL_POINT_BIT); glPointSize(5.0f); glEnable(GL_POINT_SMOOTH); ofPushStyle(); //bind kinect color camera texture and draw mesh from depth (which has texture coordinates) this->kinect.getColor()->getTextureReference().bind(); //draw point cloud this->mesh.drawVertices(); //draw triangles ofSetColor(255, 150); this->mesh.drawWireframe(); //draw fills faded ofSetColor(255, 50); this->mesh.drawFaces(); //unbind colour camera this->kinect.getColor()->getTextureReference().unbind(); ofPopStyle(); //clear the point cloud drawing attributes glPopAttrib(); //draw the view cones of depth and colour cameras ofPushStyle(); ofNoFill(); ofSetLineWidth(2.0f); ofSetColor(100, 200, 100); this->kinect.getDepth()->drawFrustum(); ofSetColor(200, 100, 100); this->kinect.getColor()->drawFrustum(); ofPopStyle(); }; //if we press the 'c' key on the World panel, then toggle the camera's cursor. This works best when you fullscreen that panel worldView->onKeyboard += [this, worldView] (ofxCvGui::KeyboardArguments & args) { if (args.action == ofxCvGui::KeyboardArguments::Action::Pressed && args.key =='c') { worldView->getCamera().toggleCursorDraw(); } }; }