Advertisement
lamiastella

SR300Camera::fillInZCoords()

May 15th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. /***
  2. Reads the depth data from the sensor and fills in the matrix
  3. ***/
  4. void SR300Camera::fillInZCoords()
  5. {
  6.     //int res = pmdGet3DCoordinates(hnd, dists, 3 * numPixels * sizeof(float)); //store x,y,z coordinates dists (type: float*)
  7.     ////float * zCoords = new float[1]; //store z-Coordinates of dists in zCoords
  8.     //xyzMap = cv::Mat(xyzMap.size(), xyzMap.type(), dists);
  9.    
  10.     /*
  11.     Projection *projection = pp->QueryCaptureManager()->QueryDevice()->CreateProjection();
  12.     std::vector<Point3DF32> vertices;
  13.     vertices.resize(depth_width * depth_height);
  14.     projection->QueryVertices(sample->depth, vertices.data());
  15.     xyzBuffer.clear();
  16.     //for (int i = 0; i < bufferSize.width*bufferSize.height; i++) {
  17.     for (int i=0; i< depth_width*depth_height; i++) {
  18.         //cv::Point3f p;
  19.         //p.x = vertices[i].x;
  20.         //p.y = vertices[i].y;
  21.         //p.z = vertices[i].z;
  22.         //xyzBuffer.push_back(p);
  23.         cout << "x= " << vertices[i].x << endl;
  24.         cout << "y= " << vertices[i].y << endl;
  25.         cout << "z= " << vertices[i].z << endl;
  26.  
  27.         xyzBuffer.push_back(cv::Point3f(vertices[i].x, vertices[i].y, vertices[i].z));
  28.     }
  29.  
  30.    
  31.    
  32.     xyzMap = cv::Mat(xyzBuffer);
  33.     cout << "xyzMap = " << endl << " " << xyzMap << endl << endl;
  34.  
  35.     projection->Release();
  36.  
  37.     */
  38.    
  39.     PXCImage::ImageData depthImage;
  40.     PXCImage *depthMap = sample->depth;
  41.     depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
  42.     PXCPoint3DF32 * pos2d = new PXCPoint3DF32[depth_width*depth_height];
  43.     int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
  44.  
  45.     for (int y = 0, k = 0; y < depth_height; y++) {
  46.         for (int x = 0; x < depth_width; x++, k++) {
  47.             pos2d[k].x = (pxcF32)x;
  48.             pos2d[k].y = (pxcF32)y;
  49.             pos2d[k].z = ((short *)depthImage.planes[0])[y* depth_stride + x];
  50.         }
  51.     }
  52.    
  53.  
  54.     //Point3DF32 * pos3d = NULL;
  55.     Point3DF32 * pos3d = new Point3DF32[depth_width*depth_height];
  56.     PXCPoint3DF32 * vertices = new PXCPoint3DF32[depth_width * depth_height];
  57.     Projection * projection = device->CreateProjection();
  58.     projection->ProjectDepthToCamera(depth_width*depth_height, pos2d, pos3d);
  59.     cout << "x is " << pos3d->x << endl;
  60.     cout << "y is " << pos3d->y << endl;
  61.     cout << "z is " << pos3d->z << endl;
  62.     /*
  63.     projection->QueryVertices(sample->depth, vertices);
  64.    
  65.     xyzBuffer.clear();
  66.     for (int i = 0; i< depth_width*depth_height; i++) {
  67.         //cv::Point3f p;
  68.         //p.x = vertices[i].x;
  69.         //p.y = vertices[i].y;
  70.         //p.z = vertices[i].z;
  71.         //xyzBuffer.push_back(p);
  72.         cout << "x= " << vertices[i].x << endl;
  73.         cout << "y= " << vertices[i].y << endl;
  74.         cout << "z= " << vertices[i].z << endl;
  75.  
  76.         xyzBuffer.push_back(cv::Point3f(vertices[i].x, vertices[i].y, vertices[i].z));
  77.     }
  78.  
  79.  
  80.  
  81.     xyzMap = cv::Mat(xyzBuffer);
  82.     */
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement