PCL中的快速三角测量

时间:2013-03-21 00:49:28

标签: mutex triangulation point-cloud-library

我想在对它们应用Passthrough过滤器后对Point Cloud进行三角测量。 它编译但观众没有显示任何内容。

这是我的源代码:

#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include <pcl/surface/organized_fast_mesh.h>
#include <pcl/console/parse.h>
#include <pcl/common/time.h>
#include <pcl/console/time.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/passthrough.h>

using namespace pcl;
using namespace pcl::visualization;
using namespace std;

#define FPS_CALC(_WHAT_) \
do \
{ \
    static unsigned count = 0;\
    static double last = pcl::getTime ();\
    if (++count == 100) \
    { \
      double now = pcl::getTime (); \
      std::cout << "Average framerate("<< _WHAT_ << "): " << double(count)/double(now - last) << " Hz" <<  std::endl; \
      count = 0; \
      last = now; \
    } \
}while(false)

template <typename PointType>
class OpenNIFastMesh
{
  public:
    typedef pcl::PointCloud<PointType> Cloud;
    typedef typename Cloud::Ptr CloudPtr;
    typedef typename Cloud::ConstPtr CloudConstPtr;

    OpenNIFastMesh (const std::string& device_id = "")
      : device_id_(device_id), vertices_ ()
    {
      ofm.setTrianglePixelSize (3);
      ofm.setTriangulationType (pcl::OrganizedFastMesh<PointType>::QUAD_MESH);

      pass_.setFilterFieldName("z");
      pass_.setFilterLimits(0.0, 1.0);
    }

    void 
    cloud_cb (const CloudConstPtr& cloud)
    {

      FPS_CALC ("computation");
      boost::mutex::scoped_lock lock(mtx_);
      cloud_ = cloud;


    }

    void
    run (int argc, char **argv)
    {
      pcl::Grabber* interface = new pcl::OpenNIGrabber (device_id_);

      boost::function<void (const CloudConstPtr&)> f = boost::bind (&OpenNIFastMesh::cloud_cb, this, _1);
      boost::signals2::connection c = interface->registerCallback (f);

      view.reset (new pcl::visualization::PCLVisualizer (argc, argv, "PCL OpenNI Mesh Viewer"));

      interface->start ();

      CloudConstPtr temp_cloud;
      boost::shared_ptr<std::vector<pcl::Vertices> > temp_verts;
      pcl::console::TicToc t1;

      while (!view->wasStopped ())

      {

        if (!cloud_ || !mtx_.try_lock ())
        {
          boost::this_thread::sleep (boost::posix_time::milliseconds (1));
          continue;
        }

        //CloudPtr temp;
        //temp.reset(new Cloud);
        //pass_.setInputCloud(cloud_);
        //pass_.filter(*temp);

        ofm.setInputCloud(cloud_);
        boost::shared_ptr<std::vector<pcl::Vertices> > temp_verts (new std::vector<pcl::Vertices>);
        ofm.reconstruct(*temp_verts);

        //vertices_ = temp_verts;
        mtx_.unlock();

        if (!view->updatePolygonMesh<PointType> (cloud_, *vertices_, "surface"))
        {
          view->addPolygonMesh<PointType> (cloud_, *vertices_, "surface");

        }

        FPS_CALC ("visualization");
        view->spinOnce (1);
      }

      interface->stop ();
    }




    pcl::OrganizedFastMesh<PointType> ofm;
    pcl::PassThrough<PointType> pass_;
    std::string device_id_;

    boost::mutex mtx_;

    CloudConstPtr cloud_;
    boost::shared_ptr<std::vector<pcl::Vertices> > vertices_;
    pcl::PolygonMesh::Ptr mesh_;


    boost::shared_ptr<pcl::visualization::PCLVisualizer> view;
};


int
main (int argc, char ** argv)
{

    OpenNIFastMesh<pcl::PointXYZ> v ("");
    v.run (argc, argv);

  return (0);
}

我认为探测来自互斥锁。

1 个答案:

答案 0 :(得分:0)

查看功能“运行”。你已经把代码

    ofm.setInputCloud(cloud_);
    boost::shared_ptr<std::vector<pcl::Vertices> > temp_verts (new  td::vector<pcl::Vertices>);
    ofm.reconstruct(*temp_verts);

在错误的地方。

它们应该在回调函数“cloud_cb_”中,而不是在“run”中。当一个新的pointcloud可用时,它应该被执行。

有关更多信息,请查看pcl的源文件夹,该文件夹位于app / src / openni_fast_mash.cpp中。