Пример #1
0
void *freenect_threadfunc(void *arg)
{
	int accelCount = 0;

	freenect_set_tilt_degs(f_dev,freenect_angle);
	freenect_set_led(f_dev,LED_RED);
	freenect_set_depth_callback(f_dev, depth_cb);
	freenect_set_video_callback(f_dev, rgb_cb);
	freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, current_format));
	freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
	freenect_set_video_buffer(f_dev, rgb_back);

	freenect_start_depth(f_dev);
	freenect_start_video(f_dev);

	printf("'w' - tilt up, 's' - level, 'x' - tilt down, '0'-'6' - select LED mode, '+' & '-' - change IR intensity \n");
	printf("'f' - change video format, 'm' - mirror video, 'o' - rotate video with accelerometer \n");
	printf("'e' - auto exposure, 'b' - white balance, 'r' - raw color, 'n' - near mode (K4W only) \n");

	while (!die && freenect_process_events(f_ctx) >= 0) {
		//Throttle the text output
		if (accelCount++ >= 2000)
		{
			accelCount = 0;
			freenect_raw_tilt_state* state;
			freenect_update_tilt_state(f_dev);
			state = freenect_get_tilt_state(f_dev);
			double dx,dy,dz;
			freenect_get_mks_accel(state, &dx, &dy, &dz);
			printf("\r raw acceleration: %4d %4d %4d  mks acceleration: %4f %4f %4f", state->accelerometer_x, state->accelerometer_y, state->accelerometer_z, dx, dy, dz);
			fflush(stdout);
		}

		if (requested_format != current_format) {
			freenect_stop_video(f_dev);
			freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, requested_format));
			freenect_start_video(f_dev);
			current_format = requested_format;
		}
	}

	printf("\nshutting down streams...\n");

	freenect_stop_depth(f_dev);
	freenect_stop_video(f_dev);

	freenect_close_device(f_dev);
	freenect_shutdown(f_ctx);

	printf("-- done!\n");
	return NULL;
}
Пример #2
0
void *freenect_threadfunc(void *arg)
{
	printf("Freenect thread\n");
	int accelCount = 0;

	//freenect_set_tilt_degs(f_dev,freenect_angle);
	//freenect_set_led(f_dev,LED_RED);
	freenect_set_depth_callback(f_dev, depth_cb);
	freenect_set_video_callback(f_dev, rgb_cb);
	freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, current_format));
	freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
	freenect_set_video_buffer(f_dev, rgb_back);

	freenect_start_depth(f_dev);
	freenect_start_video(f_dev);

	printf("'w'-tilt up, 's'-level, 'x'-tilt down, '0'-'6'-select LED mode, 'f'-video format\n");

	while (!die && freenect_process_events(f_ctx) >= 0) {
		//Throttle the text output
		if (accelCount++ >= 2000)
		{
			accelCount = 0;
			//freenect_raw_tilt_state* state;
			//freenect_update_tilt_state(f_dev);
			//state = freenect_get_tilt_state(f_dev);
			double dx,dy,dz;
			//freenect_get_mks_accel(state, &dx, &dy, &dz);
			//printf("\r raw acceleration: %4d %4d %4d  mks acceleration: %4f %4f %4f", state->accelerometer_x, state->accelerometer_y, state->accelerometer_z, dx, dy, dz);
			fflush(stdout);
		}

		if (requested_format != current_format) {
			freenect_stop_video(f_dev);
			freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, requested_format));
			freenect_start_video(f_dev);
			current_format = requested_format;
		}
	}

	printf("\nshutting down streams...\n");

	freenect_stop_depth(f_dev);
	freenect_stop_video(f_dev);

	freenect_close_device(f_dev);
	freenect_shutdown(f_ctx);

	printf("-- done!\n");
	return NULL;
}
Пример #3
0
FREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct timeval *timeout)
{

    int res = fnusb_process_events_timeout(&ctx->usb, timeout);
    // Iterate over the devices in ctx.  If any of them are flagged as
    freenect_device* dev = ctx->first;
    while(dev) {
        if (dev->usb_cam.device_dead) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,"USB camera marked dead, stopping streams" );
            FN_ERROR("USB camera marked dead, stopping streams\n");
            res = -1;
            freenect_stop_video(dev);
            freenect_stop_depth(dev);
        }
#ifdef BUILD_AUDIO
        if (dev->usb_audio.device_dead) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,"USB audio marked dead, stopping streams" );
            FN_ERROR("USB audio marked dead, stopping streams\n");
            res = -1; // Or something else to tell the user that the device just vanished.
            freenect_stop_audio(dev);
        }
#endif
        dev = dev->next;
    }

    return res;
}
Пример #4
0
void init()
{
	freenect_context *ctx;
	freenect_device *dev;
	if (freenect_init(&ctx, 0)) {
		printf("Error: Cannot get context\n");
		return;
	}

	if (freenect_open_device(ctx, &dev, 0)) {
		printf("Error: Cannot get device\n");
		return;
	}
	freenect_set_depth_format(dev, FREENECT_DEPTH_11BIT);
	freenect_start_depth(dev);
	freenect_set_video_format(dev, FREENECT_VIDEO_RGB);
	freenect_start_video(dev);
	if (use_ffmpeg) {
		init_ffmpeg_streams();
		freenect_set_depth_callback(dev, depth_cb_ffmpeg);
		freenect_set_video_callback(dev, rgb_cb_ffmpeg);
	} else {
		freenect_set_depth_callback(dev, depth_cb);
		freenect_set_video_callback(dev, rgb_cb);
	}
	while (running && freenect_process_events(ctx) >= 0)
		snapshot_accel(dev);
	freenect_stop_depth(dev);
	freenect_stop_video(dev);
	freenect_close_device(dev);
	freenect_shutdown(ctx);
}
//----------------------------------------------------------------------------------------------------------------------
void KinectInterface::stopVideo()
{
    if(freenect_stop_video(m_dev) < 0)
    {
        throw std::runtime_error("Cannot stop RGB callback");
    }
}
//----------------------------------------------------------------------------------------------------------------------
void KinectInterface::setVideoMode(
                                                     int _mode
                                                    )
{
    freenect_video_format vm=FREENECT_VIDEO_RGB;
    switch(_mode)
    {
        case 0 : { vm=FREENECT_VIDEO_RGB; break;}
        case 1 : { vm=FREENECT_VIDEO_YUV_RGB; break;}
        case 2 : { vm=FREENECT_VIDEO_IR_8BIT; break;}
        /*
        /// had issues with these modes so sticking to the 3 that work
        case 1 : { vm=FREENECT_VIDEO_BAYER; break;}
        case 2 : { vm=FREENECT_VIDEO_IR_8BIT; break;}
        case 3 : { vm=FREENECT_VIDEO_IR_10BIT; break;}
        case 4 : { vm=FREENECT_VIDEO_IR_10BIT_PACKED; break;}
        case 5 : { vm=FREENECT_VIDEO_YUV_RGB; break;}
        case 6 : { vm=FREENECT_VIDEO_YUV_RAW; break;}
        */
        default : qDebug()<<"index out of bounds for video mode\n";
                            vm=FREENECT_VIDEO_RGB;
        break;
    }
    /// stop the video and set to new mode
    freenect_stop_video(m_dev);
    freenect_set_video_mode(m_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
    //deprecated
//	freenect_set_video_format(m_dev, vm);
    freenect_start_video(m_dev);
}
Пример #7
0
//---------------------------------------------------------------------------
void ofxKinect::threadedFunction(){

	if(currentLed < 0) { 
        freenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_GREEN); 
    }
	
	freenect_frame_mode videoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, bIsVideoInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_RGB);
	freenect_set_video_mode(kinectDevice, videoMode);
	freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, bUseRegistration?FREENECT_DEPTH_REGISTERED:FREENECT_DEPTH_MM);
	freenect_set_depth_mode(kinectDevice, depthMode);

	ofLogVerbose("ofxKinect") << "device " << deviceId << " " << serial << " connection opened";

	freenect_start_depth(kinectDevice);
	if(bGrabVideo) {
		freenect_start_video(kinectDevice);
	}

	while(isThreadRunning() && freenect_process_events(kinectContext.getContext()) >= 0) {        
		if(bTiltNeedsApplying) {
			freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
			bTiltNeedsApplying = false;
		}
		
		if(bLedNeedsApplying) {
			if(currentLed == ofxKinect::LED_DEFAULT) {
				freenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_GREEN);
			}
			else {
				freenect_set_led(kinectDevice, (freenect_led_options)currentLed);
			}
			bLedNeedsApplying = false;
		}

		freenect_update_tilt_state(kinectDevice);
		freenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);
		currentTiltAngleDeg = freenect_get_tilt_degs(tilt);

		rawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);

		double dx,dy,dz;
		freenect_get_mks_accel(tilt, &dx, &dy, &dz);
		mksAccel.set(dx, dy, dz);
	}
    
	// finish up a tilt on exit
	if(bTiltNeedsApplying) {
		freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
		bTiltNeedsApplying = false;
	}
    
	freenect_stop_depth(kinectDevice);
	freenect_stop_video(kinectDevice);
	if(currentLed < 0) {
        freenect_set_led(kinectDevice, (freenect_led_options)ofxKinect::LED_RED);
    }
    
	kinectContext.close(*this);
	ofLogVerbose("ofxKinect") << "device " << deviceId << " connection closed";
}
Пример #8
0
static void *init(void *unused)
{
	pending_runloop_tasks_wait_zero();
	pthread_mutex_lock(&runloop_lock);
	while (thread_running && freenect_process_events(ctx) >= 0) {
		pthread_mutex_unlock(&runloop_lock);
		// NOTE: This lets you run tasks while process_events isn't running
		pending_runloop_tasks_wait_zero();
		pthread_mutex_lock(&runloop_lock);
	}
	// Go through each device, call stop video, close device
	int i;
	for (i = 0; i < MAX_KINECTS; ++i) {
		if (kinects[i]) {
			freenect_stop_video(kinects[i]->dev);
			freenect_stop_depth(kinects[i]->dev);
			freenect_set_user(kinects[i]->dev, NULL);
			freenect_close_device(kinects[i]->dev);
			free_buffer_ring(&kinects[i]->video);
			free_buffer_ring(&kinects[i]->depth);
			free(kinects[i]);
			kinects[i] = NULL;
		}
	}
	freenect_shutdown(ctx);
	pthread_mutex_unlock(&runloop_lock);
	return NULL;
}
Пример #9
0
void kinect_finish(Kinect* kt){
	pthread_mutex_unlock(&G_kt.mutex);
	freenect_stop_depth(kt->dev);
	freenect_stop_video(kt->dev);
	freenect_close_device(kt->dev);
	freenect_shutdown(kt->ctx);
}
Пример #10
0
int KntStop(kntCtx_t * ctx) {
    ctx->isRunning = 0;
    pthread_join(ctx->thread, NULL);

    freenect_stop_depth(ctx->dev);
    freenect_stop_video(ctx->dev);
}
Пример #11
0
		void setVideoFormat(freenect_video_format requested_format) {
			if (requested_format != m_video_format) {
				freenect_stop_video(m_dev);
				if (freenect_set_video_format(m_dev, requested_format) < 0) throw std::runtime_error("Cannot set video format");
				freenect_start_video(m_dev);
				m_video_format = requested_format;
			}
		}
Пример #12
0
//---------------------------------------------------------------------------
void ofxKinect::threadedFunction(){	

	
	freenect_set_led(kinectDevice, LED_GREEN);
	freenect_set_video_format(kinectDevice, bInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_YUV_RGB);
	freenect_set_depth_format(kinectDevice, FREENECT_DEPTH_11BIT);
	
	ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection opened");

	freenect_start_depth(kinectDevice);
	if(bGrabVideo) {
		freenect_start_video(kinectDevice);
	}

	// call platform specific processors (needed for Win)
	if(freenect_process_events(kinectContext) != 0){
		ofLog(OF_LOG_ERROR, "ofxKinect: freenect_process_events failed!");
		return;
	}
	
	while(isThreadRunning()){
		if(bTiltNeedsApplying){
			freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
			bTiltNeedsApplying = false;
		}
        if(bLedNeedsApplying){
            freenect_set_led(kinectDevice, targetLedStatus);
            bLedNeedsApplying = false;
        }

		freenect_update_tilt_state(kinectDevice);
		freenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);

		rawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);
		
		double dx,dy,dz;
		freenect_get_mks_accel(tilt, &dx, &dy, &dz);
		mksAccel.set(dx, dy, dz);
		
		ofSleepMillis(10);

//		printf("\r raw acceleration: %4d %4d %4d  mks acceleration: %4f %4f %4f", ax, ay, az, dx, dy, dz);
	}
	
	// finish up a tilt on exit
	if(bTiltNeedsApplying){
		freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
		bTiltNeedsApplying = false;
	}

	freenect_stop_depth(kinectDevice);
	freenect_stop_video(kinectDevice);
	freenect_set_led(kinectDevice, LED_YELLOW);

	freenect_close_device(kinectDevice);
	
	ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection closed");
}
Пример #13
0
/*
 * Class:     org_ensor_robots_sensors_kinect_Device
 * Method:    nativeStopVideo
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_org_ensor_robots_sensors_kinect_Device_nativeStopVideo
  (JNIEnv *aJNIEnv, jobject aThisObject, jint aDeviceId)
{
    freenect_stop_video(f_devices[aDeviceId].f_dev);
    pthread_mutex_lock(&mutex);
    (*aJNIEnv)->DeleteGlobalRef(aJNIEnv, f_devices[aDeviceId].videobuffervalue);
    free(f_devices[aDeviceId].f_video_buffer);
    f_devices[aDeviceId].f_video_buffer = NULL;
    pthread_mutex_unlock(&mutex);
}
Пример #14
0
//---------------------------------------------------------------------------
void ofxKinect::threadedFunction(){

	freenect_set_led(kinectDevice, LED_GREEN);
	freenect_frame_mode videoMode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, bIsVideoInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_RGB);
	freenect_set_video_mode(kinectDevice, videoMode);
	freenect_frame_mode depthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, bUseRegistration?FREENECT_DEPTH_REGISTERED:FREENECT_DEPTH_MM);
	freenect_set_depth_mode(kinectDevice, depthMode);

	ofLog(OF_LOG_VERBOSE, "ofxKinect: Device %d %s connection opened", deviceId, serial.c_str());

	freenect_start_depth(kinectDevice);
	if(bGrabVideo) {
		freenect_start_video(kinectDevice);
	}

	// call platform specific processors (needed for Win)
	if(freenect_process_events(kinectContext.getContext()) != 0) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Device %d freenect_process_events failed!", deviceId);
		return;
	}

	while(isThreadRunning()) {
		if(bTiltNeedsApplying) {
			freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
			bTiltNeedsApplying = false;
		}

		freenect_update_tilt_state(kinectDevice);
		freenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);

		currentTiltAngleDeg = freenect_get_tilt_degs(tilt);

		rawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);

		double dx,dy,dz;
		freenect_get_mks_accel(tilt, &dx, &dy, &dz);
		mksAccel.set(dx, dy, dz);

		// ... and $0.02 for the scheduler
		ofSleepMillis(10);
	}

	// finish up a tilt on exit
	if(bTiltNeedsApplying) {
		freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
		bTiltNeedsApplying = false;
	}

	freenect_stop_depth(kinectDevice);
	freenect_stop_video(kinectDevice);
	freenect_set_led(kinectDevice, LED_YELLOW);

	kinectContext.close(*this);
	ofLog(OF_LOG_VERBOSE, "ofxKinect: Device %d connection closed", deviceId);
}
Пример #15
0
// the freenect thread. 
void *freenect_threadfunc(void *arg) {
	
	int accelCount = 0;
	
	freenect_set_tilt_degs(f_dev,freenect_angle);
	freenect_set_led(f_dev,LED_RED);
	freenect_set_depth_callback(f_dev, depth_cb);
	freenect_set_video_callback(f_dev, rgb_cb);
	freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, current_format));
	freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
	freenect_set_video_buffer(f_dev, rgb_back);
	
	freenect_start_depth(f_dev);
	freenect_start_video(f_dev);
	
	while (!die && freenect_process_events(f_ctx) >= 0) {
		if (accelCount++ >= 2000)
		{
			accelCount = 0;
			freenect_raw_tilt_state* state;
			freenect_update_tilt_state(f_dev);
			state = freenect_get_tilt_state(f_dev);
			double dx,dy,dz;
			freenect_get_mks_accel(state, &dx, &dy, &dz);
		}
		
		if (requested_format != current_format) {
			freenect_stop_video(f_dev);
			freenect_set_video_mode(f_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, requested_format));
			freenect_start_video(f_dev);
			current_format = requested_format;
		}
	}
	
	freenect_stop_depth(f_dev);
	freenect_stop_video(f_dev);
	
	freenect_close_device(f_dev);
	freenect_shutdown(f_ctx);

	return NULL;
}
Пример #16
0
static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt)
{
	freenect_stop_video(kinect->dev);
	free_buffer_ring(&kinect->video);
	if (alloc_buffer_ring_video(fmt, &kinect->video))
		return -1;
	freenect_set_video_mode(kinect->dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, fmt));
	freenect_set_video_buffer(kinect->dev, kinect->video.bufs[2]);
	freenect_start_video(kinect->dev);
	return 0;
}
Пример #17
0
static int change_video_format(sync_kinect_t *kinect, freenect_video_format fmt)
{
	freenect_stop_video(kinect->dev);
	free_buffer_ring(&kinect->video);
	if (alloc_buffer_ring_video(fmt, &kinect->video))
		return -1;
	freenect_set_video_format(kinect->dev, fmt);
	freenect_set_video_buffer(kinect->dev, kinect->video.bufs[2]);
	freenect_start_video(kinect->dev);
	return 0;
}
Пример #18
0
		void setVideoFormat(freenect_video_format requested_format, freenect_resolution requested_resolution = FREENECT_RESOLUTION_MEDIUM) {
			if (requested_format != m_video_format || requested_resolution != m_video_resolution) {
				freenect_stop_video(m_dev);
				freenect_frame_mode mode = freenect_find_video_mode(requested_resolution, requested_format);
				if (!mode.is_valid) throw std::runtime_error("Cannot set video format: invalid mode");
				if (freenect_set_video_mode(m_dev, mode) < 0) throw std::runtime_error("Cannot set video format");
				freenect_start_video(m_dev);
				m_video_format = requested_format;
				m_video_resolution = requested_resolution;
			}
		}
//----------------------------------------------------------------------------------------------------------------------
void KinectInterface::shutDownKinect()
{
    /// stop the processing thread
    m_process->setInActive();
    /// stop the video and depth callbacks
    freenect_stop_depth(m_dev);
    freenect_stop_video(m_dev);
    // close down our devices
    freenect_close_device(m_dev);
    freenect_shutdown(m_ctx);

}
Пример #20
0
int KinectFreenect::stop() {
    die = 1;
    freenect_stop_depth(f_dev);
    freenect_stop_video(f_dev);

    freenect_close_device(f_dev);
    freenect_shutdown(f_ctx);

    pthread_join(fnkt_thread, NULL);

    return 0;
}
Пример #21
0
void FreenectGrabber :: setIRMode(bool ir)
{
    if (!isConnected()) return;

    QWriteLocker locker(&m_lock);
    m_ir_mode = ir;
    freenect_stop_video(f_dev);
    if (!m_ir_mode)
        freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB);
    else
        freenect_set_video_format(f_dev, FREENECT_VIDEO_IR_8BIT);
    freenect_start_video(f_dev);
}
Пример #22
0
/* Function: mdlTerminate =====================================================
 * Abstract:
 *    In this function, you should perform any actions that are necessary
 *    at the termination of a simulation.  For example, if memory was
 *    allocated in mdlStart, this is the place to free it.
 */
static void mdlTerminate(SimStruct *S)
{
    SS_SimMode mode= ssGetSimMode(S);
    if(mode==0)
    {
        printf("Term\n");
        kinRunning= 0;
        freenect_stop_depth(kinDev);
        freenect_stop_video(kinDev);
        freenect_close_device(kinDev);
        freenect_shutdown(kinCtx);
    }
    
}
Пример #23
0
//---------------------------------------------------------------------------
void ofxKinect::threadedFunction() {


    freenect_set_led(kinectDevice, LED_GREEN);
    freenect_set_video_format(kinectDevice, bInfrared?FREENECT_VIDEO_IR_8BIT:FREENECT_VIDEO_RGB);
    freenect_set_depth_format(kinectDevice, FREENECT_DEPTH_11BIT);
    freenect_set_depth_callback(kinectDevice, &grabDepthFrame);
    freenect_set_video_callback(kinectDevice, &grabRgbFrame);

    ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection opened");

    freenect_start_depth(kinectDevice);
    freenect_start_video(kinectDevice);

    while (isThreadRunning()) {
        if( bTiltNeedsApplying ) {

            freenect_set_tilt_degs(kinectDevice, targetTiltAngleDeg);
            bTiltNeedsApplying = false;
        }

        freenect_update_tilt_state(kinectDevice);
        freenect_raw_tilt_state * tilt = freenect_get_tilt_state(kinectDevice);

        rawAccel.set(tilt->accelerometer_x, tilt->accelerometer_y, tilt->accelerometer_z);

        double dx,dy,dz;
        freenect_get_mks_accel(tilt, &dx, &dy, &dz);
        mksAccel.set(dx, dy, dz);

        ofSleepMillis(10);

//		printf("\r raw acceleration: %4d %4d %4d  mks acceleration: %4f %4f %4f", ax, ay, az, dx, dy, dz);
    }

//TODO: uncomment these when they are implemented in freenect
    freenect_set_tilt_degs(kinectDevice, 0);
    freenect_update_tilt_state(kinectDevice);
    freenect_stop_depth(kinectDevice);
    freenect_stop_video(kinectDevice);
    freenect_set_led(kinectDevice, LED_YELLOW);

    freenect_close_device(kinectDevice);
    freenect_shutdown(kinectContext);

    ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection closed");
}
Пример #24
0
/*
 * Class:     org_ensor_robots_sensors_kinect_Device
 * Method:    nativeClose
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_org_ensor_robots_sensors_kinect_Device_nativeClose
  (JNIEnv *aJNIEnv, jobject aThisObject, jint aDeviceId)
{
    
    pthread_mutex_lock(&mutex);
    if (f_devices[aDeviceId].f_video_buffer) {
        freenect_stop_video(f_devices[aDeviceId].f_dev);
        free(f_devices[aDeviceId].f_video_buffer);
        f_devices[aDeviceId].f_video_buffer = NULL;
    }
    if (f_devices[aDeviceId].f_depth_buffer) {
        freenect_stop_depth(f_devices[aDeviceId].f_dev);
        free(f_devices[aDeviceId].f_depth_buffer);
        f_devices[aDeviceId].f_depth_buffer = NULL;
    }
    freenect_close_device(f_devices[aDeviceId].f_dev);
    (*aJNIEnv)->DeleteGlobalRef(aJNIEnv, f_devices[aDeviceId].object);
    f_devices[aDeviceId].object = NULL;
    pthread_mutex_unlock(&mutex);
    
}
Пример #25
0
void kinect_thread(void* user) { 

  Kinect* kinect = static_cast<Kinect*>(user);
  if(!kinect) {
    printf("Error: kinect thread didn't receive a reference to the Kinect instance.\n");
    ::exit(EXIT_FAILURE);
  }

  freenect_device* dev = kinect->device;
  
  //freenect_set_tilt_degs(dev, 15);
  freenect_set_led(dev, LED_RED);
  freenect_set_depth_callback(dev, kinect_depth_callback);
  freenect_set_video_callback(dev, kinect_video_callback);
  freenect_set_video_mode(dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
  freenect_set_depth_mode(dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
  freenect_set_video_buffer(dev, kinect->rgb_back);
  freenect_set_depth_buffer(dev, kinect->depth_back);
  freenect_start_depth(dev);
  freenect_start_video(dev);

  bool must_stop = false;

  while(freenect_process_events(kinect->ctx) >= 0) {
        
    uv_mutex_lock(&kinect->mutex);
      must_stop = kinect->must_stop;
    uv_mutex_unlock(&kinect->mutex);

    if(must_stop) {
      break;
    }

  }
  
  freenect_set_led(dev, LED_GREEN);
  freenect_stop_depth(dev);
  freenect_stop_video(dev);
}
Пример #26
0
void init()
{
	freenect_context *ctx;
	freenect_device *dev;
	if (freenect_init(&ctx, 0)) {
		printf("Error: Cannot get context\n");
		return;
	}

	// fakenect doesn't support audio yet, so don't bother claiming the device
	freenect_select_subdevices(ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));

	if (freenect_open_device(ctx, &dev, 0)) {
		printf("Error: Cannot get device\n");
		return;
	}
	print_mode("Depth", freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
	print_mode("Video", freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
	freenect_set_depth_mode(dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
	freenect_start_depth(dev);
	freenect_set_video_mode(dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
	freenect_start_video(dev);
	if (use_ffmpeg) {
		init_ffmpeg_streams();
		freenect_set_depth_callback(dev, depth_cb_ffmpeg);
		freenect_set_video_callback(dev, rgb_cb_ffmpeg);
	} else {
		freenect_set_depth_callback(dev, depth_cb);
		freenect_set_video_callback(dev, rgb_cb);
	}
	while (running && freenect_process_events(ctx) >= 0)
		snapshot_accel(dev);
	freenect_stop_depth(dev);
	freenect_stop_video(dev);
	freenect_close_device(dev);
	freenect_shutdown(ctx);
}
Пример #27
0
Файл: core.c Проект: Nom1vk/pcl
FREENECTAPI int freenect_close_device(freenect_device *dev)
{
	freenect_context *ctx = dev->parent;
	int res;

	// stop streams, if active
	freenect_stop_depth(dev);
	freenect_stop_video(dev);

	res = fnusb_close_subdevices(dev);
	if (res < 0) {
		FN_ERROR("fnusb_close_subdevices failed: %d\n", res);
		return res;
	}

	freenect_device *last = NULL;
	freenect_device *cur = ctx->first;

	while (cur && cur != dev) {
		last = cur;
		cur = cur->next;
	}

	if (!cur) {
		FN_ERROR("device %p not found in linked list for this context!\n", dev);
		return -1;
	}

	if (last)
		last->next = cur->next;
	else
		ctx->first = cur->next;

	free(dev);
	return 0;
}
Пример #28
0
	void stop()
	{
		freenect_stop_depth(f_dev);
		freenect_stop_video(f_dev);
	}
Пример #29
0
		void stopVideo() {
			if(freenect_stop_video(m_dev) < 0) throw std::runtime_error("Cannot stop RGB callback");
		}
Пример #30
0
void *freenect_threadfunc(void *env) {
	int accelCount = 0;

	int status = (*gJavaVM)->AttachCurrentThread(gJavaVM, &env, NULL);

	freenect_set_tilt_degs(f_dev, current_tilt_angle);
	freenect_set_led(f_dev, current_led_option);
	freenect_set_depth_callback(f_dev, depth_cb);
	freenect_set_video_callback(f_dev, rgb_cb);
	freenect_set_video_mode(
			f_dev,
			freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM,
					current_format));
	freenect_set_depth_mode(
			f_dev,
			freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM,
					FREENECT_DEPTH_11BIT));
	freenect_set_video_buffer(f_dev, rgb_back);

	int depthS = freenect_start_depth(f_dev);
	int videoS = freenect_start_video(f_dev);
	__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG,
			"Depth start = %d Video start = %d ", depthS, videoS);

	sprintf(my_log, "Depth start = %d Video start = %d ", depthS, videoS);
	sendMsgToJava(env, my_log);

	__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Threaded...\n");
	sendMsgToJava(env, "Threaded...");

	while (!die && freenect_process_events(f_ctx) >= 0) {
		//Throttle the text output
		if (accelCount++ >= 2000) {

			accelCount = 0;
//			freenect_raw_tilt_state* state;
//			freenect_update_tilt_state(f_dev);
//			state = freenect_get_tilt_state(f_dev);
//			double dx, dy, dz;
//			freenect_get_mks_accel(state, &dx, &dy, &dz);
//
			freenect_set_led(f_dev, current_led_option);
			freenect_set_tilt_degs(f_dev, current_tilt_angle);
		}

		if (requested_format != current_format) {
			freenect_stop_video(f_dev);
			freenect_set_video_mode(
					f_dev,
					freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM,
							requested_format));
			freenect_start_video(f_dev);
			current_format = requested_format;
		}
	}

	__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "shutting down streams...");

	int statusD = (*gJavaVM)->DetachCurrentThread(gJavaVM);

	freenect_set_led(f_dev, LED_OFF);
	freenect_stop_depth(f_dev);
	freenect_stop_video(f_dev);

	freenect_close_device(f_dev);
	freenect_shutdown(f_ctx);

	closed - 1;
	return NULL;
}