-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add least squares fit to existing ransac models #29
Comments
so I was playing around and made a sphere generator today if you are interested in using it for testing the sphere fit. |
Will take a look!. Thanks |
So I added the least squares fit code. Now you can pass import numpy as np
import pandas as pd
from pyntcloud import PyntCloud
from pyntcloud.ransac.fitters import single_fit
from pyntcloud.ransac.models import RansacSphere
def sphere(center=[0,0,0], radius=20, no_points=100):
np_axis = round(np.sqrt(no_points - 2),0) +1
index = np.arange(0,np.square(np_axis)+2,1)
new = pd.DataFrame(np.zeros([np.size(index,0),3]),index=index, columns=['x','y','z'])
zmin = center[2] - radius
zmax = center[2] + radius
tick = 2*np.pi/(np_axis+1)
xx = np.arange(tick,2*np.pi,tick)
yy = np.arange(tick,2*np.pi,tick)
u,v = np.meshgrid(xx,yy)
x = radius*np.cos(u)*np.sin(v) + center[0]
y = radius*np.sin(u)*np.sin(v) + center[1]
z = radius*np.cos(v) + center[2]
X = np.arange(0,1)
Y = np.arange(0,1)
Z = np.arange(0,1)
X[0] = center[0]
Y[0] = center[1]
Z[0] = zmin
X = np.append(X,x.reshape([1,np.size(x)]))
Y = np.append(Y,y.reshape([1,np.size(y)]))
Z = np.append(Z,z.reshape([1,np.size(z)]))
X = np.append(X,center[0])
Y = np.append(Y,center[1])
Z = np.append(Z,zmax)
new.x = np.round(X.T,4).astype(np.float32)
new.y = np.round(Y.T,4).astype(np.float32)
new.z = np.round(Z.T,4).astype(np.float32)
pyntcloud = PyntCloud(new)
return pyntcloud
sphere_cloud = sphere(no_points=10000)
inliers, best_model = single_fit(sphere_cloud.points.values, RansacSphere, return_model=True) |
@threerivers3d-jc I will probably add the sphere generator code somewhere in the geometry package. The noise code is not working for me, I'll take a look on how to fix it. By the way, be aware of converting the dtype of pandas DataFrame to float32 until I fix #97 . float64 is the default in numpy and pandas and it breaks things in ply format for example and in PyntCloud.plot |
Awesome, thanks for the heads up. I am using my own function to plot in figure windows as I develop in spyder instead of jupyter notebook, I haven't noticed any errors in my work so far. I'll keep an eye out for them. I'm mainly working on working through our past data sets to compare my measurements to the old matlab script we currently use. |
No description provided.
The text was updated successfully, but these errors were encountered: