Skip to content

Commit 3250951

Browse files
author
Brandyn A. White
committed
1. Updated libfreenect_sync to support changing kinects and video types
2. Updated python wrappers to use new libfreenect_sync 3. Fixed a compile warning in fakenect 4. Updated python demos to match new wrapper 5. Added new python demo for multiple kinects (currently only uses one at a time) 6. Added opencv wrappers (credit: Andrew <amiller@dappervision.com>) 7. Added nogil to sync python calls (credit: Mathieu Virbel <mathieu@pymt.eu>) 8. Updated glpclview to use new sync interface, updated calibration parameters (credit: Andrew <amiller@dappervision.com>) Signed-off-by: Brandyn A. White <bwhite@dappervision.com>
1 parent 1c0ddd6 commit 3250951

16 files changed

+730
-355
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set (PROJECT_APIVER
5151
OPTION(BUILD_EXAMPLES "Build example programs" ON)
5252
OPTION(BUILD_FAKENECT "Build fakenect mock library" ON)
5353
OPTION(BUILD_C_SYNC "Build c synchronous library" ON)
54+
OPTION(BUILD_CV "Build OpenCV wrapper" OFF)
5455
OPTION(BUILD_AS3_SERVER "Build the Actionscript 3 Server Example" OFF)
5556
IF(PROJECT_OS_LINUX)
5657
OPTION(BUILD_CPACK "Build an RPM or DEB using CPack" OFF)
@@ -112,6 +113,10 @@ IF(BUILD_C_SYNC)
112113
add_subdirectory (wrappers/c_sync)
113114
ENDIF()
114115

116+
IF(BUILD_CV)
117+
add_subdirectory (wrappers/opencv)
118+
ENDIF()
119+
115120
IF(BUILD_AS3_SERVER)
116121
add_subdirectory(wrappers/actionscript)
117122
ENDIF()

examples/glpclview.c

Lines changed: 130 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -54,179 +54,176 @@ int color = 1; // Use the RGB texture or just draw it as color
5454
// nicolas burrus' posts.
5555
void LoadVertexMatrix()
5656
{
57-
float f = 590.0f;
58-
float a = -0.0030711f;
59-
float b = 3.3309495f;
60-
float cx = 340.0f;
61-
float cy = 240.0f;
62-
GLfloat mat[16] = {
63-
1/f, 0, 0, 0,
64-
0, -1/f, 0, 0,
65-
0, 0, 0, a,
66-
-cx/f,cy/f, -1, b
67-
};
68-
glMultMatrixf(mat);
57+
float fx = 594.21f;
58+
float fy = 591.04f;
59+
float a = -0.0030711f;
60+
float b = 3.3309495f;
61+
float cx = 339.5f;
62+
float cy = 242.7f;
63+
GLfloat mat[16] = {
64+
1/fx, 0, 0, 0,
65+
0, -1/fy, 0, 0,
66+
0, 0, 0, a,
67+
-cx/fx, cy/fy, -1, b
68+
};
69+
glMultMatrixf(mat);
6970
}
7071

7172

7273
// This matrix comes from a combination of nicolas burrus's calibration post
7374
// and some python code I haven't documented yet.
7475
void LoadRGBMatrix()
7576
{
76-
float mat[16] = {
77-
5.34866271e+02, 3.89654806e+00, 0.00000000e+00, 1.74704200e-02,
78-
-4.70724694e+00, -5.28843603e+02, 0.00000000e+00, -1.22753400e-02,
79-
-3.19670762e+02, -2.60999685e+02, 0.00000000e+00, -9.99772000e-01,
80-
-6.98445586e+00, 3.31139785e+00, 0.00000000e+00, 1.09167360e-02
81-
};
82-
glMultMatrixf(mat);
77+
float mat[16] = {
78+
5.34866271e+02, 3.89654806e+00, 0.00000000e+00, 1.74704200e-02,
79+
-4.70724694e+00, -5.28843603e+02, 0.00000000e+00, -1.22753400e-02,
80+
-3.19670762e+02, -2.60999685e+02, 0.00000000e+00, -9.99772000e-01,
81+
-6.98445586e+00, 3.31139785e+00, 0.00000000e+00, 1.09167360e-02
82+
};
83+
glMultMatrixf(mat);
8384
}
8485

8586
void mouseMoved(int x, int y)
8687
{
87-
if (mx>=0 && my>=0) {
88-
rotangles[0] += y-my;
89-
rotangles[1] += x-mx;
90-
}
91-
mx = x;
92-
my = y;
88+
if (mx>=0 && my>=0) {
89+
rotangles[0] += y-my;
90+
rotangles[1] += x-mx;
91+
}
92+
mx = x;
93+
my = y;
9394
}
9495

9596
void mousePress(int button, int state, int x, int y)
9697
{
97-
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
98-
mx = x;
99-
my = y;
100-
}
101-
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
102-
mx = -1;
103-
my = -1;
104-
}
98+
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
99+
mx = x;
100+
my = y;
101+
}
102+
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
103+
mx = -1;
104+
my = -1;
105+
}
105106
}
106107

107108
void DrawGLScene()
108109
{
109-
short *depth = 0;
110-
char *rgb = 0;
111-
uint32_t ts;
112-
if (freenect_sync_get_depth((void**)&depth, &ts) < 0)
113-
return;
114-
if (freenect_sync_get_rgb((void**)&rgb, &ts) < 0) {
115-
free(depth);
116-
return;
117-
}
118-
119-
static unsigned int indices[480][640];
120-
static short xyz[480][640][3];
121-
int i,j;
122-
for (i = 0; i < 480; i++) {
123-
for (j = 0; j < 640; j++) {
124-
xyz[i][j][0] = j;
125-
xyz[i][j][1] = i;
126-
xyz[i][j][2] = depth[i*640+j];
127-
indices[i][j] = i*640+j;
128-
}
129-
}
130-
131-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
132-
glLoadIdentity();
133-
134-
glPushMatrix();
135-
glScalef(zoom,zoom,1);
136-
glTranslatef(0,0,-3.5);
137-
glRotatef(rotangles[0], 1,0,0);
138-
glRotatef(rotangles[1], 0,1,0);
139-
glTranslatef(0,0,1.5);
140-
141-
LoadVertexMatrix();
142-
143-
// Set the projection from the XYZ to the texture image
144-
glMatrixMode(GL_TEXTURE);
145-
glLoadIdentity();
146-
glScalef(1/640.0f,1/480.0f,1);
147-
LoadRGBMatrix();
148-
LoadVertexMatrix();
149-
glMatrixMode(GL_MODELVIEW);
150-
151-
glPointSize(1);
152-
153-
glEnableClientState(GL_VERTEX_ARRAY);
154-
glVertexPointer(3, GL_SHORT, 0, xyz);
155-
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
156-
glTexCoordPointer(3, GL_SHORT, 0, xyz);
157-
158-
if (color)
159-
glEnable(GL_TEXTURE_2D);
160-
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
161-
glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb);
162-
163-
glPointSize(2.0f);
164-
glDrawElements(GL_POINTS, 640*480, GL_UNSIGNED_INT, indices);
165-
glPopMatrix();
166-
glDisable(GL_TEXTURE_2D);
167-
168-
free(rgb);
169-
free(depth);
170-
171-
glutSwapBuffers();
110+
short *depth = 0;
111+
char *rgb = 0;
112+
uint32_t ts;
113+
if (freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT) < 0)
114+
return;
115+
if (freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB) < 0) {
116+
free(depth);
117+
return;
118+
}
119+
120+
static unsigned int indices[480][640];
121+
static short xyz[480][640][3];
122+
int i,j;
123+
for (i = 0; i < 480; i++) {
124+
for (j = 0; j < 640; j++) {
125+
xyz[i][j][0] = j;
126+
xyz[i][j][1] = i;
127+
xyz[i][j][2] = depth[i*640+j];
128+
indices[i][j] = i*640+j;
129+
}
130+
}
131+
132+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
133+
glLoadIdentity();
134+
135+
glPushMatrix();
136+
glScalef(zoom,zoom,1);
137+
glTranslatef(0,0,-3.5);
138+
glRotatef(rotangles[0], 1,0,0);
139+
glRotatef(rotangles[1], 0,1,0);
140+
glTranslatef(0,0,1.5);
141+
142+
LoadVertexMatrix();
143+
144+
// Set the projection from the XYZ to the texture image
145+
glMatrixMode(GL_TEXTURE);
146+
glLoadIdentity();
147+
glScalef(1/640.0f,1/480.0f,1);
148+
LoadRGBMatrix();
149+
LoadVertexMatrix();
150+
glMatrixMode(GL_MODELVIEW);
151+
152+
glPointSize(1);
153+
154+
glEnableClientState(GL_VERTEX_ARRAY);
155+
glVertexPointer(3, GL_SHORT, 0, xyz);
156+
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
157+
glTexCoordPointer(3, GL_SHORT, 0, xyz);
158+
159+
if (color)
160+
glEnable(GL_TEXTURE_2D);
161+
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
162+
glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb);
163+
164+
glPointSize(2.0f);
165+
glDrawElements(GL_POINTS, 640*480, GL_UNSIGNED_INT, indices);
166+
glPopMatrix();
167+
glDisable(GL_TEXTURE_2D);
168+
glutSwapBuffers();
172169
}
173170

174171
void keyPressed(unsigned char key, int x, int y)
175172
{
176-
if (key == 27) {
177-
freenect_sync_stop();
178-
glutDestroyWindow(window);
179-
exit(0);
180-
}
181-
if (key == 'w')
182-
zoom *= 1.1f;
183-
if (key == 's')
184-
zoom /= 1.1f;
185-
if (key == 'c')
186-
color = !color;
173+
if (key == 27) {
174+
freenect_sync_stop();
175+
glutDestroyWindow(window);
176+
exit(0);
177+
}
178+
if (key == 'w')
179+
zoom *= 1.1f;
180+
if (key == 's')
181+
zoom /= 1.1f;
182+
if (key == 'c')
183+
color = !color;
187184
}
188185

189186
void ReSizeGLScene(int Width, int Height)
190187
{
191-
glViewport(0,0,Width,Height);
192-
glMatrixMode(GL_PROJECTION);
193-
glLoadIdentity();
194-
gluPerspective(60, 4/3., 0.3, 200);
195-
glMatrixMode(GL_MODELVIEW);
188+
glViewport(0,0,Width,Height);
189+
glMatrixMode(GL_PROJECTION);
190+
glLoadIdentity();
191+
gluPerspective(60, 4/3., 0.3, 200);
192+
glMatrixMode(GL_MODELVIEW);
196193
}
197194

198195
void InitGL(int Width, int Height)
199196
{
200-
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
201-
glEnable(GL_DEPTH_TEST);
202-
glGenTextures(1, &gl_rgb_tex);
203-
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
204-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
205-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
206-
ReSizeGLScene(Width, Height);
197+
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
198+
glEnable(GL_DEPTH_TEST);
199+
glGenTextures(1, &gl_rgb_tex);
200+
glBindTexture(GL_TEXTURE_2D, gl_rgb_tex);
201+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
202+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
203+
ReSizeGLScene(Width, Height);
207204
}
208205

209206
int main(int argc, char **argv)
210207
{
211-
glutInit(&argc, argv);
208+
glutInit(&argc, argv);
212209

213-
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
214-
glutInitWindowSize(640, 480);
215-
glutInitWindowPosition(0, 0);
210+
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
211+
glutInitWindowSize(640, 480);
212+
glutInitWindowPosition(0, 0);
216213

217-
window = glutCreateWindow("LibFreenect");
214+
window = glutCreateWindow("LibFreenect");
218215

219-
glutDisplayFunc(&DrawGLScene);
220-
glutIdleFunc(&DrawGLScene);
221-
glutReshapeFunc(&ReSizeGLScene);
222-
glutKeyboardFunc(&keyPressed);
223-
glutMotionFunc(&mouseMoved);
224-
glutMouseFunc(&mousePress);
216+
glutDisplayFunc(&DrawGLScene);
217+
glutIdleFunc(&DrawGLScene);
218+
glutReshapeFunc(&ReSizeGLScene);
219+
glutKeyboardFunc(&keyPressed);
220+
glutMotionFunc(&mouseMoved);
221+
glutMouseFunc(&mousePress);
225222

226-
InitGL(640, 480);
223+
InitGL(640, 480);
227224

228-
glutMainLoop();
225+
glutMainLoop();
229226

230-
return 0;
227+
return 0;
231228
}
232229

fakenect/fakenect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int freenect_process_events(freenect_context *ctx) {
200200
memcpy(&state, data, sizeof(state));
201201
} else if (!already_warned) {
202202
already_warned = 1;
203-
printf("\n\nWarning: Accelerometer data has an unexpected size [%d] instead of [%ld]. The acceleration and tilt data will be substituted for dummy values. This data was probably made with an older version of record (the upstream interface changes and we have to follow).\n\n", data_size, sizeof state);
203+
printf("\n\nWarning: Accelerometer data has an unexpected size [%d] instead of [%u]. The acceleration and tilt data will be substituted for dummy values. This data was probably made with an older version of record (the upstream interface changes and we have to follow).\n\n", data_size, sizeof state);
204204
}
205205
break;
206206
}

0 commit comments

Comments
 (0)