55 m_rgb_buffer = (
unsigned char *)malloc(FREENECT_RGB_SIZE);
56 m_depth_buffer = (uint16_t *)malloc(FREENECT_DEPTH_SIZE);
75 memcpy((
void *)m_rgb_buffer, (
void *)rgb, FREENECT_RGB_SIZE);
76 m_depth_timestamp = timestamp;
88 memcpy((
void *)m_depth_buffer, (
void *)depth, FREENECT_DEPTH_SIZE);
89 m_depth_timestamp = timestamp;
107 return m_depth_buffer;
117 m_image_num(FALSE_COLOR_DEPTH_IMAGE),
119 m_false_color_depth_buffer(0)
122 m_freenect_ctx =
new Freenect::Freenect<FvFreenectDevice>();
124 for (
unsigned int i = 0; i < 2048; ++i) {
125 float v = i / 2048.0;
127 m_gamma[i] = v * 6 * 256;
134 delete m_freenect_ctx;
141 m_freenect_dev = &(m_freenect_ctx->createDevice(0));
143 }
catch (std::runtime_error &e) {
147 m_false_color_depth_buffer = (
unsigned char *)malloc(FREENECT_RGB_SIZE);
156 m_freenect_dev->startRGB();
157 m_freenect_dev->startDepth();
159 }
catch (std::runtime_error &e) {
170 m_freenect_dev->stopRGB();
171 m_freenect_dev->stopDepth();
173 }
catch (std::runtime_error &e) {
182 m_freenect_ctx->deleteDevice(0);
183 free(m_false_color_depth_buffer);
189 if (!m_started || !m_opened) {
194 for (
unsigned int i = 0; i < FREENECT_FRAME_PIX; ++i) {
196 int pval = m_gamma[depth[i]];
197 int lb = pval & 0xff;
200 m_false_color_depth_buffer[3 * i + 0] = 255;
201 m_false_color_depth_buffer[3 * i + 1] = 255 - lb;
202 m_false_color_depth_buffer[3 * i + 2] = 255 - lb;
206 m_false_color_depth_buffer[3 * i + 0] = 255;
207 m_false_color_depth_buffer[3 * i + 1] = lb;
208 m_false_color_depth_buffer[3 * i + 2] = 0;
212 m_false_color_depth_buffer[3 * i + 0] = 255 - lb;
213 m_false_color_depth_buffer[3 * i + 1] = 255;
214 m_false_color_depth_buffer[3 * i + 2] = 0;
218 m_false_color_depth_buffer[3 * i + 0] = 0;
219 m_false_color_depth_buffer[3 * i + 1] = 255;
220 m_false_color_depth_buffer[3 * i + 2] = lb;
224 m_false_color_depth_buffer[3 * i + 0] = 0;
225 m_false_color_depth_buffer[3 * i + 1] = 255 - lb;
226 m_false_color_depth_buffer[3 * i + 2] = 255;
230 m_false_color_depth_buffer[3 * i + 0] = 0;
231 m_false_color_depth_buffer[3 * i + 1] = 0;
232 m_false_color_depth_buffer[3 * i + 2] = 255 - lb;
236 m_false_color_depth_buffer[3 * i + 0] = 0;
237 m_false_color_depth_buffer[3 * i + 1] = 0;
238 m_false_color_depth_buffer[3 * i + 2] = 0;
270 return FREENECT_RGB_SIZE;
281 return FREENECT_FRAME_W;
287 return FREENECT_FRAME_H;
300 switch (m_image_num) {
303 printf(
"Selected RGB buffer\n");
307 m_buffer = m_false_color_depth_buffer;
308 printf(
"Selected false color depth buffer\n");
311 default: m_buffer = m_freenect_dev->
rgb_buffer();
FvFreenectDevice(freenect_context *ctx, int index)
Constructor.
~FvFreenectDevice()
Destructor.
void RGBCallback(freenect_pixel *rgb, uint32_t timestamp)
Callback function for the freenect driver.
unsigned char * rgb_buffer()
Access the RGB buffer.
uint16_t * depth_buffer()
Access the depth buffer.
void DepthCallback(void *depth, uint32_t timestamp)
Callback function for the freenect driver.
virtual unsigned int pixel_height()
Height of image in pixels.
KinectCamera(const CameraArgumentParser *cap=NULL)
Constructor.
static const unsigned int FALSE_COLOR_DEPTH_IMAGE
False color depth image.
virtual void set_image_number(unsigned int n)
Set image number to retrieve.
virtual void print_info()
Print out camera information.
virtual void start()
Start image transfer from the camera.
static const unsigned int RGB_IMAGE
Color image.
virtual void capture()
Capture an image.
virtual colorspace_t colorspace()
Colorspace of returned image.
~KinectCamera()
Destructor.
virtual void close()
Close camera.
virtual unsigned int pixel_width()
Width of image in pixels.
virtual bool ready()
Camera is ready for taking pictures.
virtual unsigned int buffer_size()
Size of buffer.
virtual void open()
Open the camera.
virtual void flush()
Flush image queue.
virtual void stop()
Stop image transfer from the camera.
virtual unsigned char * buffer()
Get access to current image buffer.
virtual void dispose_buffer()
Dispose current buffer.