493: Undecipherable

-Blog-

-Projects-

-Urlaub-

-About me-

-RSS-

Swissranger 4000 and OpenCV and Point Cloud Library

Dennis Guse

I am back on working with Depth Cameras and hand gesture recognition - now we are using a Swissranger SR4000 - a TOF camera - instead a Kinect. Here is demo code to get the camera data to OpenCV as well as Point Cloud Library.

 1 /**
 2 * Demo program for the SR4k that shows the output (DepthImage and PCL) and can export these as images.
 3 * Use SPACE to take a picture and ESC for end.
 4 * @author Dennis Guse
 5 */
 6 
 7 #include <stdio.h>
 8 #include <iostream>
 9 #include <string>
10 #include <time.h>
11 
12 #include "opencv2/core/core.hpp"
13 #include "opencv2/highgui/highgui.hpp"
14 #include "opencv2/imgproc/imgproc.hpp"
15 #include "opencv2/imgproc/imgproc_c.h"
16 
17 //SR4k
18 #include "libMesaSR.h"
19 #include "definesSR.h"
20 
21 #include "pcl/point_cloud.h"
22 #include "pcl/point_types.h"
23 #include "pcl/visualization/cloud_viewer.h"
24 
25 using namespace cv;
26 using namespace std;
27 using namespace pcl;
28 
29 #define SR_ROWS 176
30 #define SR_COLS 144
31 /**
32  * Takes a picture with the SR4k and returns the depthimage as well as the point cloud!
33  */
34 cv::Mat takePicture(SRCAM srCam, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud) {
35  SR_Acquire(srCam);
36  cv::Mat depthImage(SR_ROWS, SR_COLS, SR_CV_PIXELTYPE, (unsigned short*)SR_GetImage(srCam, 0)); //0:DepthImage; 1:Amplitude; 2:ConfidenceMap
37 
38  float x [SR_ROWS * SR_COLS];
39  float y [SR_ROWS * SR_COLS];
40  float z [SR_ROWS * SR_COLS];
41  SR_CoordTrfFlt(srCam, x, y, z, sizeof(float), sizeof(float), sizeof(float));
42 
43  for(int i=0; i&lt;SR_ROWS * SR_COLS; i++) {
44    point.x=x[i];
45    point.y=y[i];
46    point.z=z[i];
47    point-&gt;points.push_back(point);
48  }
49  return depthImage;
50 }
51 
52 int main(int argc, char **argv) {
53  SRCAM srCam;
54  SR_OpenETH(&amp;srCam, SR_IP_ADDR); //Add error handling
55  SR_SetMode(srCam, AM_COR_FIX_PTRN|AM_CONV_GRAY|AM_DENOISE_ANF|AM_CONF_MAP);
56 
57  pcl::visualization::CloudViewer viewer ("PCLViewer");
58  while(true) {
59   pcl::PointCloud<pcl::pointxyz>::Ptr cloud(new pcl::PointCloud<pcl::pointxyz>);
60   cv::Mat depthImage = takePicture(srCam, cloud);
61   cv::imshow("Depth", depthIamge);
62 
63   viewer.showCloud(cloud, "Cloud");
64 
65   int key = waitKey(1);
66   if (key == KEY_ESC) break;
67   if (key != -1) saveDepthImageAndCloud(depthImage, cloud);
68  }
69 }