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

Getting Runtime error when fitting. #28

Open
aswathyr001 opened this issue Feb 15, 2022 · 3 comments
Open

Getting Runtime error when fitting. #28

aswathyr001 opened this issue Feb 15, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@aswathyr001
Copy link

Encountered the error when plane fitting:

/usr/local/lib/python3.8/dist-packages/pyransac3d/plane.py:59: RuntimeWarning: invalid value encountered in true_divide
vecC = vecC / np.linalg.norm(vecC)

Code Attached:

def plane_fit(pointList):
[X, Y, Z, I] = pointList
p_arr = np.empty((len(X), 3), float)
P_color_arr = np.empty((0, 3), int)

print('print len of full points')
print(len(X))
for i in range(len(X)):
    p_arr = np.append(p_arr, np.array([[X[i], Y[i], Z[i]]]), axis=0)
    P_color_arr = np.append(p_arr, np.array([[I[i], 0, 0]]), axis=0)

plane1 = pyrsc.Plane()

# Load saved point cloud and visualize it
pcd_load = o3d.geometry.PointCloud()
pcd_load.points = o3d.utility.Vector3dVector(p_arr)
pcd_load.colors = o3d.utility.Vector3dVector(P_color_arr)
print("pcd created")
# o3d.visualization.draw_geometries([pcd_load])
points = np.asarray(pcd_load.points)


best_eq, best_inliers = plane1.fit(points, 1)
X_new = []
Y_new = []
Z_new = []
I_new = []
print("Printing len of inliners")
print(len(best_inliers))
print("Equation:")
print(best_eq)
for i in range(len(p_arr)):
    if i in best_inliers:
        X_new.append(p_arr[i][0])
        Y_new.append(p_arr[i][1])
        Z_new.append(p_arr[i][2])
        I_new.append(1)


print(len(X_new))
return [X_new, Y_new, Z_new, I_new]
@River-mao
Copy link

I also face this problem, have you solved this? Thanks a lot!

@leomariga
Copy link
Owner

@River-mao Not yet, but working on it

@leomariga leomariga added the bug Something isn't working label Mar 20, 2022
@wct432
Copy link

wct432 commented Sep 9, 2022

This error occurs when the vecA and vecB vectors are parallel, resulting in a zero vectorC after the cross product. I fixed it by adding the following lines after vecC is computed, on line 57 of planes.py:

        (57.)       # if vectors A and B are pallel vector C will be a zero vector resulting in a divide by zero error in the next step
        (58.)       if np.any(vecC) == False:
        (59.)           continue

I will open a pull request with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants