From 631c85c85f2e82bfdf7f6c58c5866f12ad0836a6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 27 Jan 2020 15:21:52 +0100 Subject: video/opencv: store camera index Issue: #1031 --- compat/camera-names.cpp | 23 ++++++++++++++--------- compat/camera-names.hpp | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'compat') diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp index 40edba49..8e777028 100644 --- a/compat/camera-names.cpp +++ b/compat/camera-names.cpp @@ -28,16 +28,22 @@ int camera_name_to_index(const QString &name) { auto list = get_camera_names(); - auto it = std::find(list.cbegin(), list.cend(), name); + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const auto& tuple) { + const auto& [str, idx] = tuple; + return str == name; + }); if (it != list.cend()) - return std::distance(list.cbegin(), it); + { + const auto& [ str, idx ] = *it; + return idx; + } return -1; } -std::vector get_camera_names() +std::vector> get_camera_names() { - std::vector ret; + std::vector> ret; #ifdef _WIN32 // Create the System Device Enumerator. HRESULT hr; @@ -70,7 +76,7 @@ std::vector get_camera_names() { // Display the name in your UI somehow. QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); - ret.push_back(str); + ret.push_back({ str, ret.size() }); } VariantClear(&var); pPropBag->Release(); @@ -101,16 +107,15 @@ std::vector get_camera_names() close(fd); continue; } - ret.push_back(QString((const char*)video_cap.card)); + ret.push_back({ QString((const char*)video_cap.card), i}); close(fd); } } #endif #ifdef __APPLE__ QList cameras = QCameraInfo::availableCameras(); - foreach (const QCameraInfo &cameraInfo, cameras) { - ret.push_back(cameraInfo.description()); - } + for (const QCameraInfo &cameraInfo : cameras) + ret.push_back({ cameraInfo.description(), ret.size() }); #endif return ret; diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp index bda15e81..3585edfe 100644 --- a/compat/camera-names.hpp +++ b/compat/camera-names.hpp @@ -10,9 +10,10 @@ #include #include +# include #include "export.hpp" -OTR_COMPAT_EXPORT std::vector get_camera_names(); +OTR_COMPAT_EXPORT std::vector> get_camera_names(); OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name); -- cgit v1.2.3