zoukankan      html  css  js  c++  java
  • 获取深度图像

    #include<stdafx.h>
    #include <iostream>
    #include <opencv2imgproc.hpp>    //opencv头文件
    #include <opencv2calib3d.hpp>
    #include <opencv2highgui.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 <opencv2imgproc.hpp>//opencv头文件#include <opencv2calib3d.hpp>#include <opencv2highgui.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;}

  • 相关阅读:
    Apache HTTP Server 与 Tomcat 的三种连接方式介绍(转)
    Java实现二叉树遍历以及常用算法
    随想-经验
    Java代码检查工具
    MongoDB学习笔记-维护
    脏检查
    html5对密码加密
    JavaSript模块化-AMD规范与CMD规范
    AngularJS的$watch用法
    常用的几个小函数
  • 原文地址:https://www.cnblogs.com/ikic/p/12581077.html
Copyright © 2011-2022 走看看