regtest.c
Go to the documentation of this file.
1 /*
2  * This file is part of the OpenKinect Project. http://www.openkinect.org
3  *
4  * Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file
5  * for details.
6  *
7  * This code is licensed to you under the terms of the Apache License, version
8  * 2.0, or, at your option, the terms of the GNU General Public License,
9  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10  * or the following URLs:
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * http://www.gnu.org/licenses/gpl-2.0.txt
13  *
14  * If you redistribute this file in source form, modified or unmodified, you
15  * may:
16  * 1) Leave this header intact and distribute it under the same terms,
17  * accompanying it with the APACHE20 and GPL20 files, or
18  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20  * In all cases you must keep the copyright notice intact and include a copy
21  * of the CONTRIB file.
22  *
23  * Binary distributions must follow the binary distribution requirements of
24  * either License.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "libfreenect.h"
31 #include "libfreenect_sync.h"
32 
33 FILE *open_dump(const char *filename)
34 {
35  FILE* fp = fopen(filename, "w");
36  if (fp == NULL) {
37  fprintf(stderr, "Error: Cannot open file [%s]\n", filename);
38  exit(1);
39  }
40  printf("%s\n", filename);
41  return fp;
42 }
43 
44 void dump_depth(FILE *fp, void *data, unsigned int width, unsigned int height)
45 {
46  fprintf(fp, "P5 %u %u 65535\n", width, height);
47  fwrite(data, width * height * 2, 1, fp);
48 }
49 
50 void dump_rgb(FILE *fp, void *data, unsigned int width, unsigned int height)
51 {
52  fprintf(fp, "P6 %u %u 255\n", width, height);
53  fwrite(data, width * height * 3, 1, fp);
54 }
55 
56 void no_kinect_quit(void)
57 {
58  fprintf(stderr, "Error: Kinect not connected?\n");
59  exit(1);
60 }
61 
62 int main(void)
63 {
64  short *depth = 0;
65  char *rgb = 0;
66  uint32_t ts;
67  FILE *fp;
68  int ret;
69 
70  ret = freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB);
71  if (ret < 0)
73 
74  fp = open_dump("registration_test_rgb.ppm");
75  dump_rgb(fp, rgb, 640, 480);
76  fclose(fp);
77 
78  ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT);
79  if (ret < 0)
81 
82  fp = open_dump("registration_test_depth_raw.pgm");
83  dump_depth(fp, depth, 640, 480);
84  fclose(fp);
85 
86  ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_REGISTERED);
87  if (ret < 0)
89 
90  fp = open_dump("registration_test_depth_registered.pgm");
91  dump_depth(fp, depth, 640, 480);
92  fclose(fp);
93 
94  ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_MM);
95  if (ret < 0)
97 
98  fp = open_dump("registration_test_depth_mm.pgm");
99  dump_depth(fp, depth, 640, 480);
100  fclose(fp);
101 
102  return 0;
103 }
int freenect_sync_get_depth(void **depth, uint32_t *timestamp, int index, freenect_depth_format fmt)
FILE * open_dump(const char *filename)
Definition: regtest.c:33
void no_kinect_quit(void)
Definition: regtest.c:56
int main(void)
Definition: regtest.c:62
void dump_rgb(FILE *fp, void *data, unsigned int width, unsigned int height)
Definition: regtest.c:50
unsigned int uint32_t
void dump_depth(FILE *fp, void *data, unsigned int width, unsigned int height)
Definition: regtest.c:44
int freenect_sync_get_video(void **video, uint32_t *timestamp, int index, freenect_video_format fmt)


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38