Linux下采集Kinect2图像数据(非ROS版)

准备

  1. 安装cmake
$ sudo apt-get install build-essential cmake
  • 1
  1. 安装libfreenect2,github上面有开源的安装包
  2. 安装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
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值