Windows-8.1_x64+VS2012+Kinect V2环境配置

时间:2025-03-28 19:49:22
#include <> // 使用Kinect #include <iostream> void kinectTest() { IKinectSensor *mySensor = nullptr; GetDefaultKinectSensor(&mySensor); // 获取传感器 mySensor->Open(); // 打开感应器 // ---------------------获取深度数据-------------------------------------- IDepthFrameSource *mySource = nullptr; mySensor->get_DepthFrameSource(&mySource); // 获取深度数据 int height = 0, width = 0; IFrameDescription *myDescription = nullptr; mySource->get_FrameDescription(&myDescription); // 获取深度数据的分辨率 myDescription->get_Height(&height); myDescription->get_Width(&width); myDescription->Release(); myDescription = nullptr; IDepthFrameReader *myReader = nullptr; mySource->OpenReader(&myReader); // 打开深度数据的Reader int times = 100; IDepthFrame *myFrame = nullptr; cv::Mat temp(height, width, CV_16UC1); cv::Mat img(height, width, CV_8UC1); while (times) { if (myReader->AcquireLatestFrame(&myFrame) == S_OK) // { UINT size = 0; UINT16 *buffer = nullptr; myFrame->AccessUnderlyingBuffer(&size, &buffer); std::cout << times << "\t"<< buffer[width*(height/2) + width/2] << std::endl; times--; myFrame->Release(); /* myFrame->CopyFrameDataToArray(height*width, (UINT16 *)); (img, CV_8UC1, 255.0 / 4500); imshow("Depth Map", img); myFrame->Release(); myFrame = nullptr;*/ } if (cv::waitKey(30) == VK_ESCAPE) { break; } } myReader->Release(); myReader = nullptr; mySource->Release(); mySource = nullptr; mySensor->Close(); mySensor->Release(); mySensor = nullptr; }