forked from perillamint/3dface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libfreenect_cv.cpp
78 lines (65 loc) · 1.79 KB
/
libfreenect_cv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* libfreenect_cv.cpp
*
* Created on: 2012. 5. 12.
* Author: maneulyori
*/
#include <libfreenect.h>
#include <libfreenect_sync.h>
#include <memory.h>
#include "libfreenect_cv.h"
#include "dumpcode.h"
IplImage *freenect_sync_get_depth_cv(int index)
{
static IplImage *image = 0;
uint16_t *data = 0;
uint16_t *targetData = 0;
int i, j;
if (!image)
image = cvCreateImage(cvSize(640, 480), IPL_DEPTH_16U, 1);
unsigned int timestamp;
if (freenect_sync_get_depth
((void **)&data, ×tamp, index, FREENECT_DEPTH_REGISTERED))
return NULL;
// dumpcode((unsigned char*)data, 64);
//
// cvSetData(image, data, 640);
// (uint16_t*)image->imageData = data;
// memcpy(image->imageData, data, 640*480*2);
targetData = (unsigned short int *)image->imageData;
for (i = 0; i < 640; i++)
for (j = 0; j < 480; j++)
targetData[i * 480 + j] =
0xFFFF - ((unsigned short int *)data)[i * 480 + j] * 32;
// NOTE: Multiplying 16 may occur overflow in large distance but it might
// not disturb the data.
// dumpdepth((unsigned short int*)(data+153600), 64);
return image;
}
IplImage *freenect_sync_get_rgb_cv(int index)
{
static IplImage *image = 0;
static char *data = 0;
if (!image)
image = cvCreateImage(cvSize(640, 480), 8, 3);
unsigned int timestamp;
if (freenect_sync_get_video
((void **)&data, ×tamp, index, FREENECT_VIDEO_RGB))
return NULL;
cvSetData(image, data, 640 * 3);
cvCvtColor(image, image, CV_RGB2BGR);
return image;
}
IplImage *freenect_sync_get_ir_cv(int index)
{
static IplImage *image = 0;
static char *data = 0;
if (!image)
image = cvCreateImage(cvSize(640, 480), 8, 1);
unsigned int timestamp;
if (freenect_sync_get_video
((void **)&data, ×tamp, index, FREENECT_VIDEO_IR_8BIT))
return NULL;
cvSetData(image, data, 640);
return image;
}