Advertisement
lamiastella

SR300Camera::fillInZCoords

May 19th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 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.  
  7.     Image::ImageData depthImage;
  8.     Image *depthMap = sample->depth;
  9.     depthMap->AcquireAccess(Image::ACCESS_READ, &depthImage);
  10.     Image::ImageInfo imgInfo = depthMap->QueryInfo();
  11.     int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
  12.     Projection * projection = device->CreateProjection();
  13.  
  14.    
  15.     unsigned int wxhDepth = depth_width * depth_height;
  16.     // create the array of depth coordinates + depth value (posUVZ) within the defined ROI
  17.     Point3DF32* posUVZ = new Point3DF32[wxhDepth];
  18.     pxcU16 *dpixels = (pxcU16*)depthImage.planes[0];
  19.     unsigned int dpitch = depthImage.pitches[0] / sizeof(pxcU16); /* aligned width */
  20.    
  21.     for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
  22.     {
  23.         for (unsigned int xx = 0; xx < depth_width; xx++, k++)
  24.         {
  25.             posUVZ[k].x = (pxcF32)xx*depth_width;
  26.             posUVZ[k].y = (pxcF32)yy *depth_height;
  27.             //posUVZ[k].z = (pxcF32)dpixels[yy * dpitch + xx];
  28.             //posUVZ[k].z = static_cast<pxcF32>(reinterpret_cast<pxcI16*>(depthImage.planes[0]
  29.       //+ static_cast<int>(posUVZ[k].y) * depthImage.pitches[0])[static_cast<int>(posUVZ[k].x)]);
  30.             posUVZ[k].z = static_cast<pxcF32>(reinterpret_cast<pxcI16*>(depthImage.planes[0]
  31.                 + static_cast<int>(yy) * depthImage.pitches[0])[static_cast<int>(xx)]);
  32.             cout << "xx is " << posUVZ[k].x << endl;
  33.             cout << "yy is " << posUVZ[k].y << endl;
  34.             cout << "zz is " << posUVZ[k].z<< endl;
  35.         }
  36.     }
  37.  
  38.     vector<PointF32> depthPoints;
  39.     vector<PointF32> projPoints;
  40.  
  41.  
  42.  
  43.     //CImageGUI::DEPTH_IMG = 1
  44.    
  45.  
  46.    
  47.  
  48.     // convert the array of depth coordinates + depth value (posUVZ) into the world coordinates (pos3D) in mm
  49.     Point3DF32* pos3D = new Point3DF32[wxhDepth];
  50.     //projection->DepthToWorld(depthMap, depthPoints, projPoints);
  51.     /*
  52.     for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
  53.     {
  54.         for (unsigned int xx = 0; xx < depth_width; xx++, k++)
  55.         {
  56.             cout << "xx is " << [k] << endl;
  57.             //cout << "yy is " << pos3D[k].y*1000.0 << endl;
  58.             //cout << "zz is " << pos3D[k].z*1000.0 << endl;
  59.             //xyzBuffer.push_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
  60.         }
  61.     }
  62.     */
  63.     int dsize = depth_height*depth_width;
  64.     vector<Point3DF32> dcordsAbs;
  65.     /*
  66.     for (auto i = 0; i < ; i++) {
  67.         dcordsAbs[i].x = dcords[i].x * dwidth, dcordsAbs[i].y = dcords[i].y * dheight;
  68.         dcordsAbs[i].z = static_cast<pxcF32>(reinterpret_cast<pxcI16*>(ddata.planes[0] + static_cast<int>(dcordsAbs[i].y) * ddata.pitches[0])[static_cast<int>(dcordsAbs[i].x)]);
  69.     }
  70.     */
  71.     //depth->ReleaseAccess(&ddata);
  72.     //projection->DepthToWorld(depthMap, depthPoints, pos3D);
  73.  
  74.     //projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D);
  75.     /*
  76.     if (projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) < PXC_STATUS_NO_ERROR)
  77.     {
  78.         delete[] posUVZ;
  79.         delete[] pos3D;
  80.         cout << "projection unsucessful";
  81.         return;
  82.     }
  83.     */
  84.     /*
  85.     for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
  86.     {
  87.         for (unsigned int xx = 0; xx < depth_width; xx++, k++)
  88.         {
  89.             cout << "xx is " << pos3D[k].x*1000.0 << endl;
  90.             cout << "yy is " << pos3D[k].y*1000.0 << endl;
  91.             cout << "zz is " << pos3D[k].z*1000.0 << endl;
  92.             xyzBuffer.push_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
  93.         }
  94.     }
  95.     */
  96.  
  97.     /*
  98.     for (int idx = 0; idx < wxhDepth; idx++) {
  99.  
  100.         cout << "x is " << pos3D[idx].x*1000.0 << endl;
  101.         cout << "y is " << pos3D[idx].y*1000.0 << endl;
  102.         cout << "z is " << pos3D[idx].z*1000.0 << endl;
  103.         xyzBuffer.push_back(cv::Point3f(pos3D[idx].x, pos3D[idx].y, pos3D[idx].z));
  104.     }
  105.     */
  106.    
  107.     //xyzMap = cv::Mat(xyzMap.size(), xyzMap.type, &pos3D);
  108.     //xyzMap = cv::Mat(xyzBuffer);
  109.     //cout << "xyzMap = " << endl << " " << xyzMap << endl << endl;
  110.  
  111.     projection->Release();
  112.     delete[] posUVZ;
  113.     delete[] pos3D;
  114.    
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement