📜 ⬆️ ⬇️

Tutorial: listing modules and cameras

The listing of functional modules and several cameras is an important component of the application logic for selecting the desired device. This tutorial describes the method for enumerating modules and multiple devices so that you can select the one you want.



Detection of cameras connected to the system, and identification of the capabilities of these cameras can be simplified by enumerating devices. The Intel RealSense SDK 2016 R1 provides a mechanism using PXCSession :: ImplDesc and PXCCapture :: DeviceInfo , which allows developers to obtain information such as the friendly name of the device, supported modules, etc.

This tutorial shows the Intel RealSense SDK classes needed to initialize and then list modules and devices.
')

Initialization


An example of initialization of the main Intel RealSense SDK handlers is implemented to enable the creation of PXCSession at any time during the operation of the application.

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; 

Enumeration


The enumeration of modules and devices is carried out by sequentially iterating through the modules of PXCSession :: ImplDesc and obtaining understandable changes. It then iterates through PXCCapture :: DeviceInfo and polls the device. In this way, you can interrogate the modules and device capabilities for all cameras connected to the system.

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

Pay attention to the external loop, necessary for sequential iteration of the current module, and the internal loop, which serves to iterate through the connected devices.

Conclusion


Enumeration of cameras is an important stage in the operation of any application, in which you may need to select a specific camera from several connected to the system. This tutorial presents a simple scheme for listing cameras for developers who want to embed the necessary selection logic into their application after identifying a specific camera and its capabilities. A full usage example is provided in Appendix 1 of this tutorial.

Resources



Appendix 1. Sample Source Code
 #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); } 

Source: https://habr.com/ru/post/313290/


All Articles