Saving unorganized point cloud to file

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

Saving unorganized point cloud to file

Mr.Giskard
Greetings,

I am working on a university project which among other things requires
saving point-cloud visualisations to file for further image process and
display. I have downloaded various PCD files from tutorial sites to test my
program but all of them appear to be unorganised and so I cannot use the
PCD2PNG executable (which requires organized point clouds). I can see that
the PCL_viewer software can open and display these unorganised clouds so I
was wondering if there is any way to save such images onto file?

Any help would be greatly appreciated

Thanks





--
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: Saving unorganized point cloud to file

Mr.Giskard
Anybody that can 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: Saving unorganized point cloud to file

Richard Frank
Does this help?



Rick Frank
Sent from Mobile 
617-838-2031

On Mar 28, 2018, at 12:55 PM, Mr.Giskard <[hidden email]> wrote:

Anybody that can 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
Reply | Threaded
Open this post in threaded view
|

Re: Saving unorganized point cloud to file

Mr.Giskard
I don't have any experience in C++ programming so I was hoping to find an executable that saves the vtk visualisation of pcl viewer in an image file i.e something like pcd2png but accepting camera parameters as input.

I understand that no such utility exists, something that I find odd given that exporting a picture of a point cloud would be considered an essential item in the toolkit.

From what I read I will probably have to write code that uses one of the io writePNG routines to write an imported pointcloud to file? Given the time constraints for the project and my lack of experience with c++ I will probably have to abandon the effort bit thanks for the link. Perhaps it would be useful to add such a tool in a future version.



On Wed, 28 Mar 2018 23:01 Richard Frank, <[hidden email]> wrote:
Does this help?



Rick Frank
Sent from Mobile 
617-838-2031

On Mar 28, 2018, at 12:55 PM, Mr.Giskard <[hidden email]> wrote:

Anybody that can 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

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

Re: Saving unorganized point cloud to file

Stephen McDowell
What do you intend to do with these images?  For example if you just want an image for a figure or something, you could open the point cloud using the viewer app and take a screenshot.

If you intend to use them in an algorithm, what is your goal?

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

Re: Saving unorganized point cloud to file

Mr.Giskard
Hi Stephen,

The project setup involves a sensor-activated 3D camera - could be a Kinect or some other similar device - which will take a number of captures. Some way or another the captures will be automatically converted to a format that can be visualised (probably PCD). The pointclouds will then be rotated/scaled into a number of predefined positions (the camera parameters I was referring to).The final step will involve displaying the visualisations in a number of screens which will be connected via a local network. I believe I can automate the entire flow using Python and bash scripts but the stumbling block is the creation of the image files from the pointclouds.


On 29 Mar 2018 03:19, "Stephen McDowell" <[hidden email]> wrote:
What do you intend to do with these images?  For example if you just want an image for a figure or something, you could open the point cloud using the viewer app and take a screenshot.

If you intend to use them in an algorithm, what is your goal?


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

Re: Saving unorganized point cloud to file

Richard Frank
You’d have to dig into the viewer VTK code, but you can save the current render window to a file as in this example.

https://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot

Rick Frank
Dominion Software, Inc.
825 Beacon Street
Newton, MA 02459
Medical, Scientific, and Industrial Software

On Mar 28, 2018, at 10:57 PM, The Passenger <[hidden email]> wrote:

Hi Stephen,

The project setup involves a sensor-activated 3D camera - could be a Kinect or some other similar device - which will take a number of captures. Some way or another the captures will be automatically converted to a format that can be visualised (probably PCD). The pointclouds will then be rotated/scaled into a number of predefined positions (the camera parameters I was referring to).The final step will involve displaying the visualisations in a number of screens which will be connected via a local network. I believe I can automate the entire flow using Python and bash scripts but the stumbling block is the creation of the image files from the pointclouds.


On 29 Mar 2018 03:19, "Stephen McDowell" <[hidden email]> wrote:
What do you intend to do with these images?  For example if you just want an image for a figure or something, you could open the point cloud using the viewer app and take a screenshot.

If you intend to use them in an algorithm, what is your goal?


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

Re: Saving unorganized point cloud to file

Stephen McDowell
I see.  Well, here’s the truth of the matter: embrace C++!!!

I understand the reservation, C++ can be intimidating.  However, unlike some APIs, PCL does a very good job of insulating the user from one of the more important aspects of C++: memory management.  The PCL backend takes care of allocating and freeing memory for point clouds for you.  Furthermore, if you just need to load up a cloud, rotate / translate, and then save an image and be done, you don’t necessarily need to worry about having “good” C++ code — it just needs to work right?!

So my advice:


It is showing how to load and view a PCD file, and a couple of extras.  But the code is short and to the point :)

1. Copy the code verbatim and make sure you can get it to run.  This will probably be your hardest part, because you need to learn how to build C++ code.  Fortunately, you should be able to get by without knowing the details of how CMake works.  The tutorial asks you to create two files in the same directory: CMakeLists.txt and cloud_viewer.cpp.  The mantra for CMake:

# make sure CMakeLists.txt is in this directory
$ ls

# Always build “out of source”, you can delete the whole build directory and start again if needed
$ mkdir build
$ cd build/

# Run CMake, since you mentioned Bash I assume Unix in which case it will give you a Makefile
$ cmake ..
$ make

# Run the executable
$ ./cloud_viewer

That’s it!  In Python you run the file you are writing the source code in, in C++ you need to build it first and run the result.  Though not necessarily good practice, for what you are doing / since you do not know C++ yet, you can get away with implementing this all in one file.  It’ll just be a long file.  If you add more files, make sure you include the files you created in the add_executable line.  E.g. if you created “helpers.hpp” and did #include “helpers.hpp” in the cloud_viewer.cpp file

    add_executable (cloud_viewer cloud_viewer.cpp helpers.hpp)

2. Inspect the PCL viewer interface.  I don’t know the method names but I definitely remember seeing questions about how to rotate / translate, so go find those methods.  Try and get it to work with just one and then add in more once the next step is working.  Note: the rotate / translate methods may come from VTK parent classes, I’m not sure.

3. Use the link Rick just sent (previous post), taking the code to save the current view.  You shouldn’t need all of it, just the parts related to setting up and saving the image.

4. Change the main method to take in a single argument that is the PCD file you want to visualize in different configurations.

5. Make sure you set it up so that the application exits after you are done saving PNGs (rather than waiting for user to exit the window).  When you get to this point, ask a separate question on the mailing list and I’m sure people will be able to help.

The way I envision this working in your larger picture:

(a) {magic} save the PCD from the camera.  since you have some PCD files saved already, you could actually work on this later.
(b) Now that you have an input PCD, from a bash or python script run “./build/cloud_viewer new_file_to_process.pcd”.  The result should be you saving a bunch of new PNG images.  Maybe name them “new_file_to_process_0.png” _1, _2, etc for all the different view points.
    - If you don’t get (5) working then you will need to manually close the window yourself before (c) can happen if (c) is called from the same script calling (b).
(c) Send those PNG images along to wherever you need.

It’s also worth mentioning here that if you get (b) [steps 1-5 above] working in C++, you aren’t too far away from getting (a) working.  PCL has a “grabber” interface at least for the kinect and some other common cameras.


You can just add a couple lines from this tutorial ( http://pointclouds.org/documentation/tutorials/writing_pcd.php#writing-pcd ) in order to save the PCD files you want in the first place!

Technically you could merge (a) and (b) into one program, but for your purposes I think you’re life will be easier if you just keep them separate (so that you don’t have to change more and more of the sample code already provided).  The one thing to pay attention to with the grabber interface is it’s going to keep receiving new point clouds from the camera until you shut it down.  AKA if in the main loop you’re saving every frame as a PCD, you’ll end up with a lot of new PCD files.  So similar to (5) above, you’ll probably want to just save one file and then forcibly shutdown the program.

- - - - - -

I hope the above is helpful in getting you off the ground with C++ and PCL.  The truth is, its a C++ library and if the task you seek is not implemented, you need to implement it yourself.  There is a python interface, but I doubt you’ll be able to do (3) with the python interface.

Please feel free to ask for clarification on the above.  This sounds like a term project in which you have until the end of the semester to finish it.  If so, I think you can do it!  But, I strongly encourage you to discuss with your instructor or TAs whether or not this is something can be done in however much time you have left.  The steps I’ve outlined above may not look too bad, but if you’re brand new to C++ even getting (1) to work may take some time to figure out.

Sounds like a fun project, I hope you can get things working!!!

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

Re: Saving unorganized point cloud to file

Stephen McDowell
Also one more thing.  You mentioned that PCD2PNG requires organized point clouds (taking your word for it, I’ve never used it).  You can try and get (a) above working first, the point clouds coming from range cameras (like the kinect) are organized.

So you may actually be able to avoid all of this (b) stuff (implementing the PNG stuff yourself) if you prioritize getting your hands on organized point clouds yourself first and then running PCD2PNG.

I’m assuming that doesn’t let you specify a rotation and translation, but here’s one last effort you should try before jumping in on all of the stuff I outlined previously:

1. Get the grabber interface sample code working and saving organized point clouds.
2. Make sure you can get a PNG from PCD2PNG out of this.
3. Modify the grabber code that is saving the .pcd files.  I suspect you can get away with rotating and translating the points of the original input cloud and saving multiple PCD files.  I’d be willing to bet that the PCD2PNG tool will respect these transformations, it’s probably assuming a camera viewpoint of (0,0,0), so if you rotate and translate and save a new PCD file, it may be that’s all you need.

Sorry for not including this first, definitely try this approach before trying to implement the stuff I mentioned in the previous post.

Even it it doesn’t work, you’ve now solved (a) {getting the organized PCD} and then could start in on steps [1-5] in the previous post.

That was a lot of information, sorry if it is too much…




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

Re: Saving unorganized point cloud to file

Mr.Giskard
In reply to this post by Richard Frank
Hi Richard,

Apologies for the late reply, my working hours have been crazy lately. 

Thanks for the example, I will study it in the next few days and understand the steps involved

On Thu, 29 Mar 2018 14:44 Richard Frank, <[hidden email]> wrote:
You’d have to dig into the viewer VTK code, but you can save the current render window to a file as in this example.

https://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/Screenshot

Rick Frank
Dominion Software, Inc.
825 Beacon Street
Newton, MA 02459
Medical, Scientific, and Industrial Software

On Mar 28, 2018, at 10:57 PM, The Passenger <[hidden email]> wrote:

Hi Stephen,

The project setup involves a sensor-activated 3D camera - could be a Kinect or some other similar device - which will take a number of captures. Some way or another the captures will be automatically converted to a format that can be visualised (probably PCD). The pointclouds will then be rotated/scaled into a number of predefined positions (the camera parameters I was referring to).The final step will involve displaying the visualisations in a number of screens which will be connected via a local network. I believe I can automate the entire flow using Python and bash scripts but the stumbling block is the creation of the image files from the pointclouds.


On 29 Mar 2018 03:19, "Stephen McDowell" <[hidden email]> wrote:
What do you intend to do with these images?  For example if you just want an image for a figure or something, you could open the point cloud using the viewer app and take a screenshot.

If you intend to use them in an algorithm, what is your goal?

_______________________________________________
[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 unorganized point cloud to file

Mr.Giskard
In reply to this post by Stephen McDowell
Hi Stephen,

Apologies for not replying earlier, as I mentioned to Richard things have been pretty hectic these padt few days

C++ does indeed look intimidating although to be honest, I'm more intimidated by the CMakeFiles business than the language itself :)

Thank you for the very detailed information you have provided me, I will spend the weekend going through it and trying out the various parts

I will update you and the other PCL users here on my progress

Kind regards

Savvas 


On Fri, 30 Mar 2018 02:09 Stephen McDowell, <[hidden email]> wrote:
Also one more thing.  You mentioned that PCD2PNG requires organized point clouds (taking your word for it, I’ve never used it).  You can try and get (a) above working first, the point clouds coming from range cameras (like the kinect) are organized.

So you may actually be able to avoid all of this (b) stuff (implementing the PNG stuff yourself) if you prioritize getting your hands on organized point clouds yourself first and then running PCD2PNG.

I’m assuming that doesn’t let you specify a rotation and translation, but here’s one last effort you should try before jumping in on all of the stuff I outlined previously:

1. Get the grabber interface sample code working and saving organized point clouds.
2. Make sure you can get a PNG from PCD2PNG out of this.
3. Modify the grabber code that is saving the .pcd files.  I suspect you can get away with rotating and translating the points of the original input cloud and saving multiple PCD files.  I’d be willing to bet that the PCD2PNG tool will respect these transformations, it’s probably assuming a camera viewpoint of (0,0,0), so if you rotate and translate and save a new PCD file, it may be that’s all you need.

Sorry for not including this first, definitely try this approach before trying to implement the stuff I mentioned in the previous post.

Even it it doesn’t work, you’ve now solved (a) {getting the organized PCD} and then could start in on steps [1-5] in the previous post.

That was a lot of information, sorry if it is too much…



_______________________________________________
[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 unorganized point cloud to file

Mr.Giskard
Hi Stephen,

I've been trying to compile the first example from your steps (cloud
viewer) but I've run into problems which I'm finding it hard to
comprehend. What I did is create a new directory in my source pcl
folder (/home/pi/pcl) called "cloud_viewer" where I've put the cpp &
CMakeLists.txt files from the example. In this folder I created the
"build" subdirectory

When I change to build and type cmake .. I get the error "The source
directory "/home/pi/pcl/cloud_viewer" does not appear to contain
CMakeLists.txt." However the file is most definitely in the folder.
What am I doing wrong?

On 30/03/2018, The Passenger <[hidden email]> wrote:

> Hi Stephen,
>
> Apologies for not replying earlier, as I mentioned to Richard things have
> been pretty hectic these padt few days
>
> C++ does indeed look intimidating although to be honest, I'm more
> intimidated by the CMakeFiles business than the language itself :)
>
> Thank you for the very detailed information you have provided me, I will
> spend the weekend going through it and trying out the various parts
>
> I will update you and the other PCL users here on my progress
>
> Kind regards
>
> Savvas
>
>
> On Fri, 30 Mar 2018 02:09 Stephen McDowell, <[hidden email]> wrote:
>
>> Also one more thing.  You mentioned that PCD2PNG requires organized point
>> clouds (taking your word for it, I’ve never used it).  You can try and
>> get
>> (a) above working *first*, the point clouds coming from range cameras
>> (like the kinect) are organized.
>
>> So you may actually be able to avoid *all* of this (b) stuff
>> (implementing the PNG stuff yourself) if you prioritize getting your
>> hands
>> on organized point clouds yourself first and then running PCD2PNG.
>
>> I’m assuming that doesn’t let you specify a rotation and translation, but
>> here’s one last effort you should try before jumping in on all of the
>> stuff
>> I outlined previously:
>
>> 1. Get the grabber interface sample code working and saving organized
>> point clouds.
>> 2. Make sure you can get a PNG from PCD2PNG out of this.
>> 3. Modify the grabber code that is saving the .pcd files.  I suspect you
>> can get away with rotating and translating the points of the original
>> input
>> cloud and saving multiple PCD files.  I’d be willing to bet that the
>> PCD2PNG tool will respect these transformations, it’s probably assuming a
>> camera viewpoint of (0,0,0), so if you rotate and translate and save a
>> new
>> PCD file, it may be that’s all you need.
>
>> Sorry for not including this first, *definitely try this approach before
>> trying to implement the stuff I mentioned in the previous post.*
>
>> Even it it doesn’t work, you’ve now solved (a) {getting the organized
>> PCD}
>> and then could start in on steps [1-5] in the previous post.
>
>> That was a lot of information, sorry if it is too much…
>
>
>
>> _______________________________________________
>> [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 unorganized point cloud to file

Stephen McDowell
Hmm. What is the output of

ls /home/pi/pcl/cloud_viewer

?

The naming has to be exact, capital C, M, and L, with a .txt suffix

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

Re: Saving unorganized point cloud to file

Stephen McDowell

Hmm. What is the output of

ls /home/pi/pcl/cloud_viewer

or better, what is the output of this command?

    tree /home/pi/pcl

I made a quick directory mockup in my /tmp, the layout of the directory structure should be something like this

    tree /tmp/pi/
    /tmp/pi/
    └── pcl
        └── cloud_viewer
            ├── CMakeLists.txt
            ├── build
            │   └── RUN cmake .. FROM HERE
            └── the_source_code.cpp

(where you don’t need to make the file ‘RUN cmake .. FROM HERE’!!!)

I think what you may have done is create /home/pi/pcl/build or something, but from your build directory if you do

    ls ..

That will show the contents of the parent directory.  If there is no CMakeLists.txt file, then CMake will give you the error you are getting.


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

Re: Saving unorganized point cloud to file

Mr.Giskard
Output of ls ~/pcl/cloud_viewer is :

build  cloud_viewer.cpp  CMakeLists.txt

Output of tree ~/pcl is too large to print here (it's the entire pcl
release) but the relevant folder is

├──  cloud_viewer
│   ├──  build
│   ├── cloud_viewer.cpp
│   └── CMakeLists.txt


The folder I  made is on the same level as all the other module source
code folders of the distribution.

ls .. under ~/pcl/cloud_viewer/build displays the same as ls
~/pcl/cloud_viewer i.e

build  cloud_viewer.cpp  CMakeLists.txt




On 02/04/2018, Stephen McDowell <[hidden email]> wrote:

>
>> Hmm. What is the output of
>>
>> ls /home/pi/pcl/cloud_viewer
>
> or better, what is the output of this command?
>
>     tree /home/pi/pcl
>
> I made a quick directory mockup in my /tmp, the layout of the directory
> structure should be something like this
>
>     tree /tmp/pi/
>     /tmp/pi/
>     └── pcl
>         └── cloud_viewer
>             ├── CMakeLists.txt
>             ├── build
>             │   └── RUN cmake .. FROM HERE
>             └── the_source_code.cpp
>
> (where you don’t need to make the file ‘RUN cmake .. FROM HERE’!!!)
>
> I think what you may have done is create /home/pi/pcl/build or something,
> but from your build directory if you do
>
>     ls ..
>
> That will show the contents of the parent directory.  If there is no
> CMakeLists.txt file, then CMake will give you the error you are getting.
>
>
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Saving unorganized point cloud to file

Mr.Giskard
Hi

Can someone provide any pointers towards understanding what is causing this behaviour? It appears to be something basic - at least within the makefile configuration universe - but as I have no prior experience with this and the error message is odd (given that the file exists in the folder) I'm a bit stumped

I believe that once I manage to compile at least one PCL executable I will work out all the rest to get the solution I want for my project

On Mon, 2 Apr 2018 23:00 The Passenger, <[hidden email]> wrote:
Output of ls ~/pcl/cloud_viewer is :

build  cloud_viewer.cpp  CMakeLists.txt

Output of tree ~/pcl is too large to print here (it's the entire pcl
release) but the relevant folder is

├──  cloud_viewer
│   ├──  build
│   ├── cloud_viewer.cpp
│   └── CMakeLists.txt


The folder I  made is on the same level as all the other module source
code folders of the distribution.

ls .. under ~/pcl/cloud_viewer/build displays the same as ls
~/pcl/cloud_viewer i.e

build  cloud_viewer.cpp  CMakeLists.txt




On 02/04/2018, Stephen McDowell <[hidden email]> wrote:
>
>> Hmm. What is the output of
>>
>> ls /home/pi/pcl/cloud_viewer
>
> or better, what is the output of this command?
>
>     tree /home/pi/pcl
>
> I made a quick directory mockup in my /tmp, the layout of the directory
> structure should be something like this
>
>     tree /tmp/pi/
>     /tmp/pi/
>     └── pcl
>         └── cloud_viewer
>             ├── CMakeLists.txt
>             ├── build
>             │   └── RUN cmake .. FROM HERE
>             └── the_source_code.cpp
>
> (where you don’t need to make the file ‘RUN cmake .. FROM HERE’!!!)
>
> I think what you may have done is create /home/pi/pcl/build or something,
> but from your build directory if you do
>
>     ls ..
>
> That will show the contents of the parent directory.  If there is no
> CMakeLists.txt file, then CMake will give you the error you are getting.
>
>

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