Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include "../../render/render.h"
  2. #include <unordered_set>
  3. #include "../../processPointClouds.h"
  4. // using templates for processPointClouds so also include .cpp to help linker
  5. #include "../../processPointClouds.cpp"
  6. #include <random>
  7. #include <algorithm>
  8. #include <experimental/algorithm>
  9.  
  10. std::unordered_set<int> Ransac(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, int maxIterations, float distanceTol)
  11. {
  12. std::unordered_set<int> inliersResult;
  13. srand(time(NULL));
  14.  
  15. while(maxIterations--) {
  16. std::unordered_set<int> inliers; // store the inliers here in each iteration
  17. int sample_size {2};
  18. std::vector<pcl::PointXYZ> sample (sample_size);
  19. std::sample(cloud->points.begin(), cloud->points.end(), std::back_inserter(sample),
  20. sample_size, std::mt19937{std::random_device{}()});
  21.  
  22. // fit a line ax + by+ c = 0 to the points in sample using (y0−y1)x+(x1−x0)y+(x0∗y1−x1∗y0)=0
  23. double x0 {sample.at(0).x}, y0 {sample.at(0).y}, x1 {sample.at(1).x}, y1 {sample.at(1).y};
  24. double a {y0 - y1};
  25. double b {x1 - x0};
  26. double c {x0 * y1 - x1 * y0};
  27.  
  28. // find the distance to this line for all points in the cloud. If the distance is less than
  29. // distanceTol at the index of the point to inliers
  30. for(auto& point: cloud->points) {
  31. double distance = fabs(a * point.x - b * point.y - c) / sqrt(std::pow(a, 2) + std::pow(b, 2));
  32. if (distance < distanceTol) {
  33. // add the index of the point to inliers
  34. auto index = std::find(cloud->points.begin(), cloud->points.end(), point);
  35. inliers.emplace(index);
  36. }
  37. }
  38. if (inliers.size() > inliersResult.size()) { inliersResult = inliers; }
  39. }
  40.  
  41. return inliersResult;
  42. }
  43.  
  44. error: no member named 'sample' in namespace 'std'
  45. std::sample(cloud->points.begin(), cloud->points.end(), std::back_inserter(sample),
  46.  
  47. /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:999:22: error: invalid operands to binary expression ('pcl::PointXYZ' and 'const pcl::PointXYZ')
  48. if (*__first == __value_)
  49.  
  50.  
  51.  
  52. /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:1825:31: error: no viable conversion from 'std::__1::__wrap_iter<pcl::PointXYZ *>' to 'int'
  53. ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement