NormalEstimation with GPU then Add to Viewer

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

NormalEstimation with GPU then Add to Viewer

zen
Hi All,

I am trying to compute the normal of a point cloud then it using
pcl::visualization. I have done the same using cpu to compute the normal but
I would like to reduce speed by utilising my gpu.

My problem is how do I add gpu::NormalEstimation::Normals to my
pcl::visualization?

    gpu::NormalEstimation::PointCloud cloud;    
    cloud.upload(source.cloud->points);

    // convert to single array format
    vector<int> neighbors_all(source.max_nn_size * cloud.size());
    PtrStep<int> ps(&neighbors_all[0], source.max_nn_size *
PtrStep<int>::elem_size);    
    for(size_t i = 0; i < cloud.size(); ++i)
        copy(source.neighbors_all[i].begin(), source.neighbors_all[i].end(),
ps.ptr(i));

    NeighborIndices indices;
    indices.upload(neighbors_all, source.sizes, source.max_nn_size);

    gpu::NormalEstimation::Normals normals;
    gpu::NormalEstimation::computeNormals(cloud, indices, normals);
    gpu::NormalEstimation::flipNormalTowardsViewpoint(cloud, 0.f, 0.f, 0.f,
normals);

Thanks in advance.



--
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: NormalEstimation with GPU then Add to Viewer

Sérgio Agostinho

Looking at the source code the Normals are inherently a pcl::gpu::DeviceArray<PointXYZ> type and they live in GPU memory space. You're likely required to use the `download` method to get things to CPU memory and populate a "common" normals point cloud.

Disclaimer: I have zero experience with these PCL modules.

Cheers



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

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NormalEstimation with GPU then Add to Viewer

peter9606
In reply to this post by zen
Hi, Zen

I'm not sure if this could help you out or not, but I tried it couple weeks
ago, and it worked for me. Here's the sample code from PCL/cuda module.
https://github.com/PointCloudLibrary/pcl/blob/master/cuda/apps/src/kinect_normals_cuda.cpp

Cheers,
Peter Han



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

Re: NormalEstimation with GPU then Add to Viewer

zen
In reply to this post by Sérgio Agostinho
Hi Sergio,

I am actually scrapping some code from the test folder of pcl on github, and
in  test_normals
<https://github.com/PointCloudLibrary/pcl/blob/master/gpu/features/test/test_normals.cpp>
.cpp, vector<PointXYZ> was used as a container to download the computed
normal. My question would be how can I convert the vector to a suitable
object such as PointCloud<Normal> so that I can use
pcl::visualiser::addPointCloudNormals to view it.

Thanks in advance!



--
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: NormalEstimation with GPU then Add to Viewer

Sérgio Agostinho
For two individuals points, this operation would work. Extend it to all elements of the vector.

PointXYZ p;
Normal n;

n.getNormalVector3fMap () = p.getVector3fMap ();

Cheers


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

signature.asc (836 bytes) Download Attachment
zen
Reply | Threaded
Open this post in threaded view
|

Re: NormalEstimation with GPU then Add to Viewer

zen
In reply to this post by peter9606
Hi Peter,

I shall have a look into it later in the week. Thanks.



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

Re: NormalEstimation with GPU then Add to Viewer

zen
In reply to this post by Sérgio Agostinho
Hi Sergio,

Thanks for your reply.  I cant seems to find function definitiona for
getNormalVector3fMap and getVector3fMap on PCL documentation. I am sure I
might have miss it somewhere. Happy to have a read if you know where the
functions aew declared.

I think I get the idea of the operation and please let me know if its not.
So with
n.getNormalVector3fMap () = p.getVector3fMap (), we are basically copying
all the information from p to n.
But I am slightly confused at the syntax as they are both getter.





--
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: NormalEstimation with GPU then Add to Viewer

Sérgio Agostinho



On 30-01-2018 00:00, zen wrote:
Hi Sergio,

Thanks for your reply.  I cant seems to find function definitiona for
getNormalVector3fMap and getVector3fMap on PCL documentation. I am sure I
might have miss it somewhere. Happy to have a read if you know where the
functions aew declared.

Unfortunately this is stuff you only discover once you start crawling through PCL source code.
https://github.com/PointCloudLibrary/pcl/blob/master/common/include/pcl/impl/point_types.hpp#L157-L245
I think I get the idea of the operation and please let me know if its not.
So with 
n.getNormalVector3fMap () = p.getVector3fMap (), we are basically copying
all the information from p to n.
But I am slightly confused at the syntax as they are both getter.

Close but not exactly (if we're being really strict). You're gonna dig to the intricacies of how a PointXYZ  and Normals are constructed. They're not exactly getters. Each wraps an Eigen::Map around 'data_n' and 'data' respectively.

No easy explanations at this point. You'll need to spend some time learning the memory layout of the types you're interested in :')

Cheers




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

signature.asc (836 bytes) Download Attachment
zen
Reply | Threaded
Open this post in threaded view
|

Re: NormalEstimation with GPU then Add to Viewer

zen
Hi Sergio,

Thanks for all the advice so far. Really appreciate it! I have managed to
get GPU normal estimation working using knn based search and managed to
visualise the normal with no issues.

And of course, another obstacle is waiting for me. I would like to use a
radius based search instead of knn. At the snippet below, I substituted  
kdtree->nearestKSearch(cloud->points[i], kNeighbour, neighbors_all[i],
dists); with
kdtree->radiusSearch(cloud->points[i], kNeighbour, neighbors_all[i], dists);

And, I am literally running out of CPU ram memory while creating my
neighbour indices. Am I missing something here? Using the non-gpu normal
estimation, I managed to use radius based search to compute the normal and
follow by correspondence grouping. So basically, I am trying to port the gpu
normal estimation to the local descriptor pipeline. Should I have
constructed my neighbour indices differently when using the radius search
based method?

Thanks for your help in advance. I have attached my compilable code using
cmake in case if anyone would like to have a look. I have tested the code in
both linux and window, and my program would crush due to out of CPU ram
memory.

gpuNormalEst.cpp <http://www.pcl-users.org/file/t499206/gpuNormalEst.cpp>  
CMakeLists.txt <http://www.pcl-users.org/file/t499206/CMakeLists.txt>  
wall.pcd <http://www.pcl-users.org/file/t499206/wall.pcd>  




--
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: NormalEstimation with GPU then Add to Viewer

Sérgio Agostinho
I had a look at your code, specifically the "createNeighboursIndices"
function.

Your point cloud is roughly 200k points of XYZ nature so 32B per point
which means roughly 6MB.

The first thing you need to try so reduce the radius size. In the worst
case scenario (all points are considered neighbors) this can yield a
construction of a 200k x 200k vector of vector of ints (4 bytes), which
results in 149GB of memory required...

Cheers



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

signature.asc (836 bytes) Download Attachment