Click here to Skip to main content
15,353,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to run an implementation of region growing for point clouds using python based on the documentation given by pcl. The shown error appears:
C:\Users\youss\AppData\Local\Temp\ipykernel_13008\ RuntimeWarning: invalid value encountered in arccos
  if all([nn_cur in order , np.arccos(np.abs([seed_cur[seedval]],normals[nn_cur])))<theta_th]):

the code:
import math
import numpy as np
from sklearn.neighbors import KDTree
tree    = KDTree(unique_rows, leaf_size=2) 
dist,nn_glob = tree.query(unique_rows[:len(unique_rows)], k=30) 
def normalsestimation(pointcloud,nn_glob,VP=[0,0,0]):
    ViewPoint = np.array(VP)
    normals = np.empty((np.shape(pointcloud)))
    curv    = np.empty((len(pointcloud),1))
    for index in range(len(pointcloud)):
        nn_loc = pointcloud[nn_glob[index]]
        COV = np.cov(nn_loc,rowvar=False)
        eigval, eigvec = np.linalg.eig(COV)
        idx = np.argsort(eigval)
        nor = eigvec[:,idx][:,0]
        if[index,:])) > 0:
            normals[index] = nor
            normals[index] = - nor
        curv[index] = eigval[idx][0] / np.sum(eigval)
    return normals,curv
def regiongrowing1(pointcloud,nn_glob,theta_th = 'auto', cur_th = 'auto'):
    normals,curvature = normalsestimation(pointcloud,nn_glob=nn_glob)
    order             = curvature[:,0].argsort().tolist()
    region            = []
    if theta_th == 'auto':
        theta_th          = 15.0 / 180.0 * math.pi # in radians
    if cur_th == 'auto':
        cur_th            = np.percentile(curvature,98)
    while len(order) > 0:
        region_cur = []
        seed_cur   = []
        poi_min    = order[0] #poi_order[0]
        seedval = 0

#        for i in range(len(seed_cur)):#change to while loop
        while seedval < len(seed_cur):
            nn_loc  = nn_glob[seed_cur[seedval]]
            for j in range(len(nn_loc)):
                nn_cur = nn_loc[j]
                if all([nn_cur in order , np.arccos(np.abs([seed_cur[seedval]],normals[nn_cur])))<theta_th]):
                    if curvature[nn_cur] < cur_th:
    return region
region1  = regiongrowing1(unique_rows,nn_glob)

What I have tried:

I've searched and found that this error is because the value given to arccos should be in the range[-1,1] but don't know where is the cause nor how to fix it!
Richard MacCutchan 29-Apr-22 7:18am
So use the debugger to find out what actual value is being passed, and why. Either you have bad data being input, or a calculation error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900