PCL library tutorial provides a framework to grab .pcd file: http://pointclouds.org/documentation/tutorials/dinast_grabber.php#dinast-grabber. This functionality is really useful since users can save the camera capture for later processing. However, one drawback of the exist scheme is that the duration for capturing is too long. Usually it takes a few seconds to save one .pcd file for a 640x480 image resolution. For the scenario while multiple captures are needed, the long delay makes the capturing difficult. Since .pcd file is like text file, a common way to reduce the capture time is to save the data in binary format instead of in text format. After switching the file format from .pcd to binary, we observe a roughly 10x acceleration of capture time. Instead of one capture in a few seconds, it changes to several captures in one second. We believe that this technique may also be useful to other people. Thus we want to share the trick here. The main function for binary file generation is like this:
void saveCloudToBin (const std::string &file_name, const pcl::PointCloud<pcl::PointXYZRGBA> &cloud, const int cloud_size)
{
std::ofstream myfile(file_name, std::ios_base::binary);
if (myfile.is_open())
{
for (int i = 0; i < cloud_size; i++)
{
myfile.write((char *)&cloud.points[i].x, sizeof(float));
myfile.write((char *)&cloud.points[i].y, sizeof(float));
myfile.write((char *)&cloud.points[i].z, sizeof(float));
myfile.write((char *)&cloud.points[i].rgb , sizeof(int));
}
myfile.close();
}
else
{
std::cout << "Unable to open " << file_name << std::endl;
}
}
The whole program, openni_grabber_fast.cpp, is available here: https://drive.google.com/file/d/0B05MVyfGr8lmZ2xfUjRIV1F0dWc/view?usp=sharing
An associated make file can be found at: https://drive.google.com/file/d/0B05MVyfGr8lmSFUwdnJKX3U3dW8/view?usp=sharing
After running openni_grabber_fast.exe, binary files will be generated with the names of test_pcd0.bin, test_pcd1.bin, etc. In order to convert from binary files to .pcd files, we wrote another program named binary2pcd.cpp available at https://drive.google.com/file/d/0B05MVyfGr8lmanhIRWduem83eW8/view?usp=sharing. Putting binary2pcd.exe at the same folder of binary files and running it should generate corresponding .pcd files as well as 2D image files.
The procedure discussed here is based on Windows platform. But with source codes and make file available, extending this to other platforms should be straightforward.
No comments:
Post a Comment