davidcaron / pclpy

Python bindings for the Point Cloud Library (PCL)
MIT License
428 stars 59 forks source link

Segmentation code not working #12

Closed niranjanreddy891 closed 6 years ago

niranjanreddy891 commented 6 years ago

check this link in the repository

This is the one which I am trying. :)

I tried even this code

import math
import os
import numpy as np
import pytest

import pclpy
from pclpy import pcl

def test_data(*args):
    return os.path.join("test_data", *args)

def make_pt(x, y, z):
    pt = pcl.point_types.PointXYZRGBA()
    pt.x = x
    pt.y = y
    pt.z = z
    return pt

def test_min_cut_segmentation():
     pc = pclpy.io.read_las(test_data("E:/Lidar-practice/new-files/las14_type7_ALS_RIEGL_Q680i.las"))
     seg = pcl.segmentation.RegionGrowing.PointXYZRGBA()
     print(dir(seg))
     seg.setInputCloud(pc)

     foreground = pcl.PointCloud.PointXYZRGBA()
     foreground.push_back(make_pt(5.06, 8.03, 22.16))
     seg.setForegroundPoints(foreground)

     background = pcl.PointCloud.PointXYZRGBA()
     background.push_back(make_pt(4.848, 8.426, 21.636))
     background.push_back(make_pt(5.413, 7.513, 21.710))
     seg.setBackgroundPoints(background)

     clouds = []
     for n, neighbors in enumerate([10, 15, 25]):
         seg.setSigma(0.25)
         seg.setRadius(1.5)
         seg.setNumberOfNeighbours(neighbors)
         seg.setSourceWeight(0.8)

         clusters = pcl.vector.PointIndices()
         seg.extract(clusters)
         seg.getColoredCloud()
         cloud = seg.getColoredCloud()
         clouds.append(cloud)
         pclpy.io.to_las(cloud, test_data("E:/Lidar-practice/new-files/yoooo.las" % n))

     pclpy.view.vtk.view_multiple(clouds)

It doesn't throw any error. It doesn't even generate an output.

davidcaron commented 6 years ago

This code was actually me playing with the min cut segmentation. It was commented out, and I just removed it.

I suggest reading about the functions you're trying to use first... You're copying and pasting code and it seems you didn't think about what's actually going on. (For example you kept some point coordinates which I'm sure are outside of your cloud's bounding box).

niranjanreddy891 commented 6 years ago

Still the segmentation code is not working. Do I need to modify anything in the code. :)

import math
import os
import numpy as np
import pytest

import pclpy
from pclpy import pcl

def test_data(*args):
    return os.path.join("test_data", *args)

def make_pt(x, y, z):
    pt = pcl.point_types.PointXYZRGBA()
    pt.x = x
    pt.y = y
    pt.z = z
    return pt

def test_region_growing():
    pc = pclpy.io.read(test_data("E:/Lidar-practice/new-files/las14_type7_ALS_RIEGL_Q680i.las"), "PointXYZRGBA")
    rg = pcl.segmentation.RegionGrowing.PointXYZRGBA_Normal()
    rg.setInputCloud(pc)
    normals_estimation = pcl.features.NormalEstimationOMP.PointXYZRGBA_Normal()
    normals_estimation.setInputCloud(pc)
    normals = pcl.PointCloud.Normal()
    normals_estimation.setRadiusSearch(0.35)
    normals_estimation.compute(normals)
    rg.setInputNormals(normals)

    rg.setMaxClusterSize(1000000)
    rg.setMinClusterSize(10)
    rg.setNumberOfNeighbours(15)
    rg.setSmoothnessThreshold(5 / 180 * math.pi)
    rg.setCurvatureThreshold(5)
    rg.setResidualThreshold(1)
    clusters = pcl.vectors.PointIndices()
    rg.extract(clusters)
    assert max([len(c.indices) for c in clusters]) == 2449  # ground
davidcaron commented 6 years ago

Are you running this code exactly like you pasted it? Because the function won't be executed.

Also, you're keeping the exact same parameters from the tests again. Did you check if they make sense with your cloud?

niranjanreddy891 commented 6 years ago

But why the function can't be executed? I am little bit confused. :(

davidcaron commented 6 years ago

Add test_region_growing() at the end of the script. This is python 101. I'm sorry but I can't find the time to help on everything. You will have to show that you tried something on your own.

niranjanreddy891 commented 6 years ago

@davidcaron, any update on segmentation?