invisible

changeset 6:db8f1c036d0e

quick backup - skata o kwdikas
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 03 Nov 2013 20:36:45 +0200
parents 700127288dc5
children 4f1b8ddcd32e
files src/frame.cc src/frame.h
diffstat 2 files changed, 16 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/src/frame.cc	Thu Oct 24 00:09:13 2013 +0300
     1.2 +++ b/src/frame.cc	Sun Nov 03 20:36:45 2013 +0200
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <GL/gl.h>
     1.5  #include <cxcore.h>
     1.6  #include <highgui.h> //TODO remove
     1.7 +#include <cv.h> //TODO remove
     1.8  
     1.9  #include <pthread.h>
    1.10  #include <stdio.h>
    1.11 @@ -18,7 +19,7 @@
    1.12  Frame::Frame()
    1.13  {
    1.14      video_buf = cv::Mat::zeros(KINECT_VIDEO_HEIGHT, KINECT_VIDEO_WIDTH, CV_8UC3);
    1.15 -    depth_buf = cv::Mat::zeros(KINECT_DEPTH_HEIGHT, KINECT_DEPTH_WIDTH, CV_8UC1);
    1.16 +    depth_buf = cv::Mat::zeros(KINECT_DEPTH_HEIGHT, KINECT_DEPTH_WIDTH, CV_16UC1);
    1.17  
    1.18  	tex_setup();
    1.19  }
    1.20 @@ -81,16 +82,12 @@
    1.21  	}
    1.22  
    1.23  	/* freenect depth data to cv mat: */
    1.24 -	unsigned char* src = (unsigned char*)depth;
    1.25 -	unsigned char* dest = frame->depth_buf.data;
    1.26  
    1.27 -	for(int i=0; i<KINECT_DEPTH_HEIGHT * KINECT_DEPTH_WIDTH; i++) {
    1.28 -		*dest = *src;
    1.29 -		dest++;
    1.30 -		src++;
    1.31 -	}
    1.32 +	memcpy(frame->depth_buf.data, depth, KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * 2);
    1.33  
    1.34 -	save_depth_ppm(depth, 640, 480);
    1.35 +	save_depth_ppm(depth, KINECT_DEPTH_WIDTH, KINECT_DEPTH_HEIGHT);
    1.36 +	cv::imshow("foo", frame->depth_buf);
    1.37 +	cv::waitKey(100);
    1.38  	has_depth = true;
    1.39  }
    1.40  
    1.41 @@ -101,16 +98,14 @@
    1.42  		fprintf(stderr, "Failed to open video file for writing.\n");
    1.43  		return false;
    1.44  	}
    1.45 -	fprintf(fp, "P6\n640 480\n255\n");
    1.46 -/*	unsigned char *ptr = (unsigned char*)video;
    1.47 +	fprintf(fp, "P6\n%d %d\n255\n", w, h);
    1.48 +	unsigned char *ptr = (unsigned char*)video;
    1.49  	for(int i=0; i<w * h * 3; i++) {
    1.50  		fputc(*ptr, fp);
    1.51  		ptr++;
    1.52  	}
    1.53  	fclose(fp);
    1.54  	return true;
    1.55 -	*/
    1.56 -	return false;
    1.57  }
    1.58  
    1.59  bool save_depth_ppm(void *depth, int w, int h)
    1.60 @@ -120,15 +115,13 @@
    1.61  		fprintf(stderr, "Failed to open depth file for writing.\n");
    1.62  		return false;
    1.63  	}
    1.64 -	fprintf(fp, "P6\n640 480\n255\n");
    1.65 -	unsigned char *ptr = (unsigned char*)depth;
    1.66 -	unsigned char *foo = (unsigned char*)depth;
    1.67 -	for(int i=0; i<h; i++) {
    1.68 -		for(int j=0; j<w; j++) {
    1.69 -			*foo = *ptr;
    1.70 -			fputc(foo[i * w + j], fp);
    1.71 -			ptr++;
    1.72 -		}
    1.73 +	fprintf(fp, "P6\n%d %d\n255\n", w, h);
    1.74 +	uint16_t *ptr = (uint16_t*)depth;
    1.75 +	for(int i=0; i<w * h; i++) {
    1.76 +		unsigned char c = *ptr++ >> 8;
    1.77 +		fputc(c, fp);
    1.78 +		fputc(c, fp);
    1.79 +		fputc(c, fp);
    1.80  	}
    1.81  	fclose(fp);
    1.82  	return true;
     2.1 --- a/src/frame.h	Thu Oct 24 00:09:13 2013 +0300
     2.2 +++ b/src/frame.h	Sun Nov 03 20:36:45 2013 +0200
     2.3 @@ -27,4 +27,5 @@
     2.4  
     2.5  bool save_video_ppm(void *video, int w, int h);
     2.6  bool save_depth_ppm(void *depth, int w, int h);
     2.7 +
     2.8  #endif // FRAME_H_