cvdemo.c
Go to the documentation of this file.
1 #include <opencv/cv.h>
2 #include <opencv/highgui.h>
3 #include <stdio.h>
4 #include "libfreenect_cv.h"
5 
6 IplImage *GlViewColor(IplImage *depth)
7 {
8  static IplImage *image = 0;
9  if (!image) image = cvCreateImage(cvSize(640,480), 8, 3);
10  unsigned char *depth_mid = (unsigned char*)(image->imageData);
11  int i;
12  for (i = 0; i < 640*480; i++) {
13  int lb = ((short *)depth->imageData)[i] % 256;
14  int ub = ((short *)depth->imageData)[i] / 256;
15  switch (ub) {
16  case 0:
17  depth_mid[3*i+2] = 255;
18  depth_mid[3*i+1] = 255-lb;
19  depth_mid[3*i+0] = 255-lb;
20  break;
21  case 1:
22  depth_mid[3*i+2] = 255;
23  depth_mid[3*i+1] = lb;
24  depth_mid[3*i+0] = 0;
25  break;
26  case 2:
27  depth_mid[3*i+2] = 255-lb;
28  depth_mid[3*i+1] = 255;
29  depth_mid[3*i+0] = 0;
30  break;
31  case 3:
32  depth_mid[3*i+2] = 0;
33  depth_mid[3*i+1] = 255;
34  depth_mid[3*i+0] = lb;
35  break;
36  case 4:
37  depth_mid[3*i+2] = 0;
38  depth_mid[3*i+1] = 255-lb;
39  depth_mid[3*i+0] = 255;
40  break;
41  case 5:
42  depth_mid[3*i+2] = 0;
43  depth_mid[3*i+1] = 0;
44  depth_mid[3*i+0] = 255-lb;
45  break;
46  default:
47  depth_mid[3*i+2] = 0;
48  depth_mid[3*i+1] = 0;
49  depth_mid[3*i+0] = 0;
50  break;
51  }
52  }
53  return image;
54 }
55 
56 int main(int argc, char **argv)
57 {
58  while (cvWaitKey(10) < 0) {
59  IplImage *image = freenect_sync_get_rgb_cv(0);
60  if (!image) {
61  printf("Error: Kinect not connected?\n");
62  return -1;
63  }
64  cvCvtColor(image, image, CV_RGB2BGR);
65  IplImage *depth = freenect_sync_get_depth_cv(0);
66  if (!depth) {
67  printf("Error: Kinect not connected?\n");
68  return -1;
69  }
70  cvShowImage("RGB", image);
71  cvShowImage("Depth", GlViewColor(depth));
72  }
73  return 0;
74 }
uint8_t * depth_mid
Definition: chunkview.c:57
IplImage * freenect_sync_get_rgb_cv(int index)
IplImage * freenect_sync_get_depth_cv(int index)
Definition: libfreenect_cv.c:5
int main(int argc, char **argv)
Definition: cvdemo.c:56
IplImage * GlViewColor(IplImage *depth)
Definition: cvdemo.c:6


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42