Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. pcl::PointCloud<RIFT32>::Ptr processRIFT(
  2. pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud) {
  3. // ------------------------------------------------------------------
  4. // -----Read ply file-----
  5. // ------------------------------------------------------------------
  6. //Asign pointer to the keypoints cloud
  7. /*pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudColor(
  8. new pcl::PointCloud<pcl::PointXYZRGB>);
  9. pcl::PointCloud<pcl::PointXYZRGB>& point_cloud = *cloudColor;
  10. if (pcl::io::loadPLYFile(filename, point_cloud) == -1) {
  11. cerr << "Was not able to open file "" << filename << "".n";
  12. printUsage("");
  13. }*/
  14.  
  15. // Object for storing the point cloud with intensity value.
  16. pcl::PointCloud<pcl::PointXYZI>::Ptr cloudIntensityGlobal(
  17. new pcl::PointCloud<pcl::PointXYZI>);
  18. // Convert the RGB to intensity.
  19. pcl::PointCloudXYZRGBtoXYZI(*cloud, *cloudIntensityGlobal);
  20.  
  21.  
  22. pcl::PointCloud<pcl::PointWithScale> sifts = processSift(cloud);
  23. //We find the corresponding point of the sift keypoint in the original
  24. //cloud and store it with RGB so that it can be transformed into
  25. intensity
  26. pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_Color(
  27. new pcl::PointCloud<pcl::PointXYZRGB>);
  28. pcl::PointCloud<pcl::PointXYZRGB>& point_cloud_sift = *cloud_Color;
  29. for (int i = 0; i < sifts.points.size(); ++i) {
  30. pcl::PointWithScale pointSift = sifts.points[i];
  31. pcl::PointXYZRGB point;
  32. for (int j = 0; j < cloud->points.size(); ++j) {
  33. point = cloud->points[j];
  34. /*if (pointSift.x == point.x && pointSift.y == point.y
  35. && pointSift.z == point.z) {*/
  36.  
  37. if (sqrt(
  38. pow(pointSift.x - point.x, 2)
  39. + pow(pointSift.y - point.y, 2)
  40. + pow(pointSift.z - point.z, 2)) < 0.005) {
  41. point_cloud_sift.push_back(point);
  42. //std::cout << point.x << " " << point.y << " " << point.z
  43. << std::endl;
  44. break;
  45. }
  46. }
  47. }
  48.  
  49. cout << "Keypoint cloud has " << point_cloud_sift.points.size()
  50. << " pointsn";
  51.  
  52. // Object for storing the point cloud with intensity value.
  53. pcl::PointCloud<pcl::PointXYZI>::Ptr cloudIntensityKeypoints(
  54. new pcl::PointCloud<pcl::PointXYZI>);
  55. // Object for storing the intensity gradients.
  56. pcl::PointCloud<pcl::IntensityGradient>::Ptr gradients(
  57. new pcl::PointCloud<pcl::IntensityGradient>);
  58. // Object for storing the normals.
  59. pcl::PointCloud<pcl::Normal>::Ptr normals(new
  60. pcl::PointCloud<pcl::Normal>);
  61. // Object for storing the RIFT descriptor for each point.
  62. pcl::PointCloud<RIFT32>::Ptr descriptors(new pcl::PointCloud<RIFT32>
  63. ());
  64.  
  65. // Convert the RGB to intensity.
  66. pcl::PointCloudXYZRGBtoXYZI(*cloud_Color, *cloudIntensityKeypoints);
  67. std::cout << "Size: " << cloudIntensityKeypoints->points.size() <<
  68. "n";
  69.  
  70. // Estimate the normals.
  71. pcl::NormalEstimation<pcl::PointXYZI, pcl::Normal> normalEstimation;
  72. normalEstimation.setInputCloud(cloudIntensityGlobal);
  73. //normalEstimation.setSearchSurface(cloudIntensityGlobal);
  74. normalEstimation.setRadiusSearch(0.03);
  75. pcl::search::KdTree<pcl::PointXYZI>::Ptr kdtree(
  76. new pcl::search::KdTree<pcl::PointXYZI>);
  77. normalEstimation.setSearchMethod(kdtree);
  78. normalEstimation.compute(*normals);
  79.  
  80. // Compute the intensity gradients.
  81. pcl::IntensityGradientEstimation<pcl::PointXYZI, pcl::Normal,
  82. pcl::IntensityGradient,
  83. pcl::common::IntensityFieldAccessor<pcl::PointXYZI> > ge;
  84. ge.setInputCloud(cloudIntensityGlobal);
  85. //ge.setSearchSurface(cloudIntensityGlobal);
  86. ge.setInputNormals(normals);
  87. ge.setRadiusSearch(0.03);
  88. ge.compute(*gradients);
  89.  
  90. // RIFT estimation object.
  91. pcl::RIFTEstimation<pcl::PointXYZI, pcl::IntensityGradient, RIFT32>
  92. rift;
  93. rift.setInputCloud(cloudIntensityKeypoints);
  94. rift.setSearchSurface(cloudIntensityGlobal);
  95. rift.setSearchMethod(kdtree);
  96. // Set the intensity gradients to use.
  97. rift.setInputGradient(gradients);
  98. // Radius, to get all neighbors within.
  99. rift.setRadiusSearch(0.05);
  100. // Set the number of bins to use in the distance dimension.
  101. rift.setNrDistanceBins(4);
  102. // Set the number of bins to use in the gradient orientation
  103. dimension.
  104. rift.setNrGradientBins(8);
  105. // Note: you must change the output histogram size to reflect the
  106. previous values.
  107.  
  108. rift.compute(*descriptors);
  109. cout << "Computed " << descriptors->points.size() << " RIFT
  110. descriptorsn";
  111.  
  112. //matchRIFTFeatures(*descriptors, *descriptors);
  113. return descriptors;
  114. }
  115.  
  116. int matchRIFTFeatures(pcl::PointCloud<RIFT32>::Ptr descriptors1,
  117. pcl::PointCloud<RIFT32>::Ptr descriptors2) {
  118. int correspondences = 0;
  119. for (int i = 0; i < descriptors1->points.size(); ++i) {
  120. RIFT32 des1 = descriptors1->points[i];
  121. double minDis = 100000000000000000;
  122. double actDis = 0;
  123. //Find closest descriptor
  124. for (int j = 0; j < descriptors2->points.size(); ++j) {
  125. actDis = distanceRIFT(des1, descriptors2->points[j]);
  126. //std::cout << "act distance: " << actDis << std::endl;
  127. if (actDis < minDis) {
  128. minDis = actDis;
  129. }
  130. }
  131. //std::cout << "min distance: " << minDis << std::endl;
  132. //If distance between both descriptors is less than threshold we
  133. found correspondence
  134. if (minDis < 0.5)
  135. ++correspondences;
  136. }
  137. return correspondences;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement