invisible

diff src/frame.cc @ 2:b0b90ef993a0

backup
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 09 Oct 2013 22:56:42 +0300
parents fdbd55eaa14e
children 1ff5a1a50b41
line diff
     1.1 --- a/src/frame.cc	Sat Oct 05 19:02:40 2013 +0300
     1.2 +++ b/src/frame.cc	Wed Oct 09 22:56:42 2013 +0300
     1.3 @@ -1,27 +1,50 @@
     1.4 +#include <cv.h>
     1.5 +#include <pthread.h>
     1.6  #include <stdio.h>
     1.7 -#include <pthread.h>
     1.8 +#include <string.h>
     1.9  
    1.10  #include "frame.h"
    1.11 +#include "kinect.h"
    1.12  
    1.13 -static pthread_mutex_t video_mutex = PTHREAD_MUTEX_INITIALIZER;
    1.14 -static pthread_mutex_t depth_mutex = PTHREAD_MUTEX_INITIALIZER;
    1.15 +extern Frame *frame;
    1.16 +extern KinectParams *kin_params;
    1.17  
    1.18 -void init_frame_mx()
    1.19 +extern bool has_video;
    1.20 +extern bool has_depth;
    1.21 +
    1.22 +Frame::Frame()
    1.23  {
    1.24 -	pthread_mutex_init(&video_mutex, NULL);
    1.25 -	pthread_mutex_init(&depth_mutex, NULL);
    1.26 +	if(video_buf.empty()) {
    1.27 +		video_buf = cv::Mat(FREENECT_VIDEO_WIDTH, FREENECT_VIDEO_HEIGHT, CV_32FC3, cv::Scalar(0, 0, 0));
    1.28 +	}
    1.29 +	if(depth_buf.empty()) {
    1.30 +		depth_buf = cv::Mat(FREENECT_DEPTH_WIDTH, FREENECT_VIDEO_HEIGHT, CV_16UC1, 0);
    1.31 +	}
    1.32  }
    1.33  
    1.34 -void video_cb(freenect_device *kin_dev, void *rgb, uint32_t time)
    1.35 +void Frame::process()
    1.36  {
    1.37 -	pthread_mutex_lock(&video_mutex);
    1.38 -	printf("Started video.\n");
    1.39 -	pthread_mutex_unlock(&video_mutex);
    1.40 +	if(has_video && has_depth)
    1.41 +		printf("Depth and Rgb\n");
    1.42 +}
    1.43 +
    1.44 +void video_cb(freenect_device *kin_dev, void *video, uint32_t time)
    1.45 +{
    1.46 +	if(!video) {
    1.47 +		has_video = false;
    1.48 +		return;
    1.49 +	}
    1.50 +
    1.51 +	//copy *video to video_buf if fail => has_video = false
    1.52 +	has_video = true;
    1.53  }
    1.54  
    1.55  void depth_cb(freenect_device *kin_dev, void *depth, uint32_t time)
    1.56  {
    1.57 -	pthread_mutex_lock(&depth_mutex);
    1.58 -	printf("Started depth.\n");
    1.59 -	pthread_mutex_unlock(&depth_mutex);
    1.60 +	if(!depth) {
    1.61 +		has_depth = false;
    1.62 +		return;
    1.63 +	}
    1.64 +
    1.65 +	has_depth = true;
    1.66  }