invisible

changeset 8:bd1b0385a10b

fixed depth frame rendering
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 03 Nov 2013 22:07:00 +0200
parents 4f1b8ddcd32e
children 6f5f53d0d166
files src/frame.cc
diffstat 1 files changed, 13 insertions(+), 21 deletions(-) [+]
line diff
     1.1 --- a/src/frame.cc	Sun Nov 03 21:58:56 2013 +0200
     1.2 +++ b/src/frame.cc	Sun Nov 03 22:07:00 2013 +0200
     1.3 @@ -82,10 +82,21 @@
     1.4  	}
     1.5  
     1.6  	/* freenect depth data to cv mat: */
     1.7 +	uint16_t* src = (uint16_t*)depth;
     1.8 +	uint16_t* dest = (uint16_t*)frame->depth_buf.data;
     1.9  
    1.10 -	memcpy(frame->depth_buf.data, depth, KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * 2);
    1.11 +	for(int i=0; i<KINECT_DEPTH_HEIGHT * KINECT_DEPTH_WIDTH; i++) {
    1.12 +		uint16_t val = *src;
    1.13 +		if(val >= 2047) {
    1.14 +			val = 0;
    1.15 +		}
    1.16 +		val = val << 5;
    1.17 +		*dest = val;
    1.18 +		src++;
    1.19 +		dest++;
    1.20 +	}
    1.21  
    1.22 -	save_depth_ppm(depth, KINECT_DEPTH_WIDTH, KINECT_DEPTH_HEIGHT);
    1.23 +
    1.24  	cv::imshow("foo", frame->depth_buf);
    1.25  	cv::waitKey(100);
    1.26  	has_depth = true;
    1.27 @@ -107,22 +118,3 @@
    1.28  	fclose(fp);
    1.29  	return true;
    1.30  }
    1.31 -
    1.32 -bool save_depth_ppm(void *depth, int w, int h)
    1.33 -{
    1.34 -	FILE *fp;
    1.35 -	if(!(fp = fopen("test_depth.ppm", "wb"))) {
    1.36 -		fprintf(stderr, "Failed to open depth file for writing.\n");
    1.37 -		return false;
    1.38 -	}
    1.39 -	fprintf(fp, "P6\n%d %d\n255\n", w, h);
    1.40 -	uint16_t *ptr = (uint16_t*)depth;
    1.41 -	for(int i=0; i<w * h; i++) {
    1.42 -		unsigned char c = *ptr++ >> 8;
    1.43 -		fputc(c, fp);
    1.44 -		fputc(c, fp);
    1.45 -		fputc(c, fp);
    1.46 -	}
    1.47 -	fclose(fp);
    1.48 -	return true;
    1.49 -}