def isplanar(xyz,sample_neighbors,dist_thresh,num_inliers,z_proj): """ Checks if at-least FRAC_INLIERS fraction of points of XYZ (nx3) points lie on a plane. The plane is fit using RANSAC. XYZ : (nx3) array of 3D point coordinates SAMPLE_NEIGHBORS : 5xN_RANSAC_TRIALS neighbourhood array of indices into the XYZ array. i.e. the values in this matrix range from 0 to number of points in XYZ DIST_THRESH (default = 10cm): a point pt is an inlier iff dist(plane-pt)<dist_thresh FRAC_INLIERS : fraction of total-points which should be inliers to to declare that points are planar. Z_PROJ : changes the surface normal, so that its projection on z axis is ATLEAST z_proj. Returns: None, if the data is not planar, else a 4-tuple of plane coeffs. """ frac_inliers = num_inliers/xyz.shape[0] dv = -np.percentile(xyz,50,axis=0) # align the normal to face towards camera max_iter = sample_neighbors.shape[-1] plane_info = fit_plane_ransac(xyz,neighbors=sample_neighbors, z_pos=dv,dist_inlier=dist_thresh, min_inlier_frac=frac_inliers,nsample=20, max_iter=max_iter) if plane_info != None: coeff, inliers = plane_info coeff = ensure_proj_z(coeff, z_proj) return coeff,inliers else: return #None