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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2011 individual OpenKinect contributors. See the CONTRIB file
* for details.
*
* This code is licensed to you under the terms of the Apache License, version
* 2.0, or, at your option, the terms of the GNU General Public License,
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
* or the following URLs:
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/gpl-2.0.txt
*
* If you redistribute this file in source form, modified or unmodified, you
* may:
* 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
* In all cases you must keep the copyright notice intact and include a copy
* of the CONTRIB file.
*
* Binary distributions must follow the binary distribution requirements of
* either License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "libfreenect.h"
#include "libfreenect_sync.h"
FILE *open_dump(const char *filename)
{
FILE* fp = fopen(filename, "w");
if (fp == NULL) {
fprintf(stderr, "Error: Cannot open file [%s]\n", filename);
exit(1);
}
printf("%s\n", filename);
return fp;
}
void dump_depth(FILE *fp, void *data, unsigned int width, unsigned int height)
{
fprintf(fp, "P5 %d %d 65535\n", width, height);
fwrite(data, width * height * 2, 1, fp);
}
void dump_rgb(FILE *fp, void *data, unsigned int width, unsigned int height)
{
fprintf(fp, "P6 %d %d 255\n", width, height);
fwrite(data, width * height * 3, 1, fp);
}
void no_kinect_quit(void)
{
fprintf(stderr, "Error: Kinect not connected?\n");
exit(1);
}
int main(void)
{
short *depth = 0;
char *rgb = 0;
uint32_t ts;
FILE *fp;
int ret;
ret = freenect_sync_get_video((void**)&rgb, &ts, 0, FREENECT_VIDEO_RGB);
if (ret < 0)
no_kinect_quit();
fp = open_dump("registration_test_rgb.ppm");
dump_rgb(fp, rgb, 640, 480);
fclose(fp);
ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT);
if (ret < 0)
no_kinect_quit();
fp = open_dump("registration_test_depth_raw.pgm");
dump_depth(fp, depth, 640, 480);
fclose(fp);
ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_REGISTERED);
if (ret < 0)
no_kinect_quit();
fp = open_dump("registration_test_depth_registered.pgm");
dump_depth(fp, depth, 640, 480);
fclose(fp);
ret = freenect_sync_get_depth((void**)&depth, &ts, 0, FREENECT_DEPTH_MM);
if (ret < 0)
no_kinect_quit();
fp = open_dump("registration_test_depth_mm.pgm");
dump_depth(fp, depth, 640, 480);
fclose(fp);
return 0;
}
|