kinect v2 同时获取红外图、深度图、彩色图

#include <stdio.h>
#include <Kinect.h>
#include <windows.h>
#include <opencv\highgui.h>
#include <opencv\cv.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <strstream>

using namespace cv;
using namespace std;

void GetColorDepthInfrared()
{
    IKinectSensor*          m_pKinectSensor;

    IDepthFrameReader*      m_pDepthFrameReader;
    IDepthFrameSource*      pDepthFrameSource = NULL;

    IInfraredFrameSource*   pInfraredFrameSource = NULL;
    IInfraredFrameReader*   InfraredFrameReader;

    IColorFrameReader*      ColorFrameReader = NULL;
    IColorFrameSource*      ColorFrameSource = NULL;

    IFrameDescription*      FrameDescription = NULL;

    GetDefaultKinectSensor(&m_pKinectSensor);     
    //打开传感器
    m_pKinectSensor->Open();


    m_pKinectSensor->get_DepthFrameSource(&pDepthFrameSource);

    m_pKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource);

    m_pKinectSensor->get_ColorFrameSource(&ColorFrameSource);

    pDepthFrameSource->OpenReader(&m_pDepthFrameReader);

    pInfraredFrameSource->OpenReader(&InfraredFrameReader);

    ColorFrameSource->OpenReader(&ColorFrameReader);

    while (true)
    {
        IInfraredFrame*       InfraredFrame = NULL;
        IDepthFrame*          pDepthFrame = NULL;
        IColorFrame*          pColorFrame = NULL;


        while (pDepthFrame == NULL){
            m_pDepthFrameReader->AcquireLatestFrame(&pDepthFrame);
        }
        pDepthFrameSource->get_FrameDescription(&FrameDescription);
        int depth_width, depth_height;

        FrameDescription->get_Width(&depth_width);
        FrameDescription->get_Height(&depth_height);

        Mat DepthImg(depth_height, depth_width, CV_16UC1);
        pDepthFrame->CopyFrameDataToArray(depth_height * depth_width, (UINT16 *)DepthImg.data);

        //转换为8位图像
        DepthImg.convertTo(DepthImg, CV_8UC1, 255.0 / 4500);
        //均衡化
        equalizeHist(DepthImg, DepthImg);


        while (InfraredFrame == NULL){
            InfraredFrameReader->AcquireLatestFrame(&InfraredFrame);
        }
        InfraredFrame->get_FrameDescription(&FrameDescription);
        int nWidth, nHeight;

        FrameDescription->get_Width(&nWidth);
        FrameDescription->get_Height(&nHeight);

        Mat InfraredImg(nHeight, nWidth, CV_16UC1);

        InfraredFrame->CopyFrameDataToArray(nWidth * nHeight, (UINT16 *)InfraredImg.data);





        while (pColorFrame == NULL){
            ColorFrameReader->AcquireLatestFrame(&pColorFrame);
        }
        pColorFrame->get_FrameDescription(&FrameDescription);
        int CWidth, CHeight;

        FrameDescription->get_Width(&CWidth);
        FrameDescription->get_Height(&CHeight);

        Mat ColorImg(CHeight, CWidth, CV_8UC4);

        pColorFrame->CopyConvertedFrameDataToArray(CWidth * CHeight * 4, (BYTE *)ColorImg.data, ColorImageFormat_Bgra);



        //显示图像
        resize(ColorImg, ColorImg, Size(512, 424));

        imshow("InfraredImg", InfraredImg);
        imshow("depthImg", DepthImg);
        imshow("ColorImg", ColorImg);



        DepthImg.release();
        ColorImg.release();
        InfraredImg.release();

        if (pDepthFrame)
            pDepthFrame->Release();
        if (pColorFrame)
            pColorFrame->Release();
        if (InfraredFrame)
            InfraredFrame->Release();
        if (27 == waitKey(50))
            break;
    }
}

int main()
{
    GetColorDepthInfrared();
}
  • 1
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值