saving data

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

saving data

mystpuni
hello people, I'm trying to save the point cloud data, i've tried this:


#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/common/time.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/pcd_io.h>


static int num_s, num_f; 

class SimpleKinectViewer 
{ 
public: 
 SimpleKinectViewer() :   viewer("cloud_viwer") { } 


void cloud_cb_(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud){ 

    boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> > pointer(cloud); 
    if (!viewer.wasStopped()) 
    viewer.showCloud(pointer); 
} 


void save_cloud (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud) { 
     std::stringstream s; 
     s << "save_file" << num_s++ << ".pcd"; // 
     pcl::io::savePCDFileBinary(s.str(), *cloud); 
      
} 

void run() { 
     num_s=0; 
    
     pcl::Grabber* interface = new pcl::OpenNIGrabber(); 

     boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> 
          f = boost::bind(&SimpleKinectViewer::cloud_cb_, this, _1); 
     boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> 
          g = boost::bind (&SimpleKinectViewer::save_cloud, this, _1); 
      

     boost::signals2::connection c = interface->registerCallback (f); 
     boost::signals2::connection d = interface->registerCallback (g); 
    
     interface->start(); 

     while (!viewer.wasStopped()) 
          { 
            Sleep(1); 
          } 

     interface->stop(); 

} 

pcl::visualization::CloudViewer viewer; 

}; 

int main(int argc, char **argv){ 
     SimpleKinectViewer v; 
     v.run(); 

    return 0; 
} 

and it returns 1file at sec and they have all the same dimension 4801 kb, is it normal?? how can i check if they're correct??

cause i've tried also this function pcl::io::savePCDFileASCII ("test.pcd", cloud); and it returns a test.pcd file, and if i open there are many many many nan datas, then some good data and again nan etc...

like this: # .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z rgba
SIZE 4 4 4 4
TYPE F F F U
COUNT 1 1 1 1
WIDTH 640
HEIGHT 480
VIEWPOINT 0 0 0 1 0 0 0
POINTS 307200
DATA ascii
nan nan nan 6840665
nan nan nan 6841177
nan nan nan 6973030
....

-1.8208458 -1.40012 3.6210003 7368550
-1.7949125 -1.3854268 3.5830002 7371110
-1.7880876 -1.3854268 3.5830002 7304550
-1.8001543 -1.40012 3.6210003 7238501
-1.7932572 -1.40012 3.6210003 7500900
-1.78636 -1.40012 3.6210003 7763556
...
etc etc

my project goal is to have both file with points coordinates, then a 3d data point cloud image if it is possible. any helps? thank you!
Reply | Threaded
Open this post in threaded view
|

Re: saving data

zaza1851983
It is normal that a point cloud contains nans, especially on the edges.
The header and the data look fine

On 06/21/2012 11:40 AM, mystpuni wrote:

> hello people, I'm trying to save the point cloud data, i've tried this:
>
>
>
>
> and it returns 1file at sec and they have all the same dimension 4801 kb, is
> it normal?? how can i check if they're correct??
>
> cause i've tried also this function pcl::io::savePCDFileASCII ("test.pcd",
> cloud); and it returns a test.pcd file, and if i open there are many many
> many nan datas, then some good data and again nan etc...
>
> like this: # .PCD v0.7 - Point Cloud Data file format
> VERSION 0.7
> FIELDS x y z rgba
> SIZE 4 4 4 4
> TYPE F F F U
> COUNT 1 1 1 1
> WIDTH 640
> HEIGHT 480
> VIEWPOINT 0 0 0 1 0 0 0
> POINTS 307200
> DATA ascii
> nan nan nan 6840665
> nan nan nan 6841177
> nan nan nan 6973030
> ....
>
> -1.8208458 -1.40012 3.6210003 7368550
> -1.7949125 -1.3854268 3.5830002 7371110
> -1.7880876 -1.3854268 3.5830002 7304550
> -1.8001543 -1.40012 3.6210003 7238501
> -1.7932572 -1.40012 3.6210003 7500900
> -1.78636 -1.40012 3.6210003 7763556
> ...
> etc etc
>
> my project goal is to have both file with points coordinates, then a 3d data
> point cloud image if it is possible. any helps? thank you!
>
> --
> View this message in context: http://www.pcl-users.org/saving-data-tp4019514.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: saving data

mystpuni
oh that's perfect, thank you!!
is there a way to read that test file and show you the point cloud saved??
for example I've tried this tutorial http://www.pointclouds.org/documentation/tutorials/reading_pcd.php#reading-pcd (ok it's just to read not to show the point cloud) but it crashes and doesn't work...
Reply | Threaded
Open this post in threaded view
|

Re: saving data

Radu B Rusu
Administrator
If the read PCD tutorial crashes, then your PCD file is corrupted. Please upload your file somewhere and we can help you.

Cheers,
Radu.

On 06/22/2012 12:19 AM, mystpuni wrote:

> oh that's perfect, thank you!!
> is there a way to read that test file and show you the point cloud saved??
> for example I've tried this tutorial
> http://www.pointclouds.org/documentation/tutorials/reading_pcd.php#reading-pcd
> (ok it's just to read not to show the point cloud) but it crashes and
> doesn't work...
>
>
> --
> View this message in context: http://www.pcl-users.org/saving-data-tp4019514p4019546.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: saving data

mystpuni
Reply | Threaded
Open this post in threaded view
|

Re: saving data

Radu B Rusu
Administrator
As I guessed, your file is incomplete. The application that you used to capture/save it terminated before the file was
flushed to disk. Did you press Cltr+C / kill the app?

The number of lines in the file is 65943.
The number of points in the file is 65943-11=65932.
The number of points advertised in the header is: 640 * 480 = 307200

What's worse is that your file ends in:
65944 nan n

So incomplete data.

We can add a few more robustness checks in the PCD file reader (and thus complicate the code :) ), but in general, you
need to make sure that you're passing a valid PCD file to the reader, so always check for 'consistency' before using it ;)

Cheers,
Radu.

On 06/22/2012 12:32 AM, mystpuni wrote:
> here it is http://www.mediafire.com/?84pks2byaii578x
>
> --
> View this message in context: http://www.pcl-users.org/saving-data-tp4019514p4019548.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: saving data

mystpuni
mmm I don't remember, ok I try again to save test file using ctrl+c to stop.. and let's see if it works on read tutorial and I'll let you know
Reply | Threaded
Open this post in threaded view
|

Re: saving data

Radu B Rusu
Administrator
No, my point was precisely to NOT ctrl+c an application that's running and trying to save the data to disk, and then
expect the data to be valid :)

Wait until the data has been written to disk, then terminate your program.

Cheers,
Radu.

On 06/22/2012 12:46 AM, mystpuni wrote:
> mmm I don't remember, ok I try again to save test file using ctrl+c to stop..
> and let's see if it works on read tutorial and I'll let you know
>
> --
> View this message in context: http://www.pcl-users.org/saving-data-tp4019514p4019550.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: saving data

mystpuni
ah ok, so maybe I don't understand, how do I stop the running data??
Reply | Threaded
Open this post in threaded view
|

Re: saving data

mystpuni
ok now my read tutorial code doesn't crash anymore, but it says: error.PNG

#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/pcd_io.h>

class SimpleOpenNIViewer
 {
   public:
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
         pcl::PointCloud<pcl::PointXYZ> cloud;

     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
         viewer.showCloud (cloud);
             pcl::io::savePCDFileASCII ("test_pcd.pcd", *cloud);
     }

     void run ()
     {
       // create a new grabber for OpenNI devices
           pcl::Grabber* interface = new pcl::OpenNIGrabber();
           
           // make callback function from member function
       boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
         boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
         
           // connect callback function for desired signal. In this case its a point cloud with color values
       interface->registerCallback (f);
           // start receiving point clouds
       interface->start ();
           // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
       while (!viewer.wasStopped()){Sleep (1);}
           // stop the grabber
       interface->stop ();
     }

     pcl::visualization::CloudViewer viewer;
 };

 int main ()
 {
   SimpleOpenNIViewer v;
   v.run ();
   return 0;
 }


this is just openni_grabber + pcl::io::savePCDFileASCII ("test_pcd.pcd", *cloud); very simple
I use q to quit, and the file returned seem complete respect the first one I've upload (the last line is complete)..
 I'm not an expert but itseems too slow to save ascii file, also the visualization is so slower than the openni_grabber code normal without the save line. any suggestions?
Reply | Threaded
Open this post in threaded view
|

Re: saving data

Radu B Rusu
Administrator
Saving 300k lines of ascii data is slow of course. Try saving your file as PCD binary. The type of the data (ascii vs
binary) should not affect the visualization rendering speed.

Also at this point I would recommend you go through all our tutorials on the web page. Some of the questions you have
raised are extremely simple, and you could find an answer to them in minutes :)

Cheers,
Radu.

On 06/22/2012 02:03 AM, mystpuni wrote:

> ok now my read tutorial code doesn't crash anymore, but it says:
> http://www.pcl-users.org/file/n4019554/error.PNG error.PNG
>
> /#include<pcl/io/openni_grabber.h>
> #include<pcl/visualization/cloud_viewer.h>
> #include<iostream>
> #include<pcl/io/pcd_io.h>
>
> class SimpleOpenNIViewer
>   {
>     public:
>       SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
> pcl::PointCloud<pcl::PointXYZ>  cloud;
>
>       void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr
> &cloud)
>       {
>         if (!viewer.wasStopped())
>           viewer.showCloud (cloud);
>     pcl::io::savePCDFileASCII ("test_pcd.pcd", *cloud);
>       }
>
>       void run ()
>       {
>         // create a new grabber for OpenNI devices
>   pcl::Grabber* interface = new pcl::OpenNIGrabber();
>
>   // make callback function from member function
>         boost::function<void (const
> pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)>  f =
>           boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
>
>   // connect callback function for desired signal. In this case its a
> point cloud with color values
>         interface->registerCallback (f);
>   // start receiving point clouds
>         interface->start ();
>   // wait until user quits program with Ctrl-C, but no busy-waiting ->
> sleep (1);
>         while (!viewer.wasStopped()){Sleep (1);}
>   // stop the grabber
>         interface->stop ();
>       }
>
>       pcl::visualization::CloudViewer viewer;
>   };
>
>   int main ()
>   {
>     SimpleOpenNIViewer v;
>     v.run ();
>     return 0;
>   }
> /
>
> this is just openni_grabber + pcl::io::savePCDFileASCII ("test_pcd.pcd",
> *cloud); very simple
> I use q to quit, and the file returned seem complete respect the first one
> I've upload (the last line is complete)..
>   I'm not an expert but itseems too slow to save ascii file, also the
> visualization is so slower than the openni_grabber code normal without the
> save line. any suggestions?
>
> --
> View this message in context: http://www.pcl-users.org/saving-data-tp4019514p4019554.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: saving data

mystpuni
I know you're right, I'm sorry but sometimes I found difficult to understand tutorials =( anyway I'll try to manage all that I can on my own =)
anyway I've tried binaries as you suggest, cloud viewer is not slower as ascii file, that's ok =)
just adding pcl::io::savePCDFileBinary ("output.pcd", *cloud); to the same openni_grabber. ok I saved the file!!

let's go back to the same read tutorial code and this time it reads my file but: error.PNG