Skip to content
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

Closed
daavoo opened this issue Apr 7, 2017 · 5 comments
Closed

Add least squares fit to existing ransac models #29

daavoo opened this issue Apr 7, 2017 · 5 comments
Assignees

Comments

@daavoo
Copy link
Owner

daavoo commented Apr 7, 2017

No description provided.

@daavoo daavoo self-assigned this Apr 7, 2017
@daavoo daavoo modified the milestone: Version 9000 release Apr 24, 2017
@threerivers3d-jc
Copy link
Contributor

so I was playing around and made a sphere generator today if you are interested in using it for testing the sphere fit.

Here's the code for it and the noise generator.

@daavoo
Copy link
Owner Author

daavoo commented Jun 9, 2017

Will take a look!. Thanks

@daavoo
Copy link
Owner Author

daavoo commented Jun 14, 2017

So I added the least squares fit code. Now you can pass return_model=True to single_fit:

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)

@daavoo
Copy link
Owner Author

daavoo commented Jun 14, 2017

@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

@threerivers3d-jc
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants