daavoo / pyntcloud

pyntcloud is a Python library for working with 3D point clouds.
http://pyntcloud.readthedocs.io
MIT License
1.4k stars 223 forks source link

aX+bY+cZ+d plane fitting #255

Closed brm31596 closed 5 years ago

brm31596 commented 5 years ago

Hi,

I have a Pointcloud where all points are lying on a plane which is oriented somehow in the 3D space. I'd like to determine the a,b,c,d of aX+bY+cZ+d. Are this kinds of problems implemented?

PyntCloud.add_scalar_field(cloud) adds an aditional 1 to each point, but this just tells me every point is on the plane :) I tried plane = pyntcloud.scalar_fields.PlaneFit(cloud_1) but I got an error:

**_plane = pyn.scalar_fields.PlaneFit(cloud_1, max_dist=0.1)

Traceback (most recent call last):

File "", line 1, in

plane = pyn.scalar_fields.PlaneFit(cloud_1, max_dist=0.1)

TypeError: init() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given_**

I am using spyder and windows 10.

Michael

daavoo commented 5 years ago

Hola @brm31596 ! Yes, this is implemented, although it might be a little tricky to find. I think that you can achieve what you want as follows:

from pyntcloud.geometry.models.plane import Plane
plane = Plane()
plane.from_point_cloud(cloud.xyz)
plane.get_equation()

Feel free to re-open if you run intro problems

haoliangjiang commented 4 years ago

I am getting the same error and I am trying to use RANSAC. The code is like:

    cloud = pync.PyntCloud.from_instance("open3d", pcd_origin)
    pdb.set_trace()
    x = pync.scalar_fields.PlaneFit(*cloud.xyz)
    x.extract_info()
    x.compute()

Really cannot tell what's wrong here?

DustinReagan commented 4 years ago

@haoliangjiang

I am getting the same error and I am trying to use RANSAC. The code is like:

  cloud = pync.PyntCloud.from_instance("open3d", pcd_origin)
  pdb.set_trace()
  x = pync.scalar_fields.PlaneFit(*cloud.xyz)
  x.extract_info()
  x.compute()

Really cannot tell what's wrong here?

Here is how I fit an open3d pointcloud to a plane using RANSAC:

from pyntcloud.ransac.models import RansacPlane

def get_best_fit_plane(open3d_point_cloud):
    r_plane = RansacPlane()
    r_plane.fit(open3d_point_cloud.points) # or r_plane.least_squares_fit(open3d_point_cloud.points)
    return (r_plane.normal, r_plane.point)
xinseesea commented 11 months ago

Here is how I fit an open3d pointcloud to a plane using RANSAC:

from pyntcloud.ransac.models import RansacPlane

def get_best_fit_plane(open3d_point_cloud):
    r_plane = RansacPlane()
    r_plane.fit(open3d_point_cloud.points) # or r_plane.least_squares_fit(open3d_point_cloud.points)
    return (r_plane.normal, r_plane.point)

Hi @DustinReagan , can I specify max_dist and max_iterations in RansacPlane fit? Thanks!