从C++文件(点云库)获取数据
Wrtie Data from C++ File (Point Cloud Library)
我正在使用点云库来获取深度图,然后每秒左右将PCD文件写入存储器,以便它可以被另一个程序拾取。
我让程序使用可视化工具正确渲染深度图,除了实际写入文件的一行之外,它都可以正常工作。
这是我的代码:
#include <pcl/io/openni_grabber.h>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
if (!viewer.wasStopped())
viewer.showCloud (cloud);
//this is the line to write the file.
//I am not sure it is the correct location.
pcl::io::savePCDFileASCII ("test_pcd_here.pcd", cloud);
}
void run ()
{
pcl::Grabber* interface = new pcl::OpenNIGrabber();
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
interface->registerCallback (f);
interface->start ();
while (!viewer.wasStopped())
{
boost::this_thread::sleep (boost::posix_time::seconds (1));
}
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}
这是我在尝试制作文件时遇到的错误:
/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp: In member function ‘void SimpleOpenNIViewer::cloud_cb_(const ConstPtr&)’:
/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp:15:59: error: no matching function for call to ‘savePCDFileASCII(const char [18], const ConstPtr&)’
/home/patrick/Desktop/kinect/grabber/openni_grabber.cpp:15:59: note: candidate is:
/usr/include/pcl-1.6/pcl/io/pcd_io.h:704:5: note: template<class PointT> int pcl::io::savePCDFileASCII(const string&, const pcl::PointCloud<PointT>&)
make[2]: *** [CMakeFiles/openni_grabber.dir/openni_grabber.cpp.o] Error 1
make[1]: *** [CMakeFiles/openni_grabber.dir/all] Error 2
make: *** [all] Error 2
savePCDFileASCII()
函数在提供指针时需要对PointCloud
的常量引用。您必须取消引用指针:
pcl::io::savePCDFileASCII ("test_pcd_here.pcd", *cloud);
请记住,您的回调函数会尽可能频繁地触发(每秒多次),因此您可能需要限制导出。更重要的是,如果您尝试在其他程序读取数据时写入数据(或相反),则任一程序都可能崩溃(争用条件)因此,您需要某种形式的同步或直接通过其他方式(例如套接字或管道)流式传输 PointCloud。
相关文章:
- C++ - 忽略并从其他文件获取数据
- 如何从网站获取数据并将其传输到数据库?
- 与多个 for 循环与单个 for 循环 wrt 相关的性能从多映射获取数据
- 如何从 CSV 获取数据并将其存储在 C++ 中的表对象中
- 获取 R 数据帧的内存地址
- C++ 如何从虚拟类的模板化子类中获取数据?
- 如何在C++中使用带有SFML的http reqest从节点.js服务器获取数据?
- 连接到远程存储库并获取数据
- 使用WiFi.h从WiFiClient ESP32获取数据
- CSV文件未从缓冲区获取数据
- C++从双指针获取数据
- C++ 从文件中获取数据时使用 strcpy 和 strcmp 按字母顺序对数组进行排序?
- 使用 Recvfrom 获取数据
- C 编程:在循环时运行 2 并从 loop1 获取数据的随机结果
- 复制构造函数并从方法中获取数据
- 如何在运行时从平面缓冲区获取数据值和数据类型
- 在C J2ME中读取Excel文件,并从ITQ获取数据
- 如何通过NodeMCU从Web获取数据
- 获取数据QFUTUREWATCHER
- 从文件中获取数据时如何放置换行符?