Advertisement
lamiastella

depth to xyz from dataset

Jun 13th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. const auto FX = 478.01f;
  2.     const auto FY = 478.01f;
  3.     const auto CX = 321.59f;
  4.     const auto CY = 250.55f;
  5.     vector<Point3f>  xyzBuffer;
  6.  
  7.  
  8.     auto depth_image = imread("C:\\OpenARK\\OpenARK-test\\moon.png", IMREAD_ANYDEPTH);
  9.     cout << "n rows depth: " << depth_image.rows << endl;
  10.     cout << "n cols depth: " << depth_image.cols << endl;
  11.     cout << "depth type: " << depth_image.type() << endl;
  12.  
  13.     for (auto v = 0; v < depth_image.rows; v++) {
  14.         for (auto u = 0; u < depth_image.cols; u++) {
  15.             auto depth_value = depth_image.at<float>(v, u);
  16.             Point3f p;
  17.             p.x = ((u - CX)*depth_value*(1.0f / FX)) / 1000.0f;
  18.             p.y = ((v - CY)*depth_value*(1.0f / FY)) / 1000.0f;
  19.             p.z = (depth_value) / 1000.0f;
  20.             xyzBuffer.emplace_back(p);
  21.         }
  22.     }
  23.  
  24.     /*for (auto u = 0; u < depth_image.cols; u++) {
  25.         for (auto v = 0; v < depth_image.rows; v++) {
  26.             auto depth_value = depth_image.at<float>(u, v);
  27.             Point3f p;
  28.             p.x = ((u - CX)*depth_value*(1.0f / FX)) / 1000.0f;
  29.             p.y = ((v - CY)*depth_value*(1.0f / FY)) / 1000.0f;
  30.             p.z = (depth_value) / 1000.0f;
  31.             xyzBuffer.emplace_back(p);
  32.         }
  33.     }*/
  34.     xyzMap = Mat(xyzBuffer, true).reshape(3, 480);
  35.     namedWindow("xyz Map", WINDOW_AUTOSIZE);
  36.     imshow("xyz Map", xyzMap);
  37.     waitKey(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement