summaryrefslogtreecommitdiffhomepage
path: root/video-opencv
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-04-29 16:02:13 +0200
committerStanislaw Halik <sthalik@misaki.pl>2019-04-29 16:02:13 +0200
commitf8e54403c3c30bf87491d310afd827a2d7cb7f16 (patch)
treeb5bf10614b2e4a4539ac0e33e54e6a9525806623 /video-opencv
parent9da1695192518c8f2ca7692fa45e4acbdf4dc2b7 (diff)
video/opencv: fix crash with obscure backends
Issue: #726
Diffstat (limited to 'video-opencv')
-rw-r--r--video-opencv/impl-camera.cpp2
-rw-r--r--video-opencv/impl.hpp9
-rw-r--r--video-opencv/video-property-page.cpp5
3 files changed, 14 insertions, 2 deletions
diff --git a/video-opencv/impl-camera.cpp b/video-opencv/impl-camera.cpp
index 8a540134..3f2a1b1a 100644
--- a/video-opencv/impl-camera.cpp
+++ b/video-opencv/impl-camera.cpp
@@ -33,7 +33,7 @@ bool cam::is_open()
bool cam::start(info& args)
{
stop();
- cap.emplace(idx);
+ cap.emplace(idx + video_capture_backend);
if (args.width > 0 && args.height > 0)
{
diff --git a/video-opencv/impl.hpp b/video-opencv/impl.hpp
index 3d793490..db569823 100644
--- a/video-opencv/impl.hpp
+++ b/video-opencv/impl.hpp
@@ -31,6 +31,15 @@ struct metadata : camera_
struct cam final : camera
{
+static constexpr int video_capture_backend =
+#ifdef _WIN32
+ cv::CAP_DSHOW;
+#elif !defined __APPLE__
+ cv::CAP_V4L2;
+#else
+ cv::CAP_ANY;
+#endif
+
cam(int idx);
~cam() override;
diff --git a/video-opencv/video-property-page.cpp b/video-opencv/video-property-page.cpp
index a43a5ba0..078898a5 100644
--- a/video-opencv/video-property-page.cpp
+++ b/video-opencv/video-property-page.cpp
@@ -14,6 +14,7 @@
#include "compat/run-in-thread.hpp"
#include "compat/library-path.hpp"
#include "compat/thread-name.hpp"
+#include "impl.hpp"
#include <cstring>
@@ -49,6 +50,7 @@ prop_settings_worker::prop_settings_worker(int idx_)
int ret = (int)cap.get(cv::CAP_PROP_SETTINGS);
if (ret != 0)
+ {
run_in_thread_async(qApp, [] {
QMessageBox::warning(nullptr,
"Camera properties",
@@ -56,6 +58,7 @@ prop_settings_worker::prop_settings_worker(int idx_)
QMessageBox::Cancel,
QMessageBox::NoButton);
});
+ }
else
{
idx = idx_;
@@ -67,7 +70,7 @@ prop_settings_worker::prop_settings_worker(int idx_)
void prop_settings_worker::open_prop_page()
{
- cap.open(idx);
+ cap.open(idx + opencv_camera_impl::cam::video_capture_backend);
if (cap.isOpened())
{