Problems with detecting walls in a pointcloud.

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with detecting walls in a pointcloud.

DungeonMaster
Hello,

I'm a pretty new user of PCL and I have some problems detecting walls in
given pointcloud.

The idea is to detect 2 planes with RANSAC that wold be perpendicular to XY
plane with some small deviation. I decide to use
pcl::SACMODEL_PERPENDICULAR_PLANE. But in segmentation parameters I can only
set axises and in result I got some inclined planes or even no results. Are
there any ways to strictly set a plane in segmentation parameters, or maybe
you have any other suggestions to this kind of task.

Here is my code:

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/console/parse.h>
#include <pcl/common/common_headers.h>
#include <pcl/common/angles.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>

//main
int
main(int argc, char** argv)
{
        //Fetch point cloud filename in arguments | Works with PCD files
        std::vector<int> filenames;
        filenames = pcl::console::parse_file_extension_argument (argc, argv,
".pcd");

        //Load file
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_1 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_2 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_1);
        pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_2);

        //Segmentation parameters
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr walls (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
        pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
        pcl::SACSegmentation<pcl::PointXYZRGB> seg;
        seg.setModelType (pcl::SACMODEL_PERPENDICULAR_PLANE);
        seg.setMethodType (pcl::SAC_RANSAC);
        seg.setOptimizeCoefficients (true);
        seg.setDistanceThreshold (1.0);
        seg.setAxis(Eigen::Vector3f(1,0,0));
        seg.setAxis(Eigen::Vector3f(0,1,0));
        seg.setEpsAngle (pcl::deg2rad (5.));
        pcl::ExtractIndices<pcl::PointXYZRGB> extract;
        int i=0;

        //Segmentation cycle for 2 walls
        while (i<2)
        {
                //Segment the wall
                seg.setInputCloud (source_cloud_2);
                seg.segment (*inliers, *coefficients);

                //Extraction
                extract.setInputCloud (source_cloud_2);
                extract.setIndices (inliers);
                extract.setNegative (false);
                extract.filter (*walls);

                //Create new filtering object
                extract.setNegative (true);
                extract.filter (*source_cloud_2);

                i++;
        }

        //Visualization
        pcl::visualization::PCLVisualizer viewer ("2_wall_segmentation");

        int v1(0);
        viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
        viewer.setBackgroundColor (0, 0, 0, v1);
        viewer.addText("Original", 10, 10, "v1 text", v1);
        viewer.addCoordinateSystem (1.0, v1);
        pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
rgb1(source_cloud_1);
        viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_1, rgb1, "sample
cloud1", v1);

        int v2(0);
        viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
        viewer.setBackgroundColor (0, 0, 0, v2);
        viewer.addText("Walls", 10, 10, "v2 text", v2);
        viewer.addCoordinateSystem (1.0, v2);
        pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
rgb2(source_cloud_2);
        viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_2, rgb2, "sample
cloud2", v2);
        pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB>
color1(walls, 0, 255, 0);
        viewer.addPointCloud<pcl::PointXYZRGB> (walls, color1, "sample cloud3",
v2);

        //Display the visualiser until 'q' key is pressed
        while (!viewer.wasStopped ())
        {
                viewer.spinOnce ();
        }

        return 0;
}

And the file that I use:

My file <https://drive.google.com/open?id=0B3Ly06lvT5-iUTN2Zk9UQUlnMEE>  

Sorry for my English and thank you for help.




--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Problems with detecting walls in a pointcloud.

ROZAR Fabien
Hello,

I am working on another method tahn RANSAC of segmentation for
plane fitting and I was curious about your point cloud. So I download
it and run blindy my program on it to see the results (see attached
images). The different colors on the images indicate different planes,
nothing more.

Questions:
Your point cloud is a scan of what kind of object please?
Can you show me on the attached images what are the planes you
are interested in please?

When I look at the point cloud without plane fitting, it seems difficult
to see any plane... The surfaces of your point cloud seems to be really
curved.

frozar, who tries to help

Le 26/10/2017 à 14:41, DungeonMaster a écrit :

> Hello,
>
> I'm a pretty new user of PCL and I have some problems detecting walls in
> given pointcloud.
>
> The idea is to detect 2 planes with RANSAC that wold be perpendicular to XY
> plane with some small deviation. I decide to use
> pcl::SACMODEL_PERPENDICULAR_PLANE. But in segmentation parameters I can only
> set axises and in result I got some inclined planes or even no results. Are
> there any ways to strictly set a plane in segmentation parameters, or maybe
> you have any other suggestions to this kind of task.
>
> Here is my code:
>
> #include <iostream>
> #include <pcl/io/pcd_io.h>
> #include <pcl/console/parse.h>
> #include <pcl/common/common_headers.h>
> #include <pcl/common/angles.h>
> #include <pcl/ModelCoefficients.h>
> #include <pcl/sample_consensus/method_types.h>
> #include <pcl/sample_consensus/model_types.h>
> #include <pcl/segmentation/sac_segmentation.h>
> #include <pcl/filters/extract_indices.h>
> #include <pcl/visualization/pcl_visualizer.h>
> #include <pcl/visualization/point_cloud_color_handlers.h>
>
> //main
> int
> main(int argc, char** argv)
> {
> //Fetch point cloud filename in arguments | Works with PCD files
> std::vector<int> filenames;
> filenames = pcl::console::parse_file_extension_argument (argc, argv,
> ".pcd");
>
> //Load file
> pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_1 (new
> pcl::PointCloud<pcl::PointXYZRGB> ());
> pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_2 (new
> pcl::PointCloud<pcl::PointXYZRGB> ());
> pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_1);
> pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_2);
>
> //Segmentation parameters
> pcl::PointCloud<pcl::PointXYZRGB>::Ptr walls (new
> pcl::PointCloud<pcl::PointXYZRGB> ());
> pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
> pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
> pcl::SACSegmentation<pcl::PointXYZRGB> seg;
> seg.setModelType (pcl::SACMODEL_PERPENDICULAR_PLANE);
> seg.setMethodType (pcl::SAC_RANSAC);
> seg.setOptimizeCoefficients (true);
> seg.setDistanceThreshold (1.0);
> seg.setAxis(Eigen::Vector3f(1,0,0));
> seg.setAxis(Eigen::Vector3f(0,1,0));
> seg.setEpsAngle (pcl::deg2rad (5.));
> pcl::ExtractIndices<pcl::PointXYZRGB> extract;
> int i=0;
>
> //Segmentation cycle for 2 walls
> while (i<2)
> {
> //Segment the wall
> seg.setInputCloud (source_cloud_2);
> seg.segment (*inliers, *coefficients);
>
> //Extraction
> extract.setInputCloud (source_cloud_2);
> extract.setIndices (inliers);
> extract.setNegative (false);
> extract.filter (*walls);
>
> //Create new filtering object
> extract.setNegative (true);
> extract.filter (*source_cloud_2);
>
> i++;
> }
>
> //Visualization
> pcl::visualization::PCLVisualizer viewer ("2_wall_segmentation");
>
> int v1(0);
> viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
> viewer.setBackgroundColor (0, 0, 0, v1);
> viewer.addText("Original", 10, 10, "v1 text", v1);
> viewer.addCoordinateSystem (1.0, v1);
> pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
> rgb1(source_cloud_1);
> viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_1, rgb1, "sample
> cloud1", v1);
>
> int v2(0);
> viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
> viewer.setBackgroundColor (0, 0, 0, v2);
> viewer.addText("Walls", 10, 10, "v2 text", v2);
> viewer.addCoordinateSystem (1.0, v2);
> pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
> rgb2(source_cloud_2);
> viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_2, rgb2, "sample
> cloud2", v2);
> pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB>
> color1(walls, 0, 255, 0);
> viewer.addPointCloud<pcl::PointXYZRGB> (walls, color1, "sample cloud3",
> v2);
>
> //Display the visualiser until 'q' key is pressed
> while (!viewer.wasStopped ())
> {
> viewer.spinOnce ();
> }
>
> return 0;
> }
>
> And the file that I use:
>
> My file <https://drive.google.com/open?id=0B3Ly06lvT5-iUTN2Zk9UQUlnMEE>
>
> Sorry for my English and thank you for help.
>
>
>
>
> --
> Sent from: http://www.pcl-users.org/
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

Capture du 2017-10-26 14-58-18.png (231K) Download Attachment
Capture du 2017-10-26 14-58-25.png (206K) Download Attachment
Capture du 2017-10-26 14-58-38.png (245K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problems with detecting walls in a pointcloud.

DungeonMaster
This pointcloud was formed by stereocameras mounted on robot. This is a scan
of a corridor. My cloud is only a little part of it. It also was filtered by
statistical_outlier_removal algorithm and downsampled by voxelgrid_filter.

It is full of noise and a person who gave it to me said that it was because
of camers settings. He will provide me better one latter but now I only have
this one.

I am interested in 2 corridor walls. I can send a picture that i get from
raw RANSAC plane method that satisfies my criteria to show in what planes
I'm interested in. But this method could work only after I manually remove
all noise and I need more robust method.

<http://www.pcl-users.org/file/t499071/Selection_028.bmp>

<http://www.pcl-users.org/file/t499071/Selection_029.bmp>

<http://www.pcl-users.org/file/t499071/Selection_030.bmp>

Thank you for your reply.



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Problems with detecting walls in a pointcloud.

ROZAR Fabien
Ok, I see the plane which interest you. My method of plane segmentation
is based on this article :
https://www.sciencedirect.com/user/chooseorg?targetURL=%2Fscience%2Farticle%2Fpii%2FS0924271615000283

It's a method based on an octree representation of the point cloud and I
find it really more robust than the RANSAC algorithm.

Unfortunately, it is not available in my personnal fork of PCL right
now, so
I cannot provide it easily. But in case you are insterested, I let you
know when
it will be available in my repository (it will necessitate a lot of time
before
it will be integrated in the official repository).

Best regards,
frozar

Le 26/10/2017 à 16:25, DungeonMaster a écrit :

> This pointcloud was formed by stereocameras mounted on robot. This is a scan
> of a corridor. My cloud is only a little part of it. It also was filtered by
> statistical_outlier_removal algorithm and downsampled by voxelgrid_filter.
>
> It is full of noise and a person who gave it to me said that it was because
> of camers settings. He will provide me better one latter but now I only have
> this one.
>
> I am interested in 2 corridor walls. I can send a picture that i get from
> raw RANSAC plane method that satisfies my criteria to show in what planes
> I'm interested in. But this method could work only after I manually remove
> all noise and I need more robust method.
>
> <http://www.pcl-users.org/file/t499071/Selection_028.bmp>
>
> <http://www.pcl-users.org/file/t499071/Selection_029.bmp>
>
> <http://www.pcl-users.org/file/t499071/Selection_030.bmp>
>
> Thank you for your reply.
>
>
>
> --
> Sent from: http://www.pcl-users.org/
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Problems with detecting walls in a pointcloud.

DungeonMaster
Thank you. I request full text of this article and waiting for it.

I realy interested in your method and realy hope you let me know when it
will be available at your repository.

You can reach me on this address: [hidden email]

Also I wanna ask you to send me some examples of your code which you used to
segment planes in my cloud if it's not a problem for you. I ask this because
i'm not good at programming and usually need some examples to make something
work.

Thanks.

Anyone have some other advices how else I can set RANSAC parameters to get
perpendicular to floor planes?


ROZAR Fabien wrote

> Ok, I see the plane which interest you. My method of plane segmentation
> is based on this article :
> https://www.sciencedirect.com/user/chooseorg?targetURL=%2Fscience%2Farticle%2Fpii%2FS0924271615000283
>
> It's a method based on an octree representation of the point cloud and I
> find it really more robust than the RANSAC algorithm.
>
> Unfortunately, it is not available in my personnal fork of PCL right
> now, so
> I cannot provide it easily. But in case you are insterested, I let you
> know when
> it will be available in my repository (it will necessitate a lot of time
> before
> it will be integrated in the official repository).
>
> Best regards,
> frozar
>
> Le 26/10/2017 à 16:25, DungeonMaster a écrit :
>> This pointcloud was formed by stereocameras mounted on robot. This is a
>> scan
>> of a corridor. My cloud is only a little part of it. It also was filtered
>> by
>> statistical_outlier_removal algorithm and downsampled by
>> voxelgrid_filter.
>>
>> It is full of noise and a person who gave it to me said that it was
>> because
>> of camers settings. He will provide me better one latter but now I only
>> have
>> this one.
>>
>> I am interested in 2 corridor walls. I can send a picture that i get from
>> raw RANSAC plane method that satisfies my criteria to show in what planes
>> I'm interested in. But this method could work only after I manually
>> remove
>> all noise and I need more robust method.
>>
>> &lt;http://www.pcl-users.org/file/t499071/Selection_028.bmp&gt;
>>
>> &lt;http://www.pcl-users.org/file/t499071/Selection_029.bmp&gt;
>>
>> &lt;http://www.pcl-users.org/file/t499071/Selection_030.bmp&gt;
>>
>> Thank you for your reply.
>>
>>
>>
>> --
>> Sent from: http://www.pcl-users.org/
>> _______________________________________________
>>

> PCL-users@

>  / http://pointclouds.org
>> http://pointclouds.org/mailman/listinfo/pcl-users
>
> _______________________________________________

> PCL-users@

>  / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users





--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Problems with detecting walls in a pointcloud.

DungeonMaster
In reply to this post by DungeonMaster
Hi there again. Just wanna post how I solved my problem before Rozar's new
method is ready. Key point for my pointcloud was number of iterations. By
default maximum number of them are 50 and for cloud such as mine that was
not just enough to find correct solutions for my request. After I manually
increase this number up to 500 the program detect 2 walls just as I want to.

Here is now working version of my code if someone would need an example (I
need them realy hard).

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/console/parse.h>
#include <pcl/common/common_headers.h>
#include <pcl/common/angles.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>

//main
int
main(int argc, char** argv)
{
        //Fetch point cloud filename in arguments | Works with PCD files
        std::vector<int> filenames;
        filenames = pcl::console::parse_file_extension_argument (argc, argv,
".pcd");

        //Load file
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_1 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud_2 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_1);
        pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud_2);

        //Segmentation parameters
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr wall_0 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr wall_1 (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
        pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
        pcl::SACSegmentation<pcl::PointXYZRGB> seg;
        seg.setModelType (pcl::SACMODEL_PERPENDICULAR_PLANE);
        seg.setMethodType (pcl::SAC_RANSAC);
        seg.setOptimizeCoefficients (true);
        seg.setMaxIterations(500);
        seg.setDistanceThreshold (1.0);
        seg.setAxis(Eigen::Vector3f(1,0,0));
        seg.setAxis(Eigen::Vector3f(0,1,0));
        seg.setEpsAngle (pcl::deg2rad (5.));
        pcl::ExtractIndices<pcl::PointXYZRGB> extract;
        int i=0;

        //Segmentation cycle for 2 walls
        while (i<2)
        {
                //Segment the wall
                seg.setInputCloud (source_cloud_2);
                seg.segment (*inliers, *coefficients);

                //Extraction
                extract.setInputCloud (source_cloud_2);
                extract.setIndices (inliers);
                extract.setNegative (false);
                extract.filter (*wall_0);

                //Create new filtering object
                extract.setNegative (true);
                extract.filter (*source_cloud_2);

                wall_0.swap (wall_1);
                i++;
        }

        //Visualization
        pcl::visualization::PCLVisualizer viewer ("2_wall_segmentation");

        int v1(0);
        viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
        viewer.setBackgroundColor (0, 0, 0, v1);
        viewer.addText("Original", 10, 10, "v1 text", v1);
        //viewer.addCoordinateSystem (1.0, v1);
        pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
rgb1(source_cloud_1);
        viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_1, rgb1, "sample
cloud1", v1);

        int v2(0);
        viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
        viewer.setBackgroundColor (0, 0, 0, v2);
        viewer.addText("Walls", 10, 10, "v2 text", v2);
        //viewer.addCoordinateSystem (1.0, v2);
        pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
rgb2(source_cloud_2);
        viewer.addPointCloud<pcl::PointXYZRGB> (source_cloud_2, rgb2, "sample
cloud2", v2);
        pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB>
color1(wall_0, 0, 255, 0);
        viewer.addPointCloud<pcl::PointXYZRGB> (wall_0, color1, "sample cloud3",
v2);
        pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB>
color2(wall_1, 0, 255, 0);
        viewer.addPointCloud<pcl::PointXYZRGB> (wall_1, color2, "sample cloud4",
v2);

        //Display the visualiser until 'q' key is pressed
        while (!viewer.wasStopped ())
        {
                viewer.spinOnce ();
        }

        return 0;
}





--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users