コード例 #1
0
//----------------------------------------------------------
void ofxKinect::update() {
	if(!bGrabberInited) {
		return;
	}

	if(!bNeedsUpdateVideo && !bNeedsUpdateDepth && !bGotData && tryCount < 5 && ofGetElapsedTimef() - timeSinceOpen > 2.0 ){
		close();
		ofLogWarning("ofxKinect") << "update(): device " << lastDeviceId << " isn't delivering data, reconnecting tries: " << tryCount+1;
		kinectContext.buildDeviceList();
		open(lastDeviceId);
		tryCount++;
		timeSinceOpen = ofGetElapsedTimef();
		return;
	}

	if(bNeedsUpdateVideo){
		bIsFrameNewVideo = true;
		bGotData = true;
		tryCount = 0;
		if(this->lock()) {
            if( videoPixels.getHeight() == videoPixelsIntra.getHeight() ){
                swap(videoPixels,videoPixelsIntra);
            }else{
                int minimumSize = MIN(videoPixels.size(), videoPixelsIntra.size());
                memcpy(videoPixels.getPixels(), videoPixelsIntra.getPixels(), minimumSize);
            }
			bNeedsUpdateVideo = false;
			this->unlock();
		}

		if(bUseTexture) {
			videoTex.loadData(videoPixels.getPixels(), width, height, bIsVideoInfrared?GL_LUMINANCE:GL_RGB);
		}
	} else {
		bIsFrameNewVideo = false;
	}

	if(bNeedsUpdateDepth){
		bIsFrameNewDepth = true;
		bGotData = true;
		tryCount = 0;
		if(this->lock()) {
			swap(depthPixelsRaw, depthPixelsRawIntra);
			bNeedsUpdateDepth = false;
			this->unlock();

			updateDepthPixels();
		}

		if(bUseTexture) {
			depthTex.loadData(depthPixels.getPixels(), width, height, GL_LUMINANCE);
		}
	} else {
		bIsFrameNewDepth = false;
	}

}
コード例 #2
0
ファイル: ofxKinect.cpp プロジェクト: CNCBASHER/ofxKinect
//----------------------------------------------------------
void ofxKinect::update() {
	if(!bGrabberInited) {
		return;
	}

	if(!bNeedsUpdate && !bGotData && tryCount < 5 && ofGetElapsedTimef() - timeSinceOpen > 2.0 ){
		close();
		ofLog(OF_LOG_WARNING, "ofxKinect: Device %d isn't delivering data, reconnecting tries: %d", lastDeviceId, tryCount+1);
		kinectContext.buildDeviceList();
		open(lastDeviceId);
		tryCount++;
		timeSinceOpen = ofGetElapsedTimef();
		return;
	}

	if(!bNeedsUpdate){
		return;
	} else {
		bIsFrameNew = true;
		bUpdateTex = true;
		bGotData = true;
		tryCount = 0;
	}

	if(this->lock()) {
		int n = width * height;

		depthPixelsRaw = depthPixelsRawBack;
		videoPixels = videoPixelsBack;

		// we have done the update
		bNeedsUpdate = false;

		this->unlock();

		updateDepthPixels();
	}

	if(bUseTexture) {
		depthTex.loadData(depthPixels.getPixels(), width, height, GL_LUMINANCE);
		videoTex.loadData(videoPixels.getPixels(), width, height, bIsVideoInfrared?GL_LUMINANCE:GL_RGB);
		bUpdateTex = false;
	}
}
コード例 #3
0
ファイル: ofxKinect.cpp プロジェクト: 2bbb/openFrameworks
//----------------------------------------------------------
void ofxKinect::update() {
	if(!bGrabberInited) {
		return;
	}
    
    // - Start handle reconnection
    
    //we need to do timing for reconnection based on the first update call
    //as a project with a long setup call could exceed the reconnectWaitTime and create a false positive
    //we also need to not try reconnection if the camera is tilting as this can shutoff the data coming in and cause a false positive. 
    if( bFirstUpdate || fabs(targetTiltAngleDeg-currentTiltAngleDeg) > 1.0 ){
        timeSinceOpen = ofGetElapsedTimef();
        bFirstUpdate = false;
    }
    
    //if we aren't grabbing the video stream we don't need to check for video
    bool bVideoOkay = true;
    if( bGrabVideo ){
        bVideoOkay = bGotDataVideo;
        if( bNeedsUpdateVideo ){
            bVideoOkay = true;
            bGotDataVideo = true;
        }
    }

    if( bNeedsUpdateDepth ){
        bGotDataDepth = true;
    }
    
    //try reconnect if we don't have color coming in or if we don't have depth coming in
	if( (!bVideoOkay || !bGotDataDepth ) && tryCount < 5 && ofGetElapsedTimef() - timeSinceOpen > reconnectWaitTime ){
		close();
		ofLogWarning("ofxKinect") << "update(): device " << lastDeviceIndex << " isn't delivering data. depth: " << bGotDataDepth << " color: " << bGotDataVideo <<"  , reconnecting tries: " << tryCount+1;
		kinectContext.buildDeviceList();
		open(lastDeviceIndex);
		tryCount++;
		timeSinceOpen = ofGetElapsedTimef();
	}

    // - End handle reconnection

	if(bNeedsUpdateVideo){
		bIsFrameNewVideo = true;
		tryCount = 0;
		if(this->lock()) {
            if( videoPixels.getHeight() == videoPixelsIntra.getHeight() ){
                swap(videoPixels,videoPixelsIntra);
            }else{
				int minimumSize = MIN(videoPixels.size(), videoPixelsIntra.size());
				memcpy(videoPixels.getData(), videoPixelsIntra.getData(), minimumSize);
            }
			bNeedsUpdateVideo = false;
			this->unlock();
		}

		if(bUseTexture) {
			videoTex.loadData(videoPixels);
		}
	} else {
		bIsFrameNewVideo = false;
	}

	if(bNeedsUpdateDepth){
		bIsFrameNewDepth = true;
		tryCount = 0;
		if(this->lock()) {
			swap(depthPixelsRaw, depthPixelsRawIntra);
			bNeedsUpdateDepth = false;
			this->unlock();

			updateDepthPixels();
		}

		if(bUseTexture) {
			depthTex.loadData(depthPixels);
		}
	} else {
		bIsFrameNewDepth = false;
	}

}