diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2020-01-27 15:21:52 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2020-01-27 15:21:52 +0100 |
commit | 631c85c85f2e82bfdf7f6c58c5866f12ad0836a6 (patch) | |
tree | c216067fc5f09cdd79542c81e9a618734a43b994 /compat/camera-names.cpp | |
parent | 63a2c2bc5c592e28de4090be861d8e2c7e0062a0 (diff) |
video/opencv: store camera index
Issue: #1031
Diffstat (limited to 'compat/camera-names.cpp')
-rw-r--r-- | compat/camera-names.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
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<QString> get_camera_names() +std::vector<std::tuple<QString, int>> get_camera_names() { - std::vector<QString> ret; + std::vector<std::tuple<QString, int>> ret; #ifdef _WIN32 // Create the System Device Enumerator. HRESULT hr; @@ -70,7 +76,7 @@ std::vector<QString> 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<QString> 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<QCameraInfo> 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; |