Created
January 20, 2016 09:03
-
-
Save r9y9/052f37102066185053a8 to your computer and use it in GitHub Desktop.
openni2_grabber example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <mutex> | |
#include <pcl/io/openni2_grabber.h> | |
#include <pcl/visualization/pcl_visualizer.h> | |
typedef pcl::PointXYZ T; | |
class SimpleOpenNIViewer { | |
public: | |
SimpleOpenNIViewer() | |
: viewer(new pcl::visualization::PCLVisualizer("PCL OpenNI Viewer")) {} | |
void cloud_cb_(const pcl::PointCloud<T>::ConstPtr &cloud) { | |
if (!viewer->wasStopped()) { | |
mtx.lock(); | |
viewer->updatePointCloud<T>(cloud, "openni"); | |
mtx.unlock(); | |
} | |
} | |
void run() { | |
pcl::Grabber *interface = new pcl::io::OpenNI2Grabber( | |
"", pcl::io::OpenNI2Grabber::OpenNI_QVGA_30Hz, | |
pcl::io::OpenNI2Grabber::OpenNI_QVGA_30Hz); | |
pcl::PointCloud<T>::Ptr cloud(new pcl::PointCloud<T>); | |
viewer->addPointCloud<T>(cloud, "openni", 0); | |
boost::function<void(const pcl::PointCloud<T>::ConstPtr &)> f = | |
boost::bind(&SimpleOpenNIViewer::cloud_cb_, this, _1); | |
interface->registerCallback(f); | |
interface->start(); | |
while (!viewer->wasStopped()) { | |
boost::this_thread::sleep(boost::posix_time::millisec(50)); | |
mtx.lock(); | |
viewer->spinOnce(); | |
mtx.unlock(); | |
} | |
interface->stop(); | |
} | |
std::mutex mtx; | |
pcl::visualization::PCLVisualizer::Ptr viewer; | |
}; | |
int main() { | |
SimpleOpenNIViewer v; | |
v.run(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment