53433

Fit a plane to a 3D point cloud in C++

Question:

I want to fit a plane to a 3D point cloud. I use a RANSAC approach, where I sample several points from the point cloud, calculate the plane and store the plane with the smallest error. The error is the distance between the points and the plane. I want to do this in C++, using Eigen.

So far, I sample points from the point cloud and center the data. Now, I need to fit the plane to the samples points. I know I need to solve Mx = 0, but how do I do this? So far I have M (my samples), I want to know x (the plane) and this fit needs to be as close to 0 as possible. I have no idea where to continue from here. All I have are my sampled points and I need more data. I feel like all information is there, I am overlooking something.

Answer1:

From you question I assume that you are familiar with the Ransac algorithm, so I will spare you of lengthy talks.

In a first step, you sample three random points. You can use the <a href="http://eigen.tuxfamily.org/dox/classEigen_1_1DenseBase.html#a8e759dafdd9ecc446d397b7f5435f60a" rel="nofollow">Random</a> class for that but picking them not truly random usually gives better results. To those points, you can simply fit a plane using <a href="http://eigen.tuxfamily.org/dox/classEigen_1_1Hyperplane.html#aabfcda23a80edfd62387bb3d930f4b96" rel="nofollow">Hyperplane::Through</a>.

In the second step, you repetitively cross out some points with large <a href="http://eigen.tuxfamily.org/dox/classEigen_1_1Hyperplane.html#a8383bb22fa5f6024856f2c781f6ec0db" rel="nofollow">Hyperplane::absDistance</a> and perform a least-squares fit on the remaining ones. It may look like this:

Vector3f mu = mean(points); Matrix3f covar = covariance(points, mu); Vector3 normal = smallest_eigenvector(covar); JacobiSVD<Matrix3f> svd(covariance, ComputeFullU); Vector3f normal = svd.matrixU().col(2); Hyperplane<float, 3> result(normal, mu);

Unfortunately, the functions mean and covariance are not built-in, but they are rather straightforward to code.

Recommend

  • Using datepicker within haml
  • PHP String reversal without using extra memory
  • GridBagLayout: How to set fixed column width?
  • JPanel Won't Focus After Switching in CardLayout
  • Pandas: add column with the most recent values
  • Get an entire string or a substring, depending on a specific character
  • How to use function declaration with jsfiddle
  • Sharing global variables between different Lua states through require
  • iOS app camera orientation in captureOutput
  • Implicit declaration of scandir; alphasort is undeclared
  • DateTimeFormat.AbbreviatedMonthNames adding a dot at the end of month's name
  • Flex: DataGrid column formatting of numbers
  • SQLite INSERT SELECT Query Results into Existing Table?
  • Bootstrap 4 - Center List
  • Trying to place multiple Bootstrap Thumbnails side-by-side
  • Override Data Tip Circle
  • Group variable in cobol
  • R h2o.glm - issue with max_active_predictors
  • How can I speed up CURL tasks?
  • Moving Android View and preventing onDraw to be called over and over again
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • FileReader+canvas image loading problem
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Why value captured by reference in lambda is broken? [duplicate]
  • Read text file and split every line in MSBuild
  • Optimizing database types to compact database (SQLite)
  • C# - Serializing and deserializing static member
  • TFS: Get latest causes slow project reloading
  • Java applet as stand-alone Windows application?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Running a C# exe file
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • Arrays break string types in Julia
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Error creating VM instance in Google Compute Engine
  • Change div Background jquery
  • Reading document lines to the user (python)