示例#1
0
//--------------------------------------------------------------------
bool ofxKinect::open(){
	if(!bGrabberInited){
		ofLog(OF_LOG_WARNING, "ofxKinect: Cannot open, init not called");
		return false;
	}
	
	int number_devices = freenect_num_devices(kinectContext);
    cout << "/n" <<number_devices<<" /n";
	if (number_devices < 1) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Did not find a device");
		return false;
	}
	
	if (freenect_open_device(kinectContext, &kinectDevice, 0) < 0) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device # 0 tru # 1");
		if (freenect_open_device(kinectContext, &kinectDevice, 1) < 0){
			ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device");
			return false;
		}
	} else{
		ofLog(OF_LOG_ERROR, "ofxKinect: was able open device # 0");	
	}
	freenect_set_user(kinectDevice, this);
	freenect_set_depth_callback(kinectDevice, &grabDepthFrame);
	freenect_set_video_callback(kinectDevice, &grabRgbFrame);
	
	startThread(true, false);	// blocking, not verbose
	
	return true;
}
示例#2
0
bool ofxKinectContext::open(ofxKinect& kinect, int id) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLog(OF_LOG_WARNING, "ofxKinect: No available devices found");
		return false;
	}
	
	// is the id available?
	if(id < 0) {
		id = nextAvailableId();
	}
	if(isConnected(id)) {
		ofLog(OF_LOG_WARNING, "ofxKinect: Device %d already connected", id);
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device(kinectContext, &kinect.kinectDevice, id) < 0) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device %d", id);
		return false;
	}
	kinects.insert(pair<int,ofxKinect*>(id, &kinect));
	
	// set kinect id & serial from bus id
	int index = getDeviceIndex(id);
	kinect.deviceId = id;
	kinect.serial = deviceList[index].serial;

	return true;
}
示例#3
0
int main( int argc, char **argv )
{
	//depth_gl = (uint8_t*)malloc(640*480*3);
	if( freenect_init( &f_context, NULL ) < 0 )
	{
		printf( "Freenect initialization failed.\n" );
		return 1;
	}
	freenect_set_log_level( f_context, FREENECT_LOG_DEBUG );
	freenect_select_subdevices( f_context, ( freenect_device_flags )( FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA ) );
	if( freenect_num_devices ( f_context ) < 1 )
	{
		printf( "No devices found. Shutting down...\n" );
		freenect_shutdown( f_context );
		return 1;
	}
	if( freenect_open_device( f_context, &f_device, 0 ) <0 )
	{
		printf( "Couldn't open device. Shutting down...\n" );
		freenect_shutdown( f_context );
		return 1;	
	}
	if( pthread_create( &f_thread, NULL, f_threadfunc, NULL  ) )
	{
		printf( "Thread creation failed. Shutting down...\n" );
		freenect_shutdown( f_context );
		return 1;
	}
	glutInit( &argc, argv );
	gl_threadfunc( NULL );
	return 0;
}
JNIEXPORT void JNICALL Java_com_libfreenect_KinectRGBCamera_captureRawImage (JNIEnv * e, jobject o) {

    env = e;
    obj = o;
    
    freenect_context *f_ctx;
	freenect_device *f_dev;

	printf("Kinect camera test\n");

	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
	}

	if (freenect_open_device(f_ctx, &f_dev, 0) < 0) {
		printf("Could not open device\n");
	}

    printf("Set RGB Callback");
    freenect_set_rgb_callback(f_dev, rgb_cb);

    printf("Starting RGB");
	freenect_start_rgb(f_dev);
	
	while(freenect_process_events(f_ctx) >= 0 );

	freenect_close_device(f_dev);

}
示例#5
0
bool ofxKinectContext::open(ofxKinect& kinect, int id) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLogWarning("ofxKinect") << "no available devices found";
		return false;
	}
	
	// is the id available?
	if(id < 0) {
		id = nextAvailableId();
	}
	if(isConnected(id)) {
		ofLogWarning("ofxKinect") << "device " << id << " already connected";
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device(kinectContext, &kinect.kinectDevice, id) < 0) {
		ofLogError("ofxKinect") << "could not open device " <<  id;
		return false;
	}
	kinects.insert(pair<int,ofxKinect*>(id, &kinect));
	
	// set kinect id & serial from bus id
	kinect.deviceId = id;
	kinect.serial = deviceList[getDeviceIndex(id)].serial;

	return true;
}
示例#6
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);
}
示例#7
0
bool FreenectGrabber :: connectToDevice()
{
    if (m_connected)
        return true;

    if (freenect_init(&f_ctx, NULL) < 0)
    {
        ntk_dbg(0) << "freenect_init() failed";
        return false;
    }
    ntk_dbg(0) << "Connecting to device: " << m_device_id;
    if (freenect_open_device(f_ctx, &f_dev, m_device_id) < 0)
    {
        ntk_dbg(0) << "freenect_open_device() failed";
        return false;
    }

    freenect_set_user(f_dev, this);

    freenect_set_depth_callback(f_dev, kinect_depth_db);
    freenect_set_video_callback(f_dev, kinect_video_db);

    this->setIRMode(m_ir_mode);
    m_connected = true;
    return true;
}
示例#8
0
//--------------------------------------------------------------------
bool ofxKinect::open() {
    if(!bGrabberInited) {
        ofLog(OF_LOG_WARNING, "ofxKinect: Cannot open, init not called");
        return false;
    }

    if (freenect_init(&kinectContext, NULL) < 0) {
        ofLog(OF_LOG_ERROR, "ofxKinect: freenet_init failed");
        return false;
    }

    int number_devices = freenect_num_devices(kinectContext);
    ofLog(OF_LOG_VERBOSE, "ofxKinect: Number of Devices found: " + ofToString(number_devices));

    if (number_devices < 1) {
        ofLog(OF_LOG_ERROR, "ofxKinect: Did not find a device");
        return false;
    }

    if (freenect_open_device(kinectContext, &kinectDevice, 0) < 0) {
        ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device");
        return false;
    }

    freenect_set_user(kinectDevice, this);

    startThread(true, false);	// blocking, not verbose

    return true;
}
int KinectControl::initDevice(unsigned int _user_device_number) {
	printf("KinectControl. initing the device.\n");	
	
	user_device_number = _user_device_number;
	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		this->errorCode = 4;
		errorString = "Could not open device";

		printf("%s\n", errorString.c_str());
		freenect_shutdown(f_ctx);
		return this->errorCode;
	} else {
		printf("Kinect device opened.\n");
		isInited = true;

	}

	
	int res;
	res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
	if (res) {
		errorString = "pthread_create failed";
		printf("%s\n",errorString.c_str());
		freenect_shutdown(f_ctx);
		this->errorCode = 5;
		return this->errorCode;
	} else {
		printf("Kinect thread created.\n");
	}

	
	
	return res;
}
示例#10
0
文件: sensor.c 项目: samfoo/sentry
int main(int argc, char **argv) {
    init_cv_buffers();

    context = init_kinect();
    if (context == NULL) {
        return 1;
    }

    if (freenect_open_device(context, &device, 0) < 0) {
        printf("could not open device\n");
        freenect_shutdown(context);

        return 1;
    }

    int capture_loop_failed = pthread_create(&kinect_thread, NULL, capture_loop, NULL);
    if (capture_loop_failed) {
        printf("pthread_create failed\n");
        freenect_shutdown(context);

        return 1;
    }

    handle_sigint();

    graphics_loop(argc, argv);
    pthread_join(kinect_thread, NULL);
    printf("thanks for shooting down quads!\n");
}
示例#11
0
	bool initCamera()
	{
		
		if (freenect_init(&f_ctx, NULL) < 0) {
			printf("freenect_init() failed\n");
			return false;
		}
		freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);
		freenect_select_subdevices(f_ctx, (freenect_device_flags)(FREENECT_DEVICE_CAMERA));
		
		int nr_devices = freenect_num_devices (f_ctx);
		printf ("Number of devices found: %d\n", nr_devices);
		
		int user_device_number = 0;
		
		if (nr_devices < 1)
			return false;
		
		if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
			printf("Could not open device\n");
			return false;
		}
		
		int accelCount = 0;
		
		freenect_set_depth_callback(f_dev, depth_cb);
		freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
		freenect_set_user(f_dev, (void*)this);
	}
示例#12
0
int main(int argc, char **argv)
{
	int res;

	depth_mid = (uint8_t*)malloc(640*480*3);
	depth_front = (uint8_t*)malloc(640*480*3);
	rgb_back = (uint8_t*)malloc(640*480*3);
	rgb_mid = (uint8_t*)malloc(640*480*3);
	rgb_front = (uint8_t*)malloc(640*480*3);

	printf("Kinect camera test\n");

	int i;
	for (i=0; i<2048; i++) {
		float v = i/2048.0;
		v = powf(v, 3)* 6;
		t_gamma[i] = v*6*256;
	}

	g_argc = argc;
	g_argv = argv;

	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}

	freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);
	freenect_select_subdevices(f_ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));

	int nr_devices = freenect_num_devices (f_ctx);
	printf ("Number of devices found: %d\n", nr_devices);

	int user_device_number = 0;
	if (argc > 1)
		user_device_number = atoi(argv[1]);

	if (nr_devices < 1) {
		freenect_shutdown(f_ctx);
		return 1;
	}

	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		printf("Could not open device\n");
		freenect_shutdown(f_ctx);
		return 1;
	}

	res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
	if (res) {
		printf("pthread_create failed\n");
		freenect_shutdown(f_ctx);
		return 1;
	}

	// OS X requires GLUT to run on the main thread
	gl_threadfunc(NULL);

	return 0;
}
示例#13
0
		FreenectDevice(freenect_context *_ctx, int _index) {
			if(freenect_open_device(_ctx, &m_dev, _index) != 0) throw std::runtime_error("Cannot open Kinect");
			freenect_set_user(m_dev, this);
			freenect_set_rgb_format(m_dev, FREENECT_FORMAT_RGB);
			freenect_set_depth_format(m_dev, FREENECT_FORMAT_11_BIT);
			freenect_set_depth_callback(m_dev, freenect_depth_callback);
			freenect_set_rgb_callback(m_dev, freenect_rgb_callback);
		}
示例#14
0
		FreenectDevice(freenect_context *_ctx, int _index) {
			if(freenect_open_device(_ctx, &m_dev, _index) < 0) throw std::runtime_error("Cannot open Kinect");
			freenect_set_user(m_dev, this);
			freenect_set_video_format(m_dev, FREENECT_VIDEO_RGB);
			freenect_set_depth_format(m_dev, FREENECT_DEPTH_11BIT);
			freenect_set_depth_callback(m_dev, freenect_depth_callback);
			freenect_set_video_callback(m_dev, freenect_video_callback);
		}
示例#15
0
jboolean openSync(JNIEnv* env) {
	__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Start Sync");
	sendMsgToJava(NULL, "Starting Sync...");

	int res;
	depth_mid = (uint8_t*) malloc(640 * 480 * 4);
	depth_front = (uint8_t*) malloc(640 * 480 * 3);
	rgb_back = (uint8_t*) malloc(640 * 480 * 3);
	rgb_mid = (uint8_t*) malloc(640 * 480 * 3);
	rgb_front = (uint8_t*) malloc(640 * 480 * 3);

	int i;
	for (i = 0; i < 2048; i++) {
		float v = i / 2048.0;
		v = powf(v, 3) * 6;
		t_gamma[i] = v * 6 * 256;
	}
	//init  kinect context
	if (freenect_init(&f_ctx, NULL) < 0) {
		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
				"Kinect open sync failed\n");
		sendMsgToJava(env, "Kinect open sync failed");
		return FALSE;
	}
	//settup
	freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);
	freenect_select_subdevices(
			f_ctx,
			(freenect_device_flags) (FREENECT_DEVICE_MOTOR
					| FREENECT_DEVICE_CAMERA));
	//get num dev
	int nr_devices = freenect_num_devices(f_ctx);

	sprintf(my_log, "Number of Devices found %d\n", nr_devices);
	sendMsgToJava(env, my_log);
	__android_log_print(ANDROID_LOG_INFO, LOG_TAG, my_log);

	int user_device_number = 0;

	if (nr_devices < 1)
		return FALSE;

	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Cannot Open device\n");
		sendMsgToJava(env, "Cannot Open device");
		return FALSE;
	}
//create thread
	res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, env);
	if (res) {
		__android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
				"pthread_create failed...\n");
		sendMsgToJava(env, "pthread_create failed...");
		return FALSE;
	}

	return TRUE;
}
示例#16
0
文件: kinect.c 项目: MaNDRaXe/kinect
int main() {
  freenect_context *f_ctx;
  freenect_device *f_dev;

  if (freenect_init(&f_ctx, NULL) < 0) {
    fprintf(stderr, "freenect_init() failed\n");
    return 1;
  }

  freenect_select_subdevices(f_ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));

  if (freenect_num_devices(f_ctx) < 1) {
    fprintf(stderr, "no devices found\n");
    freenect_shutdown(f_ctx);
    return 1;
  }

  if (freenect_open_device(f_ctx, &f_dev, 0) < 0) {
    fprintf(stderr, "can't open device\n");
    freenect_shutdown(f_ctx);
    return 1;
  }

  depth_image = image_create(640, 480);

  freenect_set_led(f_dev, LED_GREEN);
  freenect_set_depth_callback(f_dev, capture_depth_image);
  freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
  freenect_start_depth(f_dev);

  if (signal(SIGINT, handle_interrupt) == SIG_IGN) {
    signal(SIGINT, SIG_IGN);
  }

  if (signal(SIGTERM, handle_interrupt) == SIG_IGN) {
    signal(SIGTERM, SIG_IGN);
  }

  fprintf(stdout, "\x1B[2J");

  while (running && freenect_process_events(f_ctx) >= 0) {
    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);

    fprintf(stdout, "\x1B[1;1H");
    draw_depth_image(stdout, w.ws_col, w.ws_row - 1);
  }

  freenect_stop_depth(f_dev);
  freenect_set_led(f_dev, LED_OFF);
  freenect_close_device(f_dev);
  freenect_shutdown(f_ctx);

  image_destroy(depth_image);

  return 0;
}
示例#17
0
bool Kinect::setup() {

  if(ctx) {
    printf("Error: the freenect context has been setup already.\n");
    return false;
  }

  if(freenect_init(&ctx, NULL) < 0) {
    printf("Error: cannot init libfreenect.\n");
    return false;
  }

  freenect_set_log_level(ctx, FREENECT_LOG_DEBUG);

  int ndevices = freenect_num_devices(ctx);
  if(ndevices < 1) {
    printf("Error: cannot find a kinect. @todo cleanup mem.\n");
    freenect_shutdown(ctx);
    ctx = NULL;
    return false;
  }

  printf("Number of found kinect devices: %d\n", ndevices);

  freenect_select_subdevices(ctx, (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA));
  //freenect_select_subdevices(ctx, (freenect_device_flags)( FREENECT_DEVICE_CAMERA));

  int devnum = 0;
  if(freenect_open_device(ctx, &device, devnum) < 0) {
    printf("Error: cannot open device: %d\n", devnum);
    freenect_shutdown(ctx);
    ctx = NULL;
    return false;
  }

  freenect_set_user(device, this);

  uint32_t w = 640;
  uint32_t h = 480;
  uint32_t nbytes = w * h * 3;
  nbytes_rgb = nbytes;
  rgb_back = new uint8_t[nbytes];
  rgb_mid = new uint8_t[nbytes];
  rgb_front = new uint8_t[nbytes];
  depth_back = new uint8_t[nbytes];
  depth_mid = new uint8_t[nbytes];
  depth_front = new uint8_t[nbytes];

  uv_mutex_lock(&mutex);
    must_stop = false;
  uv_mutex_unlock(&mutex);

  uv_thread_create(&thread, kinect_thread, this);

  return true;
}
示例#18
0
		FreenectDevice(freenect_context *_ctx, int _index)
			: m_video_resolution(FREENECT_RESOLUTION_MEDIUM), m_depth_resolution(FREENECT_RESOLUTION_MEDIUM)
		{
			if(freenect_open_device(_ctx, &m_dev, _index) < 0) throw std::runtime_error("Cannot open Kinect");
			freenect_set_user(m_dev, this);
			setVideoFormat(FREENECT_VIDEO_RGB,   FREENECT_RESOLUTION_MEDIUM);
			setDepthFormat(FREENECT_DEPTH_REGISTERED, FREENECT_RESOLUTION_MEDIUM);
			freenect_set_depth_callback(m_dev, freenect_depth_callback);
			freenect_set_video_callback(m_dev, freenect_video_callback);
		}
		FreenectDevice(freenect_context *_ctx, int _index)
			: m_video_resolution(FREENECT_RESOLUTION_MEDIUM), m_depth_resolution(FREENECT_RESOLUTION_MEDIUM)
		{
			if(freenect_open_device(_ctx, &m_dev, _index) < 0) throw std::runtime_error("Cannot open Kinect");
			freenect_set_user(m_dev, this);
			freenect_set_video_mode(m_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
			freenect_set_depth_mode(m_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT));
			freenect_set_depth_callback(m_dev, freenect_depth_callback);
			freenect_set_video_callback(m_dev, freenect_video_callback);
		}
示例#20
0
int main(int argc, char **argv)
{
	int res;

	printf("Kinect camera test\n");

	int i;
	for (i=0; i<2048; i++) {
		float v = i/2048.0;
		v = powf(v, 3)* 6;
		t_gamma[i] = v*6*256;
	}

	g_argc = argc;
	g_argv = argv;

	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}

	freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);

	int nr_devices = freenect_num_devices (f_ctx);
	printf ("Number of devices found: %d\n", nr_devices);

	int user_device_number = 0;
	if (argc > 1)
		user_device_number = atoi(argv[1]);

	if (nr_devices < 1)
		return 1;

	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		printf("Could not open device\n");
		return 1;
	}

	res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
	if (res) {
		printf("pthread_create failed\n");
		return 1;
	}

	// OS X requires GLUT to run on the main thread
	gl_threadfunc(NULL);

	return 0;
}
示例#21
0
int main(int argc, char** argv) {
	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}
	freenect_set_log_level(f_ctx, FREENECT_LOG_INFO);
	freenect_select_subdevices(f_ctx, FREENECT_DEVICE_AUDIO);

	int nr_devices = freenect_num_devices (f_ctx);
	printf ("Number of devices found: %d\n", nr_devices);
	if (nr_devices < 1) {
		freenect_shutdown(f_ctx);
		return 1;
	}

	int user_device_number = 0;
	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		printf("Could not open device\n");
		freenect_shutdown(f_ctx);
		return 1;
	}

	state.max_samples = 256 * 60;
	state.current_idx = 0;
	state.buffers[0] = (int32_t*)malloc(state.max_samples * sizeof(int32_t));
	state.buffers[1] = (int32_t*)malloc(state.max_samples * sizeof(int32_t));
	state.buffers[2] = (int32_t*)malloc(state.max_samples * sizeof(int32_t));
	state.buffers[3] = (int32_t*)malloc(state.max_samples * sizeof(int32_t));
	memset(state.buffers[0], 0, state.max_samples * sizeof(int32_t));
	memset(state.buffers[1], 0, state.max_samples * sizeof(int32_t));
	memset(state.buffers[2], 0, state.max_samples * sizeof(int32_t));
	memset(state.buffers[3], 0, state.max_samples * sizeof(int32_t));
	freenect_set_user(f_dev, &state);

	freenect_set_audio_in_callback(f_dev, in_callback);
	freenect_start_audio(f_dev);

	int res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
	if (res) {
		printf("pthread_create failed\n");
		freenect_shutdown(f_ctx);
		return 1;
	}
	ros::init(argc, argv, "kinect_audio");
	MicView mv;
	mv.spin();

	return 0;
}
JNIEXPORT jlong JNICALL Java_org_openkinect_Context_jniOpenDevice
(JNIEnv *env, jobject obj, jint index)
{
    freenect_context *f_ctx = context(env, obj);

    freenect_device *f_dev = 0;
    if(freenect_open_device(f_ctx, &f_dev, index) < 0)
    {
        return 0;
    }

    freenect_set_video_callback(f_dev, rgb_cb);
    freenect_set_depth_callback(f_dev, depth_cb);

    return (jlong) f_dev;
}
示例#23
0
int main(int argc, char **argv)
{
	int i, res;
	for (i=0; i<2048; i++) {
		float v = i/2048.0;
		v = powf(v, 3)* 6;
		t_gamma[i] = v*6*256;
	}
	
	g_argc = argc;
	g_argv = argv;
	
	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}
	
	freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);
	
	int nr_devices = freenect_num_devices (f_ctx);
	printf ("Number of devices found: %d\n", nr_devices);
	
	int user_device_number = 0;
	if (argc > 1)
		user_device_number = atoi(argv[1]);
	
	if (nr_devices < 1)
		return 1;
	
	if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
		printf("Could not open device\n");
		return 1;
	}
	
	if ( network_init() < 0 )
		return -1;
	
	res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
	if (res) {
		printf("pthread_create failed\n");
		return 1;
	}

	while(!die && freenect_process_events(f_ctx) >= 0 );
	
	return 0;
}
示例#24
0
  /* Function: mdlStart =======================================================
   * Abstract:
   *    This function is called once at start of model execution. If you
   *    have states that should be initialized once, this is the place
   *    to do it.
   */
  static void mdlStart(SimStruct *S)
  {
    SS_SimMode mode= ssGetSimMode(S);
    if(mode==0)
    {
        kinFail=0;
        kinRunning=1;
        newFrame=0;
//change
        memset (kinR,'1',307200);
        memset (kinG,'1',307200);
        memset (kinB,'1',307200);
        memset (kinD,'1',307200);


        
        
        /*-----INIT---------------*/

        if (freenect_init(&kinCtx, 0)) {
            printf("Error: Cannot get context\n");
            kinFail=1;
            return;
        }

        if (freenect_open_device(kinCtx, &kinDev, 0)) {
            printf("Error: Cannot get device\n");
            kinFail=1;
            return;
        }
        freenect_set_depth_format(kinDev, FREENECT_DEPTH_11BIT);
        freenect_start_depth(kinDev);
//change
        freenect_set_video_format(kinDev, FREENECT_VIDEO_YUV_RGB);
        freenect_start_video(kinDev);
        freenect_set_depth_callback(kinDev, depth_cb);
        freenect_set_video_callback(kinDev, rgb_cb);

        /*-----END INIT------------*/

        pthread_create( &kinThread, NULL, runLoop, NULL);
    }
    
    
    
  }
示例#25
0
int initFreenect() {
  //  int res = 0;

  //setup Freenect...
  if (freenect_init(&f_ctx, NULL) < 0) {
    printf("freenect_init() failed\n");
    return 1;
  }

  freenect_set_log_level(f_ctx, FREENECT_LOG_ERROR);

  int nr_devices = freenect_num_devices (f_ctx);
  printf ("Number of devices found: %d\n", nr_devices);

  int user_device_number = 0;
  //  if (argc > 1)
  //    user_device_number = atoi(argv[1]);
  //
  //  if (nr_devices < 1)
  //    return 1;

  if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
    printf("Could not open device\n");
    return 1;
  }

  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_rgb_callback(f_dev, rgb_cb);
  //freenect_set_rgb_format(f_dev, FREENECT_FORMAT_RGB);
  freenect_set_video_callback(f_dev, rgb_cb);
  freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB);
  freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);

  freenect_start_depth(f_dev);
  freenect_start_video(f_dev);

  //start the freenect thread to poll for events
  //  res = pthread_create(&ocv_thread, NULL, freenect_threadfunc, NULL);
  //  if (res) {
  //    printf("pthread_create failed\n");
  //    return 1;
  //  }
  return 0;
}
示例#26
0
/*
 * Main method; primarily just initializes our thread and handles Kinect details.
 */
int main(int argc, char **argv)
{
	freenect_context *f_ctx;
	freenect_device *f_dev;

	display = 0;

	int res = 0;
	int die = 0;
	printf("Code Red Kinect Vision init\n");

	if (argc > 1 && strcmp(argv[1],"--display") == 0) {
		display = 1;
	}
			
	if (freenect_init(&f_ctx, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}

	if (freenect_open_device(f_ctx, &f_dev, 0) < 0) {
		printf("Could not open device\n");
		return 1;
	}


	if (display) { cvNamedWindow( FREENECTOPENCV_WINDOW_N, CV_WINDOW_AUTOSIZE ); }
	rgbimg = cvCreateImage(cvSize(FREENECTOPENCV_RGB_WIDTH, FREENECTOPENCV_RGB_HEIGHT), IPL_DEPTH_8U, FREENECTOPENCV_IR_DEPTH);
	tempimg = cvCreateImage(cvSize(FREENECTOPENCV_RGB_WIDTH, FREENECTOPENCV_RGB_HEIGHT), IPL_DEPTH_8U, FREENECTOPENCV_RGB_DEPTH);

	// create opencv display thread
	res = pthread_create(&cv_thread, NULL, cv_threadfunc, (void*) tempimg);
	if (res) {
		printf("pthread_create failed\n");
		return 1;
	}

	freenect_set_video_callback(f_dev, rgb_cb);
	freenect_set_video_format(f_dev, FREENECT_VIDEO_IR_8BIT);

	printf("init done\n");

	freenect_start_video(f_dev);

	while(!die && freenect_process_events(f_ctx) >= 0 );
}
示例#27
0
int main(int argc, char **argv)
{
	ros::init(argc, argv, "kinect_motor");

	freenect_context * context = 0;
	if (freenect_init(&context, NULL) < 0) {
		ROS_ERROR("freenect_init() failed");
		return 1;
	}

	freenect_set_log_level(context, FREENECT_LOG_DEBUG);
	freenect_select_subdevices(context, (freenect_device_flags)(FREENECT_DEVICE_MOTOR));

	int devicesCout = freenect_num_devices (context);
	ROS_INFO("Number of devices found: %d", devicesCout);

	if (devicesCout < 1) {
		freenect_shutdown(context);
		return 1;
	}

	ROS_INFO("Connecting to device: 1");

	if (freenect_open_device(context, &device, 0) < 0) {
		printf("Could not open device\n");
		freenect_shutdown(context);
		return 1;
	}

	freenect_set_tilt_degs(device, 0);

	ros::NodeHandle nodeHandleForAngle;
	ros::Subscriber angleSubscriber = nodeHandleForAngle.subscribe("angle", 10, Angle);

	ros::NodeHandle nodeHandleForLed;
	ros::Subscriber ledSubscriber = nodeHandleForLed.subscribe("led", 10, Led);

	ros::spin();

	freenect_close_device(device);
	freenect_shutdown(context);

	return 0;
}
示例#28
0
文件: kkcd.c 项目: dlowe/kkcd
int main(int argc, char **argv) {
    freenect_context *fc;
    freenect_device *fd;

    if (freenect_init(&fc, 0) < 0) {
        printf("failed to init freenect\n");
        exit(1);
    }

    if (freenect_num_devices(fc) < 1) {
        printf("no kinect found\n");
        freenect_shutdown(fc);
        exit(1);
    }

    if (freenect_open_device(fc, &fd, 0) < 0) {
        printf("unable to open device 0\n");
        freenect_shutdown(fc);
        exit(1);
    }

    double want;
    while (1) {
        want = 30.0;
        freenect_set_tilt_degs(fd, want);
        freenect_set_led(fd, LED_RED);
        while (fabs(freenect_get_tilt_degs(freenect_get_tilt_state(fd)) - want) > 1) {
            freenect_update_tilt_state(fd);
            usleep(1000);
        }

        want = -30.0;
        freenect_set_tilt_degs(fd, want);
        freenect_set_led(fd, LED_GREEN);
        while (fabs(freenect_get_tilt_degs(freenect_get_tilt_state(fd)) - want) > 1) {
            freenect_update_tilt_state(fd);
            usleep(1000);
        }
    }

    freenect_close_device(fd);
    freenect_shutdown(fc);
    exit(0);
}
示例#29
0
int main(int argc, char** argv)
{
	ros::init(argc, argv, "kinect_audio");

	freenect_context * contex;
	if (freenect_init(&contex, NULL) < 0) {
		printf("freenect_init() failed\n");
		return 1;
	}
	freenect_set_log_level(contex, FREENECT_LOG_SPEW);
	freenect_select_subdevices(contex, FREENECT_DEVICE_AUDIO);

	int nr_devices = freenect_num_devices(contex);
	printf ("Number of devices found: %d\n", nr_devices);
	if (nr_devices < 1) {
		freenect_shutdown(contex);
		return 1;
	}

	freenect_device * device;
	int deviceNumber = 0;
	if (freenect_open_device(contex, &device, deviceNumber) < 0) {
		printf("Could not open device\n");
		freenect_shutdown(contex);
		return 1;
	}

	freenect_set_audio_in_callback(device, callback);
	freenect_start_audio(device);
	signal(SIGINT, cleanup);

	audioPublisher = ros::NodeHandle().advertise<kinect_audio::audio>("audio", 10);

	while(!die && freenect_process_events(contex) >= 0) {
		// If we did anything else, it might go here.
		// Alternately, we might split off another thread
		// to do this loop while the main thread did something
		// interesting.
	}

	freenect_shutdown(contex);
	return 0;
}
示例#30
0
int main (int argc, char **argv) {
    // Initalize the ROS node
    ros::init(argc, argv, "kinect_base_node");
    ros::NodeHandle n;
    // Initalize the Freenect Context
    if (freenect_init (&f_ctx, NULL) < 0) {
        ROS_INFO("freenect_init() failed\n");
        return 1;
    }
    freenect_set_log_level (f_ctx, FREENECT_LOG_INFO);
    // Scan for kinect devices
    int nr_devices = freenect_num_devices (f_ctx);
    ROS_INFO("Number of devices found: %d\n", nr_devices);
    // Get the device number
    if (argc > 1) user_device_number = atoi (argv[1]);
    if (nr_devices < 1) return 1;
    // Calculate the kinect node base name
    std::stringstream kinect_node_base;
    kinect_node_base << "/kinect_base_node/" << user_device_number << "/";
    // Open the base portion of the Kinect
    if (freenect_open_device (f_ctx, &f_dev, user_device_number) < 0) {
        ROS_INFO("Could not open device\n");
        return 1;
    }
    // Get the defaults 
    double  tiltDefaultPosition = 0.0;
    double  imuDefaultDuration = 1.0;
    int     ledDefaultState = LED_BLINK_GREEN;
    n.getParam(kinect_node_base.str() + "tilt", tiltDefaultPosition);
    n.getParam(kinect_node_base.str() + "led", ledDefaultState);
    n.getParam(kinect_node_base.str() + "imuDuration", imuDefaultDuration);
    // Set the default kinect state
    freenect_set_tilt_degs(f_dev, tiltDefaultPosition);
    freenect_set_led(f_dev, (freenect_led_options) ledDefaultState);
    // Create the provided services
    ros::Subscriber subTilt = n.subscribe(kinect_node_base.str() + "tilt", 1000, tilt_received_callback);
    ros::Subscriber subLED = n.subscribe(kinect_node_base.str() + "led", 1000, led_received_callback);
    imu_publisher = n.advertise<sensor_msgs::Imu>(kinect_node_base.str() + "imu", 1000);
    ros::Timer imu_publish_timer = n.createTimer(ros::Duration(imuDefaultDuration), imu_publish_data);
    ros::spin();   
    return 0;
}