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

  • 相关阅读:
    [JOYOI1326] 剑人合一
    linux hive +mysql(mysql用于hive元数据存储)
    hadoop 伪分布式单机部署练习hive
    pyhton 操作hive数据仓库
    python操作hadoop HDFS api使用
    hadoop伪集群部署
    python 文件指针切割文件
    jdk8 permgen OOM再见迎来metaspace
    java JVM内存区域模型
    java垃圾回收
  • 原文地址:https://www.cnblogs.com/ikic/p/12581077.html
Copyright © 2011-2022 走看看