{"id":17841694,"url":"https://github.com/blackcipher101/pcl","last_synced_at":"2025-03-22T14:41:08.988Z","repository":{"id":119133471,"uuid":"414915336","full_name":"Blackcipher101/PCL","owner":"Blackcipher101","description":"Using Point Cloud Library to do stuff like filters down sample and many more","archived":false,"fork":false,"pushed_at":"2022-02-07T16:50:56.000Z","size":23287,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T01:41:25.328Z","etag":null,"topics":["dept","depth-camera","pcl","python"],"latest_commit_sha":null,"homepage":"","language":"Cython","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blackcipher101.png","metadata":{"files":{"readme":"ReadME.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-08T08:58:30.000Z","updated_at":"2025-03-01T20:29:30.000Z","dependencies_parsed_at":"2023-07-09T23:15:29.789Z","dependency_job_id":null,"html_url":"https://github.com/Blackcipher101/PCL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackcipher101%2FPCL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackcipher101%2FPCL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackcipher101%2FPCL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackcipher101%2FPCL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blackcipher101","download_url":"https://codeload.github.com/Blackcipher101/PCL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244973701,"owners_count":20541021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dept","depth-camera","pcl","python"],"created_at":"2024-10-27T21:06:03.000Z","updated_at":"2025-03-22T14:41:08.968Z","avatar_url":"https://github.com/Blackcipher101.png","language":"Cython","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PCL\n\n## Depth map amd depth cameras :camera:\n**Depth cameras** are cameras which give back depth data its better then stereo camera retup as it has a higer realibity and is better then lidar as its more cost-effective. RGB-D cameras use an IR sensor and projector to map the depth locatation to the respective pixels on the map.\n\nHere is an example of using a Depth Map and Image to find its point cloud\n![](images/Screenshot%20from%202021-10-08%2014-25-09.png)\n\n## Point cloud Library :red_circle:\n\n### DownSample\n\nDown Sampling is very imporatnt tool to reduce computation time as larger amplitue of the signal higher the amplitude of noise so we can nreduce the absolte value of the noise\nwe used Voxel Grid filter to downsample\n``` python\nvox = cloud.make_voxel_grid_filter()\nLEAF_SIZE = 0.01\nvox.set_leaf_size(LEAF_SIZE,LEAF_SIZE,LEAF_SIZE)\ncloud_filtred = vox.filter()\n```\n### Passthrough\n\nPassthrough filters are something like band pass filters in commounicaction it just allows value in a certian region along a axis\n``` python\nfilter_axis = 'z'\npassthrough = cloud_filtred.make_passthrough_filter()\npassthrough.set_filter_field_name(filter_axis)\nax_min=0.78\nax_max=1.2\npassthrough.set_filter_limits(ax_min,ax_max)\ncloud_filtred = passthrough.filter()\n```\n![](images/Screenshot%20from%202021-10-08%2017-18-22.png)\n\n### RANSAC\nNext in your perception pipeline, you need to remove the table itself from the scene. To do this you will use a popular technique known as Random Sample Consensus or \"RANSAC\". RANSAC is an algorithm, that you can use to identify points in your dataset that belong to a particular model. In the case of the 3D scene you're working with here, the model you choose could be a plane, a cylinder, a box, or any other common shape.\n\nThe RANSAC algorithm assumes that all of the data in a dataset is composed of both inliers and outliers, where inliers can be defined by a particular model with a specific set of parameters, while outliers do not fit that model and hence can be discarded. Like in the example below, we can extract the outliners that are not good fits for the model.\n``` python\nseg = cloud_filtred.make_segmenter()\nseg.set_model_type(pcl.SACMODEL_PLANE)\nseg.set_method_type(pcl.SAC_RANSAC)\nmax_dis=0.01\nseg.set_distance_threshold(max_dis)\ninliners,coffe=seg.segment()\nextracted_inliners=cloud_filtred.extract(inliners,negative=False)\nfilename=\"inliner.pcd\"\npcl.save(extracted_inliners,filename)\ntry:\n    extracted_outliners=cloud_filtred.extract(inliners,negative=True)\nexcept RuntimeError:\n    print(\"maxdis wrong\")\nelse:\n    filename = 'extracted.pcd'\n    pcl.save(extracted_outliners,filename)\n```\n![](images/Screenshot%20from%202021-10-12%2012-38-07.png)\n### Noise Filter\n\n#### Stastical_filter\nAlthough calibration can solve the distortion problem, noise caused by external factors (such as dust in the environment, humidity in the air, or the presence of various light sources) can cause sparse outliers, which can further ruin the results.\n\nThese outliers will complicate the estimation of point cloud features (such as curvature, gradient, etc.), leading to incorrect values, which may lead to failures in various stages of our perception process.\n\nOne filtering technique used to remove such outliers is to perform statistical analysis near each point and remove those points that do not meet certain conditions. PCL's Statistics Outlier Removal filter is an example of one of the filtering techniques. For each point in the point cloud, it calculates the distance to all its neighbors, and then calculates the average distance.\n\nBy assuming a Gaussian distribution, all points whose average distance is outside the interval defined by the global distance mean + standard deviation are regarded as outliers and deleted from the point cloud.\n![](images/Screenshot%20from%202021-10-12%2012-52-59.png)\n``` python\n fil = p.make_statistical_outlier_filter()\n    fil.set_mean_k(50)\n    fil.set_std_dev_mul_thresh(1.0)\n\n    pcl.save(fil.filter(),\n             \"table_scene_lms400_inliers.pcd\")\n\n    fil.set_negative(True)\n    pcl.save(fil.filter(),\n             \"table_scene_lms400_outliers.pcd\")\n```\n\n## Segmtation and clustering\n\n### K-means clustering\nK-means clustering is implemented as follows:\n\n- Assume you have n data points p1, p2, p3, . . , pn and plan to divide them into k clusters.\n- Start by selecting k individual points c1,c2, . . .,ck  from the dataset as the initial cluster centroids.\n- Establish convergence and termination criteria (stability of solution and maximum number of iterations)\n- In the absence of convergence / termination criteria, do:\n    - for \n    - i=1 to n:\n    - Calculate distance from pi to each cluster centroid\n    - Assign pi to its closest centroid and label it accordingly\n    - endfor\n    - For j = 1 to k:\n    - Recompute the centroid of cluster j based on the average of all data point that belog to the cluster\n    - endfor\n- end\n\n![](images/1.png)\n\n### DBSCAN Algorithm\nDBSCAN stands for Density-Based Spatial Clustering of Applications with Noise. This algorithm is a nice alternative to k-means when you don' t know how many clusters to expect in your data, but you do know something about how the points should be clustered in terms of density (distance between points in a cluster).\nSuppose you have a set PP of nn data points p1,p2,..., pn​:\n\n-   Set constraints for the minimum number of points that comprise a cluster (`min_samples`)\n-   Set distance threshold or maximum distance between cluster points (`max_dist`)\n-   For every point p_ipi​ in PP, do:\n    -   if pi​ has at least one neighbor within `max_dist`:\n        -   if pi​'s neighbor is part of a cluster:\n            -   add p_ipi​ to that cluster\n        -   if pi​ has at least `min_samples`-1 neighbors within `max_dist`:\n            -   pi​ becomes a \"core member\" of the cluster\n        -   else:\n            -   pi​ becomes an \"edge member\" of the cluster\n    -   else:\n        -   pi​ is defined as an outlier\n![](images/2.png)\n### ROS PCL\nThis package provides interfaces and tools for bridging a running ROS system to the Point Cloud Library. These include ROS nodelets, nodes, and C++ interfaces.\n\n![](images/3.png)\n\n---\n\n![](images/4.png)\n\nin this we cluster using the above DBSANC algorithm\n\n```python\n    cloud = ros_to_pcl(pcl_msg)\n    vox = cloud.make_voxel_grid_filter()\n    # TODO: Voxel Grid Downsampling\n    LEAF_SIZE = 0.01   \n    vox.set_leaf_size(LEAF_SIZE, LEAF_SIZE, LEAF_SIZE)\n    cloud_filtered = vox.filter()\n    # TODO: PassThrough Filter\n    passthrough = cloud_filtered.make_passthrough_filter()\n\n    # TODO: RANSAC Plane Segmentation\n    filter_axis = 'z'\n    passthrough.set_filter_field_name(filter_axis)\n    axis_min = 0.76\n    axis_max = 1.1\n    passthrough.set_filter_limits(axis_min, axis_max)\n    # TODO: Extract inliers and outliers\n    cloud_filtered = passthrough.filter()\n    seg = cloud_filtered.make_segmenter()\n    seg.set_model_type(pcl.SACMODEL_PLANE)\n    seg.set_method_type(pcl.SAC_RANSAC)\n    max_distance = 0.01\n    seg.set_distance_threshold(max_distance)\n    inliers, coefficients = seg.segment()\n    extracted_inliers = cloud_filtered.extract(inliers, negative=False)\n    extracted_outliers = cloud_filtered.extract(inliers, negative=True)\n    ros_cloud_objects = pcl_to_ros(extracted_outliers)\n    ros_cloud_table   = pcl_to_ros(extracted_inliers)\n\n    # TODO: Euclidean Clustering\n    white_cloud = XYZRGB_to_XYZ(extracted_outliers)\n    tree = white_cloud.make_kdtree()\n\n    # Create a cluster extraction object\n    ################################\n    ec = white_cloud.make_EuclideanClusterExtraction()\n    # Set tolerances for distance threshold \n    # as well as minimum and maximum cluster size (in points)\n    # NOTE: These are poor choices of clustering parameters\n    # Your task is to experiment and find values that work for segmenting objects.\n    ec.set_ClusterTolerance(0.03)\n    ec.set_MinClusterSize(10)\n    ec.set_MaxClusterSize(3000)\n    \n    # Search the k-d tree for clusters\n    ec.set_SearchMethod(tree)\n    \n    # Extract indices for each of the discovered clusters\n    cluster_indices = ec.Extract()\n\n    # Create Cluster-Mask Point Cloud to visualize each cluster separately\n    ################################\n    # Assign a color corresponding to each segmented object in scene\n    cluster_color = get_color_list(len(cluster_indices))\n\n    color_cluster_point_list = []\n\n    for j, indices in enumerate(cluster_indices):\n        for i, indice in enumerate(indices):\n            color_cluster_point_list.append([white_cloud[indice][0],\n                                             white_cloud[indice][1],\n                                             white_cloud[indice][2],\n                                             rgb_to_float(cluster_color[j])])\n\n    # Create new cloud containing all clusters, each with unique color\n    ################################\n    cluster_cloud = pcl.PointCloud_PointXYZRGB()\n    cluster_cloud.from_list(color_cluster_point_list)\n    ros_cluster_cloud = pcl_to_ros(cluster_cloud)\n```\nthis creates the clusters\n\n### object recgonctition\nSVMs work by applying an iterative method to a training dataset, where each item in the training set is characterized by a feature vector and a label. In the image above, each point is characterized by just two features, A and B. The color of each point corresponds to its label, or which class of object it represents in the dataset.\n\n\n![](images/5.png)\n![](images/6.png)\n### *This repo is under development and contains all my learnings about PCL*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackcipher101%2Fpcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackcipher101%2Fpcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackcipher101%2Fpcl/lists"}