//--------------------------------------------------------------------------- void ofxKinect::threadedFunction(){ openKinect(); while (isThreadRunning()) { if ( lock() ) { rc = kinectContext->WaitOneUpdateAll(depth); if (rc != XN_STATUS_OK) { printf("UpdateData failed: %s\n", xnGetStatusString(rc)); return; } depth.GetMetaData(depthMD); if (bImage){ image.GetMetaData(imageMD); const XnUInt8* pImage = imageMD.Data(); videoPixelsBack=(unsigned char*)imageMD.Data(); }else{ for (int i=0;i<users.size();i++){ userGenerator.GetUserPixels(users[i]->userID,sceneMD); const XnLabel* pLabels=sceneMD.Data(); //color silhouette for (int p=0;p<640*480*3;p++){ videoPixelsBack[p]=0; if (pLabels[p/3]>0 ){ if (p%3==pLabels[p/3]-1) videoPixelsBack[p]=128; } } } } const XnDepthPixel* pImageIR = depthMD.Data(); memcpy(depthPixelsBack, depthMD.Data(), depthMD.XRes()*depthMD.YRes() * sizeof(unsigned short)); //unsigned short maxValue=2048; thisKinect->bNeedsUpdate = true; unlock(); ofSleepMillis(20); } } kinectContext->Shutdown(); free(kinectContext); ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection closed"); }
//-------------------------------------------------------------------------------- bool ofxKinectV2::open(string serial) { close(); params.setName("kinectV2_" + serial); int retVal = openKinect(serial); if (retVal == 0) startThread(true); else return false; bOpened = true; return true; }
bool KinectGrabber::setup(){ // settings and defaults storedframes = 0; kinect.init(); kinect.setRegistration(true); // To have correspondance between RGB and depth images kinect.setUseTexture(false); width = kinect.getWidth(); height = kinect.getHeight(); kinectDepthImage.allocate(width, height, 1); filteredframe.allocate(width, height, 1); kinectColorImage.allocate(width, height); kinectColorImage.setUseTexture(false); return openKinect(); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(30); gpuBlur = NULL; useKinect = false; kinectOpen = false; cameraOpen = false; learnBG = false; showGui = false; inputWidth = 640; inputHeight = 480; guiPath = "guisettings.xml"; if (ofxKinect::numAvailableDevices() >= 1) { cout << "using kinect" << endl; openKinect(); useKinect = true; } else { cout << "using camera" << endl; openCamera(); useKinect = false; } colorImg.allocate(inputWidth, inputHeight); grayImage.allocate(inputWidth, inputHeight); grayImagePrev.allocate(inputWidth, inputHeight); grayThreshNear.allocate(inputWidth, inputHeight); grayThreshFar.allocate(inputWidth, inputHeight); grayBg.allocate(inputWidth, inputHeight); nearThreshold = 255; farThreshold = 45; setupGpuBlur(inputWidth, inputHeight); #ifdef USE_OFX_SOUNDSTREAM xss.setDeviceId(0); xss.setup(0, 1, this, 44100, fftLive.getBufferSize(), 4); #else xss.setup(this, 0, 1, 44100, fftLive.getBufferSize(), 4); #endif fftLive.setMirrorData(audioMirror); lows = 0; nbins = (int)(fftLive.getBufferSize() * 0.5); rawFFT = new float[nbins]; setupColorMesh(); colors.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA); updateColors(); drawmode = 0; gui.setup("Settings", guiPath, 20, 20); gui.add(audioThreshold.setup("audioThreshold", 0.5, 0.0, 1.0)); gui.add(audioPeakDecay.setup("audioPeakDecay", 0.95, 0.0, 1.0)); gui.add(audioMaxDecay.setup("audioMaxDecay", 1.0, 0.0, 1.0)); gui.add(audioMirror.setup("audioMirror", false)); gui.add(nearThreshold.setup("nearThreshold", 255, 0, 255)); gui.add(farThreshold.setup("farThreshold", 45, 0, 255)); gui.add(blobMin.setup("blobMin", 2000, 200, 20000)); gui.add(mirrorInput.setup("mirrorInput", true)); gui.add(drawFPS.setup("FPS", true)); gui.add(useGPU.setup("GPUBlur", true)); gui.add(triangleMax.setup("triangleMax", 15, 3, 60)); gui.add(glowExtra.setup("glowExtra", 1.0, 0.0, 10.0)); gui.add(lineWidth.setup("lineWidth", 10.0, 1.0, 20.0)); gui.add(jitterSize.setup("jitterSize", 0.5, 0.0, 2.0)); gui.loadFromFile(guiPath); }