チュートリアル:モジュールとカメラの一覧表示

機能モジュールと複数のカメラの列挙は、目的のデバイスを選択するためのアプリケーションロジックの重要なコンポーネントです。 このチュートリアルでは、必要なモジュールを選択できるように、モジュールと複数のデバイスを一覧表示する方法について説明します。











システムに接続されたカメラの検出とこれらのカメラの機能の決定は、デバイスをリストすることで簡素化できます。 Intel RealSense SDK 2016 R1は、 PXCSession :: ImplDescおよびPXCCapture :: DeviceInfoを使用するメカニズムを提供します。これにより、開発者はデバイスのフレンドリ名、サポートされているモジュールなどの情報を受け取ることができます。



このチュートリアルでは、モジュールとデバイスの初期化とリストに必要なIntel RealSense SDKクラスを示します。



初期化



メインのIntel RealSense SDKハンドラーの初期化の例は、アプリケーションの任意の時点でPXCSessionの作成を可能にするために実装されています。



int main(int argc, char *argv[]) try { PXCSession *pSession; PXCSession::ImplDesc *pDesc; PXCCapture *pCapture; PXCSenseManager *pSenseManager; // Initialize pSession = PXCSession::CreateInstance(); pDesc = new PXCSession::ImplDesc(); pDesc->group = PXCSession::ImplGroup::IMPL_GROUP_SENSOR; pDesc->subgroup = PXCSession::ImplSubgroup::IMPL_SUBGROUP_VIDEO_CAPTURE;
      
      





リスティング



モジュールとデバイスの列挙は、 PXCSession :: ImplDescモジュールを順番に列挙し、明確な変更を取得することにより実行されます 。 次に、 PXCCapture :: DeviceInfoを列挙し、デバイスをポーリングします。 このようにして、システムに接続されているすべてのカメラのモジュールとデバイス機能をポーリングできます。



  // Enumerate Devices std::string temp; // iterating over the present modules for (int m = 0; ; m++) { PXCSession::ImplDesc desc2; if (pSession->QueryImpl(pDesc, m, &desc2) < pxcStatus::PXC_STATUS_NO_ERROR) { break; } //temp = format("Module[%d]: %d", m, desc2.friendlyName); wstring ws(desc2.friendlyName); string str(ws.begin(), ws.end()); std::cout << "Module[" << m << "]: " << str.c_str() << std::endl; PXCCapture *pCap; pSession->CreateImpl<PXCCapture>(&desc2, &pCap); // interating over the devices for (int d = 0; ; d++) { PXCCapture::DeviceInfo dinfo; if (pCap->QueryDeviceInfo(d, &dinfo) < pxcStatus::PXC_STATUS_NO_ERROR) { break; }; wstring ws(dinfo.name); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl; /*wstring ws(dinfo.orientation); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl; wstring ws(dinfo.model); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl;*/ } }
      
      





現在のモジュールを順番にソートするために必要な外側のループと、接続されているデバイスを反復処理する内側のループに注意してください。



おわりに



カメラの列挙は、システムに接続された複数のカメラから特定のカメラを選択する必要があるアプリケーションの操作における重要なステップです。 このチュートリアルでは、特定のカメラとその機能を特定した後、必要な選択ロジックをアプリケーションに統合したい開発者向けのシンプルなカメラ列挙スキームを提供します。 完全な使用例は、このチュートリアルの付録1に記載されています。



資源





付録1.サンプルソースコード
 #include <windows.h> #include <iostream> #include <string> #include <cstdio> // #include "pxcbase.h" #include "pxcsensemanager.h" #include "pxcmetadata.h" #include "service/pxcsessionservice.h" #include "pxccapture.h" #include "pxccapturemanager.h" using namespace std; int main(int argc, char *argv[]) try { PXCSession *pSession; PXCSession::ImplDesc *pDesc; PXCCapture *pCapture; PXCSenseManager *pSenseManager; // Initialize pSession = PXCSession::CreateInstance(); pDesc = new PXCSession::ImplDesc(); pDesc->group = PXCSession::ImplGroup::IMPL_GROUP_SENSOR; pDesc->subgroup = PXCSession::ImplSubgroup::IMPL_SUBGROUP_VIDEO_CAPTURE; // Enumerate Devices std::string temp; for (int m = 0; ; m++) { PXCSession::ImplDesc desc2; if (pSession->QueryImpl(pDesc, m, &desc2) < pxcStatus::PXC_STATUS_NO_ERROR) { break; } //temp = format("Module[%d]: %d", m, desc2.friendlyName); wstring ws(desc2.friendlyName); string str(ws.begin(), ws.end()); std::cout << "Module[" << m << "]: " << str.c_str() << std::endl; PXCCapture *pCap; pSession->CreateImpl<PXCCapture>(&desc2, &pCap); // print out all device information for (int d = 0; ; d++) { PXCCapture::DeviceInfo dinfo; if (pCap->QueryDeviceInfo(d, &dinfo) < pxcStatus::PXC_STATUS_NO_ERROR) { break; }; wstring ws(dinfo.name); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl; /*wstring ws(dinfo.orientation); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl; wstring ws(dinfo.model); string str(ws.begin(), ws.end()); std::cout << "Device[" << d << "]: " << str.c_str() << std::endl;*/ } } cin.clear(); cout << endl << "Press any key to continue..."; cin.ignore(); return 0; } catch (const char *c) { std::cerr << "Program aborted: " << c << "\n"; MessageBox(GetActiveWindow(), (LPCWSTR)c, L"FAIL", 0); } catch (std::exception e) { std::cerr << "Program aborted: " << e.what() << "\n"; MessageBox(GetActiveWindow(), (LPCWSTR)e.what(), L"FAIL", 0); }
      
      








All Articles