openni

tech2023-07-19  125

openni_grabber.cpp

#include <pcl/io/openni_grabber.h> #include <pcl/visualization/cloud_viewer.h> #ifdef _WIN32 # define sleep(x) Sleep((x)*1000) #endif class SimpleOpenNIViewer { public: SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {} void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud) { if (!viewer.wasStopped()) viewer.showCloud (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; }

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(openni_grabber) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable(openni_grabber openni_grabber.cpp) target_link_libraries(openni_grabber ${PCL_LIBRARIES})

注意:

这里可能需要特殊设备,仅用电脑跑会有问题(个人想法)。

最新回复(0)