//-------------------------------------------------------------- void testApp::update() { ofBackground(100, 100, 100); gui.update(); kinect.update(); if (kinect.isFrameNew()) { // compute Kinect frame rate computeFrameRate(); int nearThreshold = gui.getValueI("LO_THRESHOLD"); int farThreshold = gui.getValueI("HI_THRESHOLD"); colorImg.setFromPixels(kinect.getPixels(), KW,KH); colorImg.mirror(false, true); // Retrieve the current depth buffer. ofxCv8uC1_DepthRaw.setFromPixels(kinect.getDepthPixels(), KW,KH); ofxCv8uC1_DepthRaw.mirror(false, true); // Compute a double-ended threshold of the depth image ofxCv8uC1_ThreshN = ofxCv8uC1_DepthRaw; ofxCv8uC1_ThreshF = ofxCv8uC1_DepthRaw; ofxCv8uC1_ThreshN.threshold(nearThreshold, false); ofxCv8uC1_ThreshF.threshold(farThreshold, true); cvAnd( ofxCv8uC1_ThreshN.getCvImage(), ofxCv8uC1_ThreshF.getCvImage(), ofxCv8uC1_ThreshNF.getCvImage(), NULL); cvAnd( ofxCv8uC1_ThreshNF.getCvImage(), ofxCv8uC1_DepthRaw.getCvImage(), ofxCv8uC1_DepthRawThreshed.getCvImage(), NULL); ofxCv8uC1_Depth = ofxCv8uC1_DepthRawThreshed; bool bFillHolesUsingHistory = gui.getValueB("FILL_USING_HISTORY", 0); bool bFillHolesUsingContours = gui.getValueB("FILL_USING_CONTOURS", 0); bool bFillHolesUsingClosing = gui.getValueB("FILL_USING_CLOSING", 0); if (bFillHolesUsingHistory) { int depthHistory = gui.getValueI("N_HISTORY"); DHF.setDepthHistory(depthHistory); DHF.updatePreProcessingDepthHistory (ofxCv8uC1_Depth ); DHF.fillHolesUsingHistory (ofxCv8uC1_Depth); } if (bFillHolesUsingClosing) { int nClosingPasses = gui.getValueI("N_CLOSING_PASSES"); DHF.performMorphologicalClose(ofxCv8uC1_Depth,nClosingPasses); } if (bFillHolesUsingContours) { int maxContourHoleToFillArea = gui.getValueI("MAX_HOLE_AREA"); int maxNContoursToFill = gui.getValueI("MAX_N_CONTOURS_TO_FILL"); DHF.fillHolesUsingContourFinder (ofxCv8uC1_Depth, maxContourHoleToFillArea, maxNContoursToFill); } bComputeDepthHistogram = gui.getValueB("DO_HISTOGRAM", 0); if (bComputeDepthHistogram) { computeDepthHistogram (ofxCv8uC1_Depth); } } }
//-------------------------------------------------------------- void testApp::update() { ofBackground(100, 100, 100); gui.update(); kinect.update(); if (kinect.isFrameNew()){ // Compute Kinect frame rate computeFrameRate(); // Fetch control panel values int nearThreshold = gui.getValueI("LO_THRESHOLD"); int farThreshold = gui.getValueI("HI_THRESHOLD"); bool bMirrorHorizontally = gui.getValueB("MIRROR_HORIZONTAL", 0); bool bFillHolesUsingHistory = gui.getValueB("FILL_USING_HISTORY", 0); bool bFillHolesUsingContours = gui.getValueB("FILL_USING_CONTOURS", 0); bool bFillHolesUsingClosing = gui.getValueB("FILL_USING_CLOSING", 0); // Rescale the gray values into a range suitable for close use float nearCentimeters = 35.0; float farCentimeters = 130.0; kinect.getCalibration().setClippingInCentimeters(nearCentimeters, farCentimeters); // Retrieve the current depth buffer. ofxCv8uC1_DepthRaw.setFromPixels(kinect.getDepthPixels(), KW,KH); // Mirror horizontally if desired. ofxCv8uC1_DepthRaw.mirror(false, bMirrorHorizontally); // Compute a double-ended threshold of the depth image. ofxCv8uC1_ThreshN = ofxCv8uC1_DepthRaw; ofxCv8uC1_ThreshF = ofxCv8uC1_DepthRaw; ofxCv8uC1_ThreshN.threshold(nearThreshold, false); ofxCv8uC1_ThreshF.threshold(farThreshold, true); cvAnd( ofxCv8uC1_ThreshN.getCvImage(), ofxCv8uC1_ThreshF.getCvImage(), ofxCv8uC1_ThreshNF.getCvImage(), NULL); cvAnd( ofxCv8uC1_ThreshNF.getCvImage(), ofxCv8uC1_DepthRaw.getCvImage(), ofxCv8uC1_DepthRawThreshed.getCvImage(), NULL); ofxCv8uC1_Depth = ofxCv8uC1_DepthRawThreshed; if (bFillHolesUsingHistory){ int depthHistory = gui.getValueI("N_HISTORY"); DHF.setDepthHistory(depthHistory); DHF.updatePreProcessingDepthHistory (ofxCv8uC1_Depth ); DHF.fillHolesUsingHistory (ofxCv8uC1_Depth); } if (bFillHolesUsingClosing){ int nClosingPasses = gui.getValueI("N_CLOSING_PASSES"); DHF.performMorphologicalClose(ofxCv8uC1_Depth,nClosingPasses); } if (bFillHolesUsingContours){ int maxContourHoleToFillArea = gui.getValueI("MAX_HOLE_AREA"); int maxNContoursToFill = gui.getValueI("MAX_N_CONTOURS_TO_FILL"); int maxLevelDelta = gui.getValueI("MAX_DELTA_TO_FILL"); int maxHoleFillWidth = gui.getValueI("MAX_HOLE_FILL_WIDTH"); DHF.fillHolesUsingContourFinder (ofxCv8uC1_Depth, maxContourHoleToFillArea, maxNContoursToFill, maxLevelDelta, maxHoleFillWidth); } bComputeDepthHistogram = gui.getValueB("DO_HISTOGRAM", 0); if (bComputeDepthHistogram){ computeDepthHistogram (ofxCv8uC1_Depth); } } }