I would like to construct a plane from a list of 3D points in OpenCV. I would like to obtain the result by finding the four parameters in the following form: Ax+By+Cz+D = 0
. Would anyone suggest me a way to do it?
Asked
Active
Viewed 7,214 times
1

Kevin Katzke
- 3,581
- 3
- 38
- 47

Carl
- 105
- 3
- 12
-
1Does the data contain outliers? – Humam Helfawi Nov 30 '15 at 11:14
-
principal component analysis should give good results in theory. I'd suggest you a simple RANSAC method though. You should present a 3D image of your points to give an idea about your setting. – Micka Nov 30 '15 at 11:23
-
Maybe some kind of linear least squares may help you? – Daiver Nov 30 '15 at 11:26
-
@HumamHelfawi Well, at this point outliers are ignored – Carl Nov 30 '15 at 13:00
-
So see my answer it is going to solve the problem, you may ask about any ambiguity. – Humam Helfawi Nov 30 '15 at 13:10
2 Answers
4
If the data does not contain outliers and does not contain more than one plane. Furthermore, all the points lay exactly on a plane (the data is not noisy), it is so simple:
- Pick up three random points which are not lay on the same line.
- solve this system of linear equations:
x1+by1+cz1+d = 0 x2+by2+cz2+d = 0 x3+by3+cz3+d = 0
then :
A= Choose any number you want in order to match your scale. B= b*A C= c*A D= d*A
If the data is noisy or contains outliers or more than plane (or both) you need then some kind of Robust Estimation techniques. Search for RANSAC as a start.
if you are familar with RANSAC you can see this example here (it is about lines you can simply generlize it to deal with plane)

Humam Helfawi
- 19,566
- 15
- 85
- 160
-
Finally, I find a way by using the class SVD to solve the problem. First I transform the equation of plane from `AX+BY+CZ+D = 0` to `A'X+B'Y+C' = Z`, so the required parameters to characterize a plane becomes 3. Then by applying `SVD sample(leftMatrix); sample.backSubst(z, result);` where leftMatrix is a n*3 matrix containing each row (x_i, y_i, 1), z is just all the points of z coordinates in n*1 matrix form, variable"result" finally conotains the calculated plane parameters. – Carl Dec 10 '15 at 13:31
-
Anyway, thank you for your answer as your answer inspried me to reach my current solution. – Carl Dec 10 '15 at 13:35
-
1glad it helped. You may accept this answer or try to write a full answer by yourself and accept your own. good luck – Humam Helfawi Dec 10 '15 at 13:37
1
Answer by leveraging OpenCV
If you want to have equation solved by 3 points, just like follows:
ax + by + cz = 1
Example
you have three points: cv::Point3f p1, p2 and p3, and here is the code:
cv::Matx33f M(p1.x, p1.y, p1.z,
p2.x, p2.y, p2.z,
p3.x, p3.y, p3.z);
cv::Vec3f d(1, 1, 1);
cv::Vec3f coef = M.inv() * d;
Then, a, b, c are coef(0), coef(1), coef(2) sequentially.

Chaohsiung Huang
- 154
- 1
- 4