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;}

  • 相关阅读:
    D. Constructing the Array
    B. Navigation System
    B. Dreamoon Likes Sequences
    A. Linova and Kingdom
    G. Special Permutation
    B. Xenia and Colorful Gems
    Firetrucks Are Red
    java getInstance()的使用
    java 静态代理和动态代理
    java 类加载机制和反射机制
  • 原文地址:https://www.cnblogs.com/ikic/p/12581077.html
Copyright © 2011-2022 走看看