准备
- 安装cmake
$ sudo apt-get install build-essential cmake
- 1
- 安装libfreenect2,github上面有开源的安装包
- 安装opencv,自行百度
获取数据
下面将给出c++获取数据的源码,是一个简单的程序。在引入相应头文件后,声明了初始化函数和获取数据函数,之后在main函数中进行测试。
在这里我使用的是libfreenect2自带的kinect2标定参数
我们只获取了红外数据和深度数据,都是以cv::Mat存储的
#include <iostream>
#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>
#include <libfreenect2/registration.h>
#include <libfreenect2/packet_pipeline.h>
#include <libfreenect2/config.h>
#include <pcl/pcl_config.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <map>
/**
* Get the value of a specified key from a std::map.
* @param m the map
* @param key the key
* @param defaultValue the default value used if the key is not found
* @return the value
*/
template<class K, class V>
inline V uValue(const std::map<K, V> & m, const K & key, const V & defaultValue = V())
{
V v = defaultValue;
typename std::map<K, V>::const_iterator i = m.find(key);
if(i != m.end())
{
v = i->second;
}
return v;
}
/********** global variable begin ************/
int deviceId_;
libfreenect2::Freenect2* freenect2_;
libfreenect2::SyncMultiFrameListener* listener_;
libfreenect2::Freenect2Device* dev_;
libfreenect2::Registration * reg_;
//StereoCameraModel stereoModel_;
/********** global variable end ************/
bool init()
{
libfreenect2::PacketPipeline* pipeline;
pipeline = new libfreenect2::CpuPacketPipeline();
std::cout << ">>> opening default device ..." << std::endl;
dev_ = freenect2_->openDefaultDevice(pipeline);
pipeline = 0;
if(dev_)
{
std::cout << ">>> Had got default device " << std::endl;
libfreenect2::Freenect2Device::Config config;
config.EnableBilateralFilter = true;
config.EnableEdgeAwareFilter = true;
config.MinDepth = 0.3f;
config.MaxDepth = 12.0f;
dev_->setConfiguration(config);
dev_->setColorFrameListener(listener_);
dev_->setIrAndDepthFrameListener(listener_);
dev_->start();
std::cout << ">>&g