PCL——獲取Kinect裝置
阿新 • • 發佈:2018-11-15
獲取Kinect裝置程式碼如下:
#include<iostream> #include "kinect.h" int main() { printf("Hello, Wellcome to kinect world!\n"); IKinectSensor* bb; //申請一個Sensor指標 名稱為bb HRESULT hr = GetDefaultKinectSensor(&bb); // 獲取一個預設的Sensor if (FAILED(hr)) { printf("No Kinect connect to your pc!\n"); goto endstop; } BOOLEAN bIsOpen = 0; bb->get_IsOpen(&bIsOpen); // 檢視下是否已經開啟 printf("bIsOpen: %d\n", bIsOpen); if (!bIsOpen) // 沒開啟,則嘗試開啟 { hr = bb->Open(); if (FAILED(hr)) { printf("Kinect Open Failed!\n"); goto endstop; } printf("Kinect opened! But it need sometime to work!\n"); // 這裡一定要多等會,否則下面的判斷都是錯誤的 printf("Wait For 3000 ms...\n"); Sleep(3000); } bIsOpen = 0; bb->get_IsOpen(&bIsOpen); // 是否已經開啟 printf("bIsOpen: %d\n", bIsOpen); BOOLEAN bAvaliable = 0; bb->get_IsAvailable(&bAvaliable); // 是否可用 printf("bAvaliable: %d\n", bAvaliable); DWORD dwCapability = 0; bb->get_KinectCapabilities(&dwCapability); // 獲取容量 printf("dwCapability: %d\n", dwCapability); TCHAR bbuid[256] = { 0 }; bb->get_UniqueKinectId(256, bbuid); // 獲取唯一ID printf("UID: %s\n", bbuid); bb->Close(); endstop: system("pause"); return 0; }
其中的get_IsOpen get_IsAvaliable get_KinectCapabilities get_UniqueKinectId 均為Kinect庫中自帶函式
無Kinect裝置連線時:
有Kinect裝置連線時: