pcfitcylinder giving different answers

1 view (last 30 days)
Karen Kruger
Karen Kruger on 4 Oct 2017
Commented: Tim McKinley on 8 Jul 2019
I'm using pcfitcylinder to calculate a best fit cylinder to a point cloud. The code is giving me different solutions when I run the function for the same data. Is this a bug in the code? I need a function that will give me reliable answers.

Answers (2)

Jyotish Robin
Jyotish Robin on 9 Oct 2017
Hi Karen!
I understand that you are getting different results each time when you run the "pcfitcylinder" command. This behavior is due to the use of MSAC, a version or RANSAC algorithm. This algorithm is used inside the estimateEssentialMatrix that's part of the helperEstimateRelativePose.m file.
RANSAC uses a random process to initialize computation of a mathematical model, in this case an essential matrix, and to remove outliers from the data. This is expected behavior. It's the nature of this approach.
For debugging purpose, you can set the random seed before the "pcfitcylinder" command to get a deterministic result using the following command:
>> rng(0);
Hope this helps!
Regards ,
Jyotish
  1 Comment
Tim McKinley
Tim McKinley on 8 Jul 2019
Hi Jyotish,
I ran into the same problem as Karen and upon following your suggest I still seem to get various fits to the data. I read that RANSAC utilizes a random sample size as well and wondered if that would be causing the solution variability.
Are you aware of a way to fix the sample size RANSAC is using or how to fix additional variable that the solver is using (beside the few listed in the pcfitcylinder documentation) to force the exact same number of points and seed point?
Thanks

Sign in to comment.


Daniel Fiole
Daniel Fiole on 18 May 2018
Hi Karen,
Have you tried increasing the value of 'MaxNumTrials'?
Cheers, Daniel

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!