pcl::Normal, what is the correct way to access data after computing normal

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

pcl::Normal, what is the correct way to access data after computing normal

hasnat
Hi All,

I am having problem in conversion of point normal (pcl::Normal) to 32 bit floating point value (of OpenCV CV_32F). After computing the normal ( ... ne.compute(*normals); ) I tried to access the data using several ways as follows:

normals->at(i).normal_x
normals->at(i).p.normal[0]
normals->points[i].normal[0]

All these different data accessing provide me same value. However, when I use these values further for other task I get error. Can anyone please tell me what should I do in order to make proper conversion. Here is an example:

==============================================================

// Compute normal
pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne;
ne.setInputCloud(cloud);

pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new pcl::search::KdTree< pcl::PointXYZRGB>()); ne.setSearchMethod(tree);

ne.setRadiusSearch(0.03);
ne.compute(*normals);


//// Store the values
Mat samples(normals->size(), 4, CV_32FC1 );
int sC = 0;
for (int i = 0; i < normals->size(); i++) {
    samples.at<float> (sC, 6) = normals->at(i).normal[0];
    samples.at<float> (sC, 7) = normals->at(i).normal[1];
    samples.at<float> (sC, 8) = normals->at(i).normal[2];
    samples.at<float> (sC, 9) = normals->at(i).curvature;
    sC++;
}
Reply | Threaded
Open this post in threaded view
|

Re: pcl::Normal, what is the correct way to access data after computing normal

Radu B Rusu
Administrator
On 06/10/2012 07:55 AM, hasnat wrote:

> Hi All,
>
> I am having problem in conversion of point normal (pcl::Normal) to 32 bit
> floating point value (of OpenCV CV_32F). After computing the normal ( ...
> ne.compute(*normals); ) I tried to access the data using several ways as
> follows:
>
> normals->at(i).normal_x
> normals->at(i).p.normal[0]
> normals->points[i].normal[0]
>
> All these different data accessing provide me same value. However, when I
> use these values further for other task I get error. Can anyone please tell
> me what should I do in order to make proper conversion. Here is an example:

I'm not sure what you mean by "I get error". Please be more specific.

Cheers,
Radu.

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

Re: pcl::Normal, what is the correct way to access data after computing normal

hasnat
Hi Radu,

In my previous example, I wanted to use the values stored in the opencv matrix (Mat samples(normals->size(), 4, CV_32FC1 ); that is filled with the values of normals) as training samples. I use opencv expectation maximization (CvEM) algorithm to train a mixture model.

I got error message (segmentation fault or memory allocate problem) from the CvEM training algorithm when I use the normal values that I accessed as:

samples.at<float> (i, 0) = normals->at(i).normal[0]
...

I believe that there is problem in the assignment statement.
Reply | Threaded
Open this post in threaded view
|

Re: pcl::Normal, what is the correct way to access data after computing normal

Radu B Rusu
Administrator
Your samples Mat is defined as Nx4, but you're trying to access its Nx{6,7,8,9} indices. That might be what's causing
the errors.

You can always just copy the normal data into some good old float numbers and print them out. If that works, the errors
are somewhere else.

Cheers,
Radu.

On 06/10/2012 10:49 AM, hasnat wrote:

> Hi Radu,
>
> In my previous example, I wanted to use the values stored in the opencv
> matrix (Mat samples(normals->size(), 4, CV_32FC1 ); that is filled with the
> values of normals) as training samples. I use opencv expectation
> maximization (CvEM) algorithm to train a mixture model.
>
> I got error message (segmentation fault or memory allocate problem) from the
> CvEM training algorithm when I use the normal values that I accessed as:
>
> samples.at<float>  (i, 0) = normals->at(i).normal[0]
> ...
>
> I believe that there is problem in the assignment statement.
>
>
> --
> View this message in context: http://www.pcl-users.org/pcl-Normal-what-is-the-correct-way-to-access-data-after-computing-normal-tp4019187p4019191.html
> Sent from the Point Cloud Library (PCL) Users mailing list archive at Nabble.com.
> _______________________________________________
> [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: pcl::Normal, what is the correct way to access data after computing normal

hasnat
Hi Radu,

I am very much sorry for the typing error in the post. Actually I accessed it correctly in my program (means access its Nx{0,1,2,3}).

In order to clarify the conversion issue, I did another thing. I copied the normal values to a text file. And then reading those values from the file. It worked perfectly.

I saw in the pcl documentation and found that the normal_x, normal_y, normal_z are declared as float. However, for some reason this direct assignment is not working for me. Therefore, I was thinking whether there is any alternative syntax to access the normal values.

Thank you very much for your response.
Reply | Threaded
Open this post in threaded view
|

Re: pcl::Normal, what is the correct way to access data after computing normal

hasnat
I would like to write an update about the issue that I raised in this post. I got the particular problem when I tested the piece of code in Ubuntu and compiled with Eclipse CDT. Later I test the same code in windows and compiled with VS 2010. Surprisingly there is no error in windows!!!
Reply | Threaded
Open this post in threaded view
|

Re: pcl::Normal, what is the correct way to access data after computing normal

Radu B Rusu
Administrator
That might be an unrelated problem caused by something else. Can you provide a minimal code example only using PCL that
can replicate the behavior?

Cheers,
Radu.

On 06/13/2012 09:16 AM, hasnat wrote:

> I would like to write an update about the issue that I raised in this post. I
> got the particular problem when I tested the piece of code in Ubuntu and
> compiled with Eclipse CDT. Later I test the same code in windows and
> compiled with VS 2010. Surprisingly there is no error in windows!!!
>
> --
> View this message in context: http://www.pcl-users.org/pcl-Normal-what-is-the-correct-way-to-access-data-after-computing-normal-tp4019187p4019288.html
> Sent from the Point Cloud Library (PCL) Users mailing list archive at Nabble.com.
> _______________________________________________
> [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: pcl::Normal, what is the correct way to access data after computing normal

hasnat
I think at this moment I can not provide any such example where 'only using pcl' I can replicate such behavior. I have tried basic arithmetic operations with those information provided by pcl::Normal and so far no problem. Problem only appears when I try to integrate this data with the cvEM train of OpenCV library.
Reply | Threaded
Open this post in threaded view
|

Re: pcl::Normal, what is the correct way to access data after computing normal

Radu B Rusu
Administrator
The bug might be in OpenCV then. We'd be happy to work with you to identify that and solve it.

Cheers,
Radu.

On 06/13/2012 01:51 PM, hasnat wrote:

> I think at this moment I can not provide any such example where 'only using
> pcl' I can replicate such behavior. I have tried basic arithmetic operations
> with those information provided by pcl::Normal and so far no problem.
> Problem only appears when I try to integrate this data with the cvEM train
> of OpenCV library.
>
> --
> View this message in context: http://www.pcl-users.org/pcl-Normal-what-is-the-correct-way-to-access-data-after-computing-normal-tp4019187p4019303.html
> Sent from the Point Cloud Library (PCL) Users mailing list archive at Nabble.com.
> _______________________________________________
> [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: pcl::Normal, what is the correct way to access data after computing normal

hasnat
Thank you for your encouragement to probe it further. I will look at this problem once again and try to find out the exact reason.