首页 > 其他 > 详细

获取深度图像

时间:2020-03-27 15:44:18      阅读:70      评论:0      收藏:0      [点我收藏+]
#include<stdafx.h>
#include <iostream>
#include <opencv2\imgproc.hpp>    //opencv头文件
#include <opencv2\calib3d.hpp>
#include <opencv2\highgui.hpp>
#include <Kinect.h>    //Kinect头文件

using namespace std;
using namespace cv;

int main(void)
{
    //初始化Kinect
    IKinectSensor* mySensor;
    HRESULT hResult = S_OK;
    hResult = GetDefaultKinectSensor(&mySensor);
    if (FAILED(hResult)) {
        cerr << "Error : GetDefaultKinectSensor" << std::endl;
        return -1;
    }
    hResult = mySensor->Open();
    if (FAILED(hResult)) {
        cerr << "Error : IKinectSensor::Open()" << std::endl;
        return -1;
    }

    //深度帧源
    IDepthFrameSource   * myDepthSource = nullptr;
    hResult = mySensor->get_DepthFrameSource(&myDepthSource);
    if (FAILED(hResult)) {
        cerr << "Error : IKinectSensor::get_DepthFrameSource()" << std::endl;
        return -1;
    }

    //深度帧读取
    IDepthFrameReader *myDepthReader = nullptr;
    hResult = myDepthSource->OpenReader(&myDepthReader);
    if (FAILED(hResult)) {
        cerr << "Error : IDepthFrameSource::OpenReader()" << std::endl;
        return -1;
    }

    //Description
    IFrameDescription * myDescription = nullptr;
    hResult = myDepthSource->get_FrameDescription(&myDescription);
    if (FAILED(hResult)) {
        cerr << "Error : IColorFrameSource::get_FrameDescription()" << std::endl;
        return -1;
    }
    int height = 0, width = 0;
    myDescription->get_Height(&height);
    myDescription->get_Width(&width);
    myDescription->Release();

    Mat temp(height, width, CV_16UC1);    //建立图像矩阵
    Mat img(height, width, CV_8UC1);
    IDepthFrame * myDepthFrame = nullptr;

    while (1)
    {

        while (myDepthReader->AcquireLatestFrame(&myDepthFrame) != S_OK);
        myDepthFrame->CopyFrameDataToArray(height*width, (UINT16 *)temp.data);
        temp.convertTo(img, CV_8UC1, 255.0 / 4500);

        myDepthFrame->Release();   //释放彩色帧
        imshow("test", img);
        if (waitKey(30) == VK_ESCAPE)
            break;
        //Sleep(1000);
    }
    myDepthSource->Release();
    myDepthReader->Release();
    mySensor->Close();
    mySensor->Release();
    return 0;
}

技术分享图片

 

 

#include<stdafx.h>#include <iostream>#include <opencv2\imgproc.hpp>//opencv头文件#include <opencv2\calib3d.hpp>#include <opencv2\highgui.hpp>#include <Kinect.h>//Kinect头文件
using namespace std;using namespace cv;
int main(void){//初始化KinectIKinectSensor* mySensor;HRESULT hResult = S_OK;hResult = GetDefaultKinectSensor(&mySensor);if (FAILED(hResult)) {cerr << "Error : GetDefaultKinectSensor" << std::endl;return -1;}hResult = mySensor->Open();if (FAILED(hResult)) {cerr << "Error : IKinectSensor::Open()" << std::endl;return -1;}
//深度帧源IDepthFrameSource   * myDepthSource = nullptr;hResult = mySensor->get_DepthFrameSource(&myDepthSource);if (FAILED(hResult)) {cerr << "Error : IKinectSensor::get_DepthFrameSource()" << std::endl;return -1;}
//深度帧读取IDepthFrameReader *myDepthReader = nullptr;hResult = myDepthSource->OpenReader(&myDepthReader);if (FAILED(hResult)) {cerr << "Error : IDepthFrameSource::OpenReader()" << std::endl;return -1;}
//DescriptionIFrameDescription * myDescription = nullptr;hResult = myDepthSource->get_FrameDescription(&myDescription);if (FAILED(hResult)) {cerr << "Error : IColorFrameSource::get_FrameDescription()" << std::endl;return -1;}int height = 0, width = 0;myDescription->get_Height(&height);myDescription->get_Width(&width);myDescription->Release();
Mat temp(height, width, CV_16UC1);    //建立图像矩阵Mat img(height, width, CV_8UC1);IDepthFrame * myDepthFrame = nullptr;
while (1){
while (myDepthReader->AcquireLatestFrame(&myDepthFrame) != S_OK);myDepthFrame->CopyFrameDataToArray(height*width, (UINT16 *)temp.data);temp.convertTo(img, CV_8UC1, 255.0 / 4500);
myDepthFrame->Release();   //释放彩色帧imshow("test", img);if (waitKey(30) == VK_ESCAPE)break;//Sleep(1000);}myDepthSource->Release();myDepthReader->Release();mySensor->Close();mySensor->Release();return 0;}

 

获取深度图像

原文:https://www.cnblogs.com/ikic/p/12581077.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!