【发布时间】:2014-02-01 23:01:10
【问题描述】:
我需要处理 ONI 文件的每一帧。现在我只想将file.oni 的每一帧保存在file.pcd 中。我关注这个code,但它仅适用于 PCL 1.7,我使用的是 v1.6。 所以我以这种方式修改了一点代码
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/oni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <vector>
int i = 0;
char buf[4096];
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
//if (!viewer.wasStopped())
//{
// viewer.showCloud (cloud);
pcl::PCDWriter w;
sprintf (buf, "frame_%06d.pcd", i);
w.writeBinaryCompressed (buf, *cloud);
PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (), cloud->width, cloud->height, buf);
++i;
//}
}
void run ()
{
pcl::Grabber* interface = new pcl::OpenNIGrabber("file.oni");
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));
}
PCL_INFO ("Successfully processed %d frames.\n", i);
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}
但是当我运行它时它崩溃了。为什么?
【问题讨论】:
-
我解决了删除代码行:
PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (), cloud->width, cloud->height, buf);但我不明白为什么?你能帮我理解吗?函数 cloud_cb_ 是否调用了每一帧?
标签: visual-c++ openni point-cloud-library