int main(int argc, char **argv) { while (cvWaitKey(10) < 0) { IplImage *image = freenect_sync_get_rgb_cv(0); if (!image) { printf("Error: Kinect not connected?\n"); return -1; } cvCvtColor(image, image, CV_RGB2BGR); IplImage *depth = freenect_sync_get_depth_cv(0); if (!depth) { printf("Error: Kinect not connected?\n"); return -1; } cvShowImage("RGB", image); cvShowImage("Depth", GlViewColor(depth)); } }
int main(int argc, char **argv) { int first = 1; int angle = 0; double duration = 5; IplImage *image = 0; IplImage *image2 = 0; IplImage *prev = 0; IplImage *output = 0; IplImage *depth; IplImage *diff = 0; IplImage *bw = 0; IplImage *edge = 0; IplImage *edge2 = 0; // if (!prev) prev = cvCreateImageHeader(cvSize(640,480), 8, 3); //if (!diff) diff = cvCreateImageHeader(cvSize(640,480), 8, 3); diff = cvCreateImage(cvSize(640,480),8,3); bw = cvCreateImage(cvSize(640,480),8,1); edge = cvCreateImage(cvSize(640,480),8,1); edge2 = cvCreateImage(cvSize(640,480),8,1); output = cvCreateImage(cvSize(640,480),8,3); cvZero( output ); //cvCvtColor(output, output, CV_RGB2BGR); while (1) { switch(cvWaitKey(10)){ case 113: exit(0); case 'w': angle++; if(angle > 30) angle = 30; set_tilt_cv(angle,0); break; case 'x': angle--; if(angle < -30) angle = -30; set_tilt_cv(angle,0); break; case 's': angle = 0; set_tilt_cv(angle,0); break; case 'e': angle += 10; if(angle > 30) angle = 30; set_tilt_cv(angle,0); break; case 'c': angle -=10; if(angle < -30) angle = -30; set_tilt_cv(angle,0); break; default: // cvWaitKey(700); if(first){ prev = freenect_sync_get_rgb_cv(0); //first = 0; } else { prev = cvCloneImage(image2); cvReleaseImage(&image2); } image = freenect_sync_get_rgb_cv(0); image2 = cvCloneImage(image); if (!image) { printf("Error: Kinect not connected?\n"); return -1; } cvCvtColor(image, image, CV_RGB2BGR); // cvCvtColor(image2, image2, CV_RGB2BGR); cvAbsDiff(image,prev,diff); cvCvtColor(diff, bw,CV_BGR2GRAY); cvCanny(bw, edge, 29000,30500,7); // cvThreshold(bw,bw,100,254,CV_THRESH_BINARY); cvNot(edge,edge2); if(!first) { cvSubS(output,cvScalar(255,255,255,255),output,0); cvAnd(GlViewColor(depth),GlViewColor(depth),output,edge); //cvRunningAvg(GlViewColor(depth),output,1,edge); } //cvRunningAvg(image,output,1,edge); if(!first) { cvReleaseImage(&prev); } else first = 0; cvAddWeighted(image, .3, output, .7, 1, image); // OverlayImage(image2, output, cvPoint(0, 0), cvScalar(0.8,0.8,0.8,0.8), cvScalar(0.2,0.2,0.2,0.2)); /* CvPoint* points[1]; CvPoint ptt[5]; points[0] = &(ptt[0]); points[0][0] = cvPoint(100,100); points[0][1] = cvPoint(200,100); points[0][2] = cvPoint(150,150); points[0][3] = cvPoint(150,300); points[0][4] = cvPoint(100,250); int npts[1]; npts[0]=5; cvPolyLine(image, points, npts, 1,1, cvScalar(100,100,100,230),1, 8,0); cvFillPoly(image, points, npts,1, cvScalar(100,100,100,230), 8,0); */ depth = freenect_sync_get_depth_cv(0); cvSmooth(depth,depth,CV_BLUR,18,18,2.0,2.0); if (!depth) { printf("Error: Kinect not connected?\n"); return -1; } cvShowImage("RGB", image); cvShowImage("Output", output); cvShowImage("Depth", GlViewColor(depth)); break; } } }