使用 Kinect 生成点云数据
参考台湾 Heresy 大神的程序:
http://kheresy.wordpress.com/2011/01/25/build_3d_point_
cloud_via_openni/
[cpp] view plain copy
1. #include <XnCppWrapper.h>
2. #include <iostream>
3. #include <iomanip>
4. #include <vector>
5.
6. using namespace xn;
7. using namespace std;
8.
9. //point cloud data struct
10. struct SColorPoint3D
11. {
12. float X;
13. float Y;
14. float Z;
15. float R;
16. float G;
17. float B;
18.
19. SColorPoint3D( XnPoint3D pos, XnRGB24Pixel color )
20. {
21. X = pos.X;
22. Y = pos.Y;
23. Z = pos.Z;
24. R = (float)color.nRed / 255;
25. G = (float)color.nGreen / 255;
26. B = (float)color.nBlue / 255;
27. }
28. };
29.
30. void GeneratePointCloud( DepthGenerator& rDepthGen,
31. const XnDepthPixel* pDepth,
32. const XnRGB24Pixel* pImage,
33. vector<SColorPoint3D>& vPointCloud )
34. {
35. // number of point is the number of 2D image pixel
36. DepthMetaData mDepthMD;
37. rDepthGen.GetMetaData( mDepthMD );
38. unsigned int uPointNum = mDepthMD.FullXRes() * mDepthMD.FullYRes();
39.
40. // build the data structure for convert
41. XnPoint3D* pDepthPointSet = new XnPoint3D[ uPointNum ];
42. unsigned int i, j, idxShift, idx;
43. for( j = 0; j < mDepthMD.FullYRes(); ++j )