Advertisement
jarod_reynolds

icp

Apr 15th, 2021
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. % ICP - Bunny Example
  2. % -----------------------------------
  3. clear
  4. load_vars = 'on';
  5. clf
  6.  
  7.  
  8.  
  9.  
  10. % TODO
  11. % SVD - Singular Value Deposition
  12. % ICP Algorithm
  13.  
  14. % Links
  15. if(load_vars == 'on')
  16. ptCloudRef = pcread('A2_PointClouds/Pose1/1453.268000000.pcd');
  17. ptCloudCurrent = pcread('A2_PointClouds/Pose2/1622.950000000.pcd');
  18.  
  19. points = {ptCloudRef, ptCloudCurrent};
  20. %gridStep = 0.1;
  21. % ptCloudRef = pcdenoise(ptCloudRef);
  22. % ptCloudCurrent = pcdenoise(ptCloudCurrent);
  23. % ptCloudRef = pcdownsample(ptCloudRef,'nonuniformGridSample', 50);
  24. % ptCloudCurrent = pcdownsample(ptCloudCurrent,'nonuniformGridSample', 50);
  25. ptCloudRef = pcnormals(ptCloudRef, 10);
  26. ptCloudCurrent = pcnormals(ptCloudCurrent, 10);
  27. end
  28.  
  29.  
  30. i = 1;
  31. tf = 1;
  32. for j = 1:size(points, 2)-1
  33. %selecting});
  34. %Add in a Z column
  35. %ICP Algorithm
  36. tf_new = pcregistericp(pointCloud(ptCloudRef),pointCloud(ptCloudCurrent),'InlierRatio', .5, 'Tolerance',[0.0001, 0.00011], 'MaxIterations', 100);
  37. %tf_new = pcregistericp(pointCloud(ptCloudCurrent),pointCloud(ptCloudRef),'Tolerance',[0.0001, 0.0001], 'MaxIterations', 500, 'InlierRatio', 0.97
  38. %returns a transformation
  39. tf = tf * tf_new.T';
  40. translation = [tf(1:3,4)];
  41. rotation = [tf(1:3, 1:3)];
  42. i = i+1;
  43. end
  44. % Create the transformed bunny from the current result
  45. tform = rigid3d(rotation, translation');
  46. ptCloudNew = pctransform(points{2}, tform);
  47. ptCloudNew = ptCloudNew.Location;
  48.  
  49. ptCloudCurrent = points{1}.Location;
  50. ptCloudRef = points{2}.Location;
  51.  
  52.  
  53. figure(1)
  54. scatter3(ptCloudCurrent(:, 1), ptCloudCurrent(:, 2), ptCloudCurrent(:, 3), 'b')
  55. hold on
  56. scatter3(ptCloudRef(:, 1), ptCloudRef(:, 2), ptCloudRef(:, 3), 'g');
  57. hold on
  58. scatter3(ptCloudNew(:, 1), ptCloudNew(:, 2), ptCloudNew(:, 3), 'r');
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement