//-------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------- 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; }
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; }
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); }
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; }
KinectControl::KinectControl() { printf("\nKinectControl Init\n"); errorCode = 0; isInited = false; if (kinectControlRef != NULL) { errorCode = 1; errorString = "KinectControl Already Started."; printf("%s.\n",errorString.c_str()); return; } for (int i=0; i<2048; i++) { float v = i/2048.0; v = powf(v, 3)* 6; t_gamma[i] = v*6*256; } kinectControlRef = this; freenect_angle = 0; user_device_number = -1; requested_format = FREENECT_VIDEO_RGB; current_format = FREENECT_VIDEO_RGB; //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); depth_mid = NULL; memset(depth_front,0,(640*480*3)); memset(rgb_back,0,(640*480*3)); memset(rgb_mid,0,(640*480*3)); memset(rgb_front,0,(640*480*3)); if (freenect_init(&f_ctx, NULL) < 0) { errorCode = 2; errorString = "freenect_init() failed."; printf("%s\n",errorString.c_str()); return; } else { printf("freenect_init() OK\n"); } 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); // check if there were no device found. if (nr_devices < 0) { freenect_shutdown(f_ctx); errorCode = 3; errorString = "No freenect devices found!"; printf("%s\n", errorString.c_str()); } }
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; }
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; }
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; }
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; }
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; }
//-------------------------------------------------------------------- bool ofxKinect::init(bool infrared, bool video, bool texture){ if(isConnected()){ ofLog(OF_LOG_WARNING, "ofxKinect: Do not call init while ofxKinect is running!"); return false; } clear(); bInfrared = infrared; bGrabVideo = video; bytespp = infrared?1:3; calibration.init(bytespp); bUseTexture = texture; int length = width*height; depthPixelsRaw = new unsigned short[length]; depthPixelsBack = new unsigned short[length]; videoPixels = new unsigned char[length*bytespp]; // pixels.setFromExternalPixels(videoPixels, width, height, OF_IMAGE_COLOR); videoPixelsBack = new unsigned char[length*bytespp]; memset(depthPixelsRaw, 0, length*sizeof(unsigned short)); memset(depthPixelsBack, 0, length*sizeof(unsigned short)); memset(videoPixels, 0, length*bytespp*sizeof(unsigned char)); memset(videoPixelsBack, 0, length*bytespp*sizeof(unsigned char)); if(bUseTexture){ depthTex.allocate(width, height, GL_LUMINANCE); videoTex.allocate(width, height, infrared?GL_LUMINANCE:GL_RGB); } if (freenect_init(&kinectContext, NULL) < 0){ ofLog(OF_LOG_ERROR, "ofxKinect: freenet_init failed"); return false; } ofLog(OF_LOG_VERBOSE, "ofxKinect: Inited"); int number_devices = freenect_num_devices(kinectContext); ofLog(OF_LOG_VERBOSE, "ofxKinect: Number of Devices found: " + ofToString(number_devices)); bGrabberInited = true; return bGrabberInited; }
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; }
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; }
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; }
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); }
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; }
int KinectFreenect::start() { if (freenect_init(&f_ctx, NULL) < 0) { printf("freenect_init() failed\n"); return 1; } int nr_devices = freenect_num_devices(f_ctx); int user_device_number = 0; if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) { printf("Could not open device.\n"); return 1; } freenect_set_led(f_dev, LED_RED); freenect_set_depth_callback(f_dev, KinectFreenect::depth_cb); freenect_set_video_callback(f_dev, KinectFreenect::rgb_cb); freenect_set_video_mode(f_dev, freenect_find_video_mode(current_resolution, current_format)); freenect_set_depth_mode(f_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT)); freenect_start_depth(f_dev); freenect_start_video(f_dev); int res; res = pthread_create(&fnkt_thread, NULL, freenect_threadfunc, NULL); if (res) { printf("pthread_create failed\n"); return 1; } int status = 0; while (!die && status >= 0) { char k = cvWaitKey(5); if( k == 27 ) { die = 1; break; } } return 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; }
//--------------------------------------------------------------------------- void ofxKinect::threadedFunction(){ if (freenect_init(&kinectContext, NULL) < 0) { ofLog(OF_LOG_ERROR, "ofxKinect: freenet_init failed"); } 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: didnt find a device"); return; } if (freenect_open_device(kinectContext, &kinectDevice, 0) < 0) { ofLog(OF_LOG_ERROR, "ofxKinect: could not open device"); return; } freenect_set_led(kinectDevice, LED_GREEN); freenect_set_depth_callback(kinectDevice, &grabDepthFrame); freenect_set_rgb_callback(kinectDevice, &grabRgbFrame); freenect_set_rgb_format(kinectDevice, FREENECT_FORMAT_RGB); freenect_set_depth_format(kinectDevice, FREENECT_FORMAT_11_BIT); ofLog(OF_LOG_VERBOSE, "ofxKinect: Connection opened"); freenect_start_depth(kinectDevice); freenect_start_rgb(kinectDevice); while (isThreadRunning()) { int16_t ax,ay,az; freenect_get_raw_accelerometers(kinectDevice, &ax, &ay, &az); rawAccel.set(ax, ay, az); double dx,dy,dz; freenect_get_mks_accelerometers(kinectDevice, &dx, &dy, &dz); mksAccel.set(dx, dy, dz); // printf("\r raw acceleration: %4d %4d %4d mks acceleration: %4f %4f %4f", ax, ay, az, dx, dy, dz); } }
int audio_setup(){ 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) 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"); return 1; } freenect_set_audio_in_callback(f_dev, in_callback); freenect_start_audio(f_dev); return 0; }
/* * Class: org_ensor_robots_sensors_kinect_Driver * Method: nativeInit * Signature: ()V */ JNIEXPORT jint JNICALL Java_org_ensor_robots_sensors_kinect_Driver_nativeInit (JNIEnv *aJNIEnv, jobject aThisObject) { f_running = 0; (*aJNIEnv)->GetJavaVM(aJNIEnv, &jvm); int rc = freenect_init(&f_ctx, NULL); if (rc == 0) { f_device_count = freenect_num_devices(f_ctx); if (f_device_count > 0) { f_devices = malloc(sizeof(jfreenect_device_t)*f_device_count); int i; for (i = 0; i < f_device_count; i++) { f_devices[i].f_dev = NULL; f_devices[i].f_depth_buffer = NULL; f_devices[i].f_video_buffer = NULL; f_devices[i].object = NULL; } f_running = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); int res = pthread_create(&f_thread, &attr, freenect_threadfunc, NULL); pthread_attr_destroy(&attr); } else { f_devices = NULL; } } freenect_select_subdevices(f_ctx, (freenect_device_flags)( FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA)); }
t_jit_err jit_freenect_grab_get_ndevices(t_jit_freenect_grab *x, void *attr, long *ac, t_atom **av){ if ((*ac)&&(*av)) { } else { *ac = 1; if (!(*av = jit_getbytes(sizeof(t_atom)*(*ac)))) { *ac = 0; return JIT_ERR_OUT_OF_MEM; } } if(f_ctx){ x->ndevices = freenect_num_devices(f_ctx); } else{ x->ndevices = 0; } jit_atom_setlong(*av,x->ndevices); return JIT_ERR_NONE; }
int main(int argc, char **argv) { int res; //initGPIO(); bool pin = pollGPIO(); printf("GPIO pin = %d\n", pin); int data_dir_number = 0; sprintf(data_dir, "%s/%d", DATA_DIR, data_dir_number); struct stat st; while(stat(data_dir,&st) == 0){ data_dir_number++; sprintf(data_dir, "%s/%d", DATA_DIR, data_dir_number); } mkdir(data_dir, S_IREAD | S_IWRITE | S_IEXEC); printf("Data dir is: %s\n", data_dir); depth_back = malloc(640*480*2); depth_mid = malloc(640*480*2); depth_front = malloc(640*480*2); rgb_back = malloc(640*480*3); rgb_mid = malloc(640*480*3); rgb_front = 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_FATAL); 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); //closeGPIO(); return 0; }
int deviceCount() { return freenect_num_devices(m_ctx); }
int main(int argc, char *argv[]) { struct kingrid_info data; freenect_context *kn; freenect_device *kn_dev; int rows = 40, cols = 96; // terminal size int opt; sigdata = &data; data.out_of_range = 0; data.done = 0; data.divisions = 6; data.boxwidth = 10; data.histrows = 8; data.frame = 0; data.zmin = 0.5; data.zmax = 5.0; data.disp_mode = STATS; if(getenv("LINES")) { rows = atoi(getenv("LINES")); } if(getenv("COLUMNS")) { cols = atoi(getenv("COLUMNS")); } // Handle command-line options while((opt = getopt(argc, argv, "shag:z:Z:")) != -1) { switch(opt) { case 's': // Stats mode data.disp_mode = STATS; break; case 'h': // Histogram mode data.disp_mode = HISTOGRAM; break; case 'a': // ASCII art mode data.disp_mode = ASCII; break; case 'g': // Grid divisions data.divisions = atoi(optarg); break; case 'z': // Near clipping data.zmin = atof(optarg); break; case 'Z': // Far clipping data.zmax = atof(optarg); break; default: fprintf(stderr, "Usage: %s -[sha] [-g divisions] [-zZ distance]\n", argv[0]); fprintf(stderr, "Use up to one of:\n"); fprintf(stderr, "\ts - Stats mode (default)\n"); fprintf(stderr, "\th - Histogram mode\n"); fprintf(stderr, "\ta - ASCII art mode\n"); fprintf(stderr, "Use any of:\n"); fprintf(stderr, "\tg - Set grid divisions for both dimensions\n"); fprintf(stderr, "\tz - Set near clipping plane in meters for ASCII art mode (default 0.5)\n"); fprintf(stderr, "\tZ - Set far clipping plane in meters for ASCII art mode (default 5.0)\n"); return -1; } } data.boxwidth = (cols - 1) / data.divisions - 3; if(data.boxwidth < 10) { data.boxwidth = 10; } data.histrows = (rows - 2) / data.divisions - 1; init_lut(data.depth_lut); if(signal(SIGINT, intr) == SIG_ERR || signal(SIGTERM, intr) == SIG_ERR) { ERROR_OUT("Error setting signal handlers\n"); return -1; } if(freenect_init(&kn, NULL) < 0) { ERROR_OUT("libfreenect init failed.\n"); return -1; } INFO_OUT("Found %d Kinect devices.\n", freenect_num_devices(kn)); if(freenect_num_devices(kn) == 0) { ERROR_OUT("No Kinect devices present.\n"); return -1; } if(freenect_open_device(kn, &kn_dev, 0)) { ERROR_OUT("Error opening Kinect #0.\n"); return -1; } freenect_set_user(kn_dev, &data); freenect_set_tilt_degs(kn_dev, -5); freenect_set_led(kn_dev, LED_GREEN); freenect_set_depth_callback(kn_dev, depth); freenect_set_depth_format(kn_dev, FREENECT_DEPTH_11BIT); freenect_start_depth(kn_dev); int last_oor = data.out_of_range; while(!data.done && freenect_process_events(kn) >= 0) { if(last_oor != data.out_of_range) { freenect_set_led(kn_dev, data.out_of_range ? LED_BLINK_RED_YELLOW : LED_GREEN); last_oor = data.out_of_range; } } freenect_stop_depth(kn_dev); freenect_set_led(kn_dev, LED_OFF); freenect_close_device(kn_dev); freenect_shutdown(kn); return 0; }
int ofxKinectContext::numAvailable() { if(!isInited()) init(); return freenect_num_devices(kinectContext) - kinects.size(); }
void qKinect::doStartGrabbing() { assert(m_app); if (!m_app) return; f_ctx=0; f_dev=0; s_grabIndex=0; if (m_kDlg) delete m_kDlg; m_kDlg=0; s_max_depth_count = 0; if (s_depth_data) delete[] s_depth_data; s_depth_count = 0; s_depth_data = 0; s_wDepth = s_hDepth = 0; if (s_last_rgb_data) delete[] s_last_rgb_data; s_last_rgb_data = 0; s_rgb_count = 0; s_wRgb = s_hRgb = 0; if (freenect_init(&f_ctx, NULL) < 0) { m_app->dispToConsole("[qKinect] Failed to initialize kinect driver!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG); int nr_devices = freenect_num_devices(f_ctx); m_app->dispToConsole(qPrintable(QString("[qKinect] Number of devices found: %1").arg(nr_devices))); if (nr_devices < 1) return; if (freenect_open_device(f_ctx, &f_dev, 0) < 0) { m_app->dispToConsole("[qKinect] Failed to initialize kinect device!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } //test: try to init high resolution mode //freenect_frame_mode upDepthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_HIGH, FREENECT_DEPTH_11BIT); //int success = freenect_set_depth_mode(f_dev,upDepthMode); /*** Depth information ***/ freenect_frame_mode depthMode = freenect_get_current_depth_mode(f_dev); if (!depthMode.depth_format == FREENECT_DEPTH_11BIT) { depthMode = freenect_find_depth_mode(depthMode.resolution, FREENECT_DEPTH_11BIT); if (freenect_set_depth_mode(f_dev,depthMode)<0) { m_app->dispToConsole("[qKinect] Failed to initialiaze depth mode!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } } if (!getResolution(depthMode.resolution,s_wDepth,s_hDepth)) { m_app->dispToConsole("[qKinect] Failed to read depth resolution!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } m_app->dispToConsole(qPrintable(QString("[qKinect] Depth resolution: %1 x %2").arg(s_wDepth).arg(s_hDepth))); s_depth_data = new uint16_t[s_wDepth*s_hDepth]; if (!s_depth_data) { m_app->dispToConsole("[qKinect] Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } s_max_depth_count = 1; /*** RGB information ***/ bool grabRGB = true; { freenect_frame_mode rgbMode = freenect_get_current_video_mode(f_dev); if (!rgbMode.video_format == FREENECT_VIDEO_RGB || depthMode.resolution != rgbMode.resolution) { rgbMode = freenect_find_video_mode(depthMode.resolution, FREENECT_VIDEO_RGB); if (freenect_set_video_mode(f_dev,rgbMode)<0) { m_app->dispToConsole("[qKinect] Can't find a video mode compatible with current depth mode?!"); grabRGB = false; } } //still want to/can grab RGB info? if (grabRGB) { getResolution(rgbMode.resolution,s_wRgb,s_hRgb); s_last_rgb_data = new uint8_t[s_wRgb*s_hRgb*3]; if (!s_last_rgb_data) //not enough memory for RGB { m_app->dispToConsole("[qKinect] Not enough memory to grab RGB info!"); grabRGB = false; } else { m_app->dispToConsole(qPrintable(QString("[qKinect] RGB resolution: %1 x %2").arg(s_wRgb).arg(s_hRgb))); } } } int freenect_angle = 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); if (grabRGB) freenect_set_video_buffer(f_dev, s_last_rgb_data); freenect_start_depth(f_dev); if (s_last_rgb_data) freenect_start_video(f_dev); m_kDlg = new ccKinectDlg(m_app->getMainWindow()); if (grabRGB) m_kDlg->addMode(QString("%1 x %2").arg(s_wDepth).arg(s_hDepth)); else m_kDlg->grabRGBCheckBox->setChecked(false); m_kDlg->grabRGBCheckBox->setEnabled(grabRGB); m_kDlg->grabPushButton->setEnabled(true); connect(m_kDlg->grabPushButton, SIGNAL(clicked()), this, SLOT(grabCloud())); connect(m_kDlg, SIGNAL(finished(int)), this, SLOT(dialogClosed(int))); //m_kDlg->setModal(false); //m_kDlg->setWindowModality(Qt::NonModal); m_kDlg->show(); if (!m_timer) { m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(updateRTView())); } m_timer->start(0); }
int main(int argc, char **argv) { 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; } if ( network_init() < 0 ) return -1; 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_depth_format(f_dev, FREENECT_FORMAT_11_BIT); //freenect_start_depth(f_dev); //freenect_set_led(f_dev,LED_RED); while(!die && freenect_process_events(f_ctx) >= 0 ){ char buffer[6]; int n = read(data_child, buffer, 1024); //printf("n: %d\n", n); if(n == 6){ if (buffer[0] == 1) { //MOTOR if (buffer[1] == 1) { //MOVE int angle; memcpy(&angle, &buffer[2], sizeof(int)); freenect_set_tilt_degs(f_dev,ntohl(angle)); } } } } network_close(); printf("-- done!\n"); pthread_exit(NULL); }
int ofxKinectContext::numTotal() { if(!isInited()) init(); return freenect_num_devices(kinectContext); }