eleni@5: #include eleni@4: #include eleni@9: #include eleni@10: #include eleni@9: eleni@4: #include //TODO remove eleni@6: #include //TODO remove eleni@4: eleni@2: #include eleni@1: #include eleni@2: #include eleni@1: eleni@1: #include "frame.h" eleni@2: #include "kinect.h" eleni@1: eleni@2: extern Frame *frame; eleni@2: extern KinectParams *kin_params; eleni@1: eleni@2: extern bool has_video; eleni@2: extern bool has_depth; eleni@2: eleni@2: Frame::Frame() eleni@1: { eleni@5: video_buf = cv::Mat::zeros(KINECT_VIDEO_HEIGHT, KINECT_VIDEO_WIDTH, CV_8UC3); eleni@9: depth_buf = cv::Mat::zeros(KINECT_DEPTH_HEIGHT, KINECT_DEPTH_WIDTH, CV_8UC1); eleni@5: eleni@5: tex_setup(); eleni@5: } eleni@5: eleni@5: void Frame::tex_setup() eleni@5: { eleni@5: glGenTextures(1, &video_tex); eleni@5: glGenTextures(1, &depth_tex); eleni@5: eleni@5: glBindTexture(GL_TEXTURE_2D, video_tex); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); eleni@12: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, KINECT_VIDEO_WIDTH, KINECT_VIDEO_HEIGHT, eleni@12: 0, GL_BGR, GL_UNSIGNED_BYTE, 0); eleni@5: eleni@5: glBindTexture(GL_TEXTURE_2D, depth_tex); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); eleni@5: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); eleni@12: glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, KINECT_DEPTH_WIDTH, KINECT_DEPTH_HEIGHT, eleni@12: 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); eleni@1: } eleni@1: eleni@2: void Frame::process() eleni@1: { eleni@12: if(has_video) { eleni@12: glBindTexture(GL_TEXTURE_2D, video_tex); eleni@12: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, KINECT_VIDEO_WIDTH, KINECT_VIDEO_HEIGHT, GL_BGR, GL_UNSIGNED_BYTE, video_buf.data); eleni@13: } eleni@13: if(has_depth) { eleni@13: glBindTexture(GL_TEXTURE_2D, depth_tex); eleni@13: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, KINECT_DEPTH_WIDTH, KINECT_DEPTH_HEIGHT, GL_LUMINANCE, GL_UNSIGNED_BYTE, depth_buf.data); eleni@12: } eleni@12: if(has_video && has_depth) {//pot eleni@12: } eleni@2: } eleni@2: eleni@2: void video_cb(freenect_device *kin_dev, void *video, uint32_t time) eleni@2: { eleni@4: if(!video || !frame) { eleni@2: has_video = false; eleni@2: return; eleni@2: } eleni@2: eleni@5: /* freenect video data to cv mat: */ eleni@5: unsigned char* src = (unsigned char*)video; eleni@5: unsigned char* dest = frame->video_buf.data; eleni@5: eleni@5: for(int i=0; idepth_buf.data; eleni@5: eleni@8: for(int i=0; i= 2047) { eleni@11: val = 2047; eleni@8: } eleni@9: *dest = val >> 3; eleni@8: src++; eleni@8: dest++; eleni@8: } eleni@5: eleni@11: // cv::GaussianBlur(frame->depth_buf, frame->depth_buf, cv::Size(3, 3), 0.5); eleni@10: eleni@11: /* eleni@11: //Inpaint to fill the regions eleni@11: //^ val = 0 instead of 2047 and: eleni@10: cv::Mat mask = 255 - frame->depth_buf; eleni@10: cv::threshold(mask, mask, 254, 255, 3); eleni@10: cv::inpaint(frame->depth_buf, mask, frame->depth_buf, 1, cv::INPAINT_NS); eleni@11: */ eleni@2: has_depth = true; eleni@1: } eleni@5: eleni@5: bool save_video_ppm(void *video, int w, int h) eleni@5: { eleni@5: FILE *fp; eleni@5: if(!(fp = fopen("test_video.ppm", "wb"))) { eleni@5: fprintf(stderr, "Failed to open video file for writing.\n"); eleni@5: return false; eleni@5: } eleni@6: fprintf(fp, "P6\n%d %d\n255\n", w, h); eleni@6: unsigned char *ptr = (unsigned char*)video; eleni@5: for(int i=0; i