invisible

view src/kinect.cc @ 4:1ff5a1a50b41

foo, TODO: fix conversions
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 16 Oct 2013 15:41:08 +0300
parents fdbd55eaa14e
children 700127288dc5
line source
1 #include <stdio.h>
2 #include <pthread.h>
3 #include <libfreenect.h>
5 #include "kinect.h"
6 #include "frame.h"
8 bool init_kinect(freenect_context **kin_ctx, freenect_device **kin_dev, KinectParams *kin_params)
9 {
10 if(freenect_init(kin_ctx, NULL) < 0) {
11 fprintf(stderr, "Failed to initialize kinect context.\n");
12 return false;
13 }
15 freenect_set_log_level(*kin_ctx, FREENECT_LOG_INFO);
17 int num_dev = freenect_num_devices(*kin_ctx);
18 if(num_dev < 1) {
19 fprintf(stderr, "Kinect device not found.\n");
20 return false;
21 }
22 printf("%d devices found, will use the first.\n", num_dev);
24 if(freenect_open_device(*kin_ctx, kin_dev, 0) < 0) {
25 fprintf(stderr, "Couldn't open kinect device.\n");
26 return false;
27 }
29 if(freenect_set_tilt_degs(*kin_dev, kin_params->angle) < 0) {
30 stop_kinect(*kin_ctx, *kin_dev);
31 fprintf(stderr, "Failed to set kinect angle\n");
32 return false;
33 }
35 if(freenect_set_led(*kin_dev, kin_params->led_color) < 0) {
36 fprintf(stderr, "Failed to set kinect LED\n");
37 stop_kinect(*kin_ctx, *kin_dev);
38 return false;
39 }
41 return true;
42 }
44 bool init_kinect_frames(freenect_context **kin_ctx, freenect_device **kin_dev,
45 KinectParams *kin_params) {
47 freenect_set_video_callback(*kin_dev, video_cb);
48 freenect_set_depth_callback(*kin_dev, depth_cb);
50 if(freenect_set_video_mode(*kin_dev,
51 freenect_find_video_mode(kin_params->video_res,
52 kin_params->video_format)) < 0) {
53 fprintf(stderr, "Failed to set kinect video mode.\n");
54 return false;
55 }
57 if(freenect_set_depth_mode(*kin_dev,
58 freenect_find_depth_mode(kin_params->depth_res,
59 kin_params->depth_format)) < 0) {
60 fprintf(stderr, "Failed to set kinect depth mode.\n");
61 return false;
62 }
64 if(freenect_start_video(*kin_dev) < 0) {
65 fprintf(stderr, "Failed to start kinect video.\n");
66 return false;
67 }
69 if(freenect_start_depth(*kin_dev) < 0) {
70 fprintf(stderr, "Failed to start kinect depth video.\n");
71 return false;
72 }
74 return true;
75 }
77 void stop_kinect_video_frames(freenect_device *kin_dev)
78 {
79 freenect_stop_video(kin_dev);
80 }
82 void stop_kinect_depth_frames(freenect_device *kin_dev)
83 {
84 freenect_stop_depth(kin_dev);
85 }
87 void stop_kinect_frames(freenect_device *kin_dev)
88 {
89 stop_kinect_video_frames(kin_dev);
90 stop_kinect_depth_frames(kin_dev);
91 }
93 void stop_kinect(freenect_context *kin_ctx, freenect_device *kin_dev)
94 {
95 freenect_set_led(kin_dev, LED_OFF);
96 freenect_close_device(kin_dev);
97 freenect_shutdown(kin_ctx);
98 }