diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-08-29 03:15:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-08-29 03:54:17 +0200 |
commit | e2405afeae0adfa32bde63a182e5f605ac8e8f16 (patch) | |
tree | aa5f8ddcfd289cca521915a0487538e3cdf3f3b6 | |
parent | 48d1d1a06eb6acad0b0f436dcc73a19b408edb32 (diff) |
tracker/pt, video/opencv: allow mjpeg media type
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_dialog.cpp | 3 | ||||
-rw-r--r-- | tracker-pt/module/camera.cpp | 8 | ||||
-rw-r--r-- | tracker-pt/pt-api.hpp | 1 | ||||
-rw-r--r-- | tracker-pt/pt-settings.hpp | 1 | ||||
-rw-r--r-- | video-opencv/impl-camera.cpp | 5 | ||||
-rw-r--r-- | video/camera.hpp | 1 |
6 files changed, 15 insertions, 4 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index 32916cc5..0f056e82 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -10,8 +10,6 @@ #include "compat/math.hpp" #include "video/camera.hpp" -#include <opencv2/core.hpp> - #include <QString> #include <QtGlobal> #include <QDebug> @@ -39,6 +37,7 @@ TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : tie_setting(s.cam_res_x, ui.res_x_spin); tie_setting(s.cam_res_y, ui.res_y_spin); tie_setting(s.cam_fps, ui.fps_spin); + tie_setting(s.use_mjpeg, ui.use_mjpeg); tie_setting(s.threshold_slider, ui.threshold_slider); diff --git a/tracker-pt/module/camera.cpp b/tracker-pt/module/camera.cpp index 99bea617..62b23ea9 100644 --- a/tracker-pt/module/camera.cpp +++ b/tracker-pt/module/camera.cpp @@ -77,6 +77,7 @@ bool Camera::start(const pt_settings& s) { int fps = s.cam_fps, res_x = s.cam_res_x, res_y = s.cam_res_y; QString name = s.camera_name; + bool use_mjpeg = s.use_mjpeg; if (fps >= 0 && res_x >= 0 && res_y >= 0) { @@ -84,15 +85,17 @@ bool Camera::start(const pt_settings& s) (int)cam_desired.fps != fps || cam_desired.res_x != res_x || cam_desired.res_y != res_y || + cam_desired.use_mjpeg != use_mjpeg || !cap || !cap->is_open()) { stop(); cam_desired.name = name; - cam_desired.fps = fps; + cam_desired.fps = (f)fps; cam_desired.res_x = res_x; cam_desired.res_y = res_y; cam_desired.fov = fov; + cam_desired.use_mjpeg = use_mjpeg; cap = video::make_camera(name); @@ -103,12 +106,15 @@ bool Camera::start(const pt_settings& s) info.fps = fps; info.width = res_x; info.height = res_y; + info.use_mjpeg = use_mjpeg; if (!cap->start(info)) goto fail; cam_info = pt_camera_info(); cam_info.name = name; + cam_info.use_mjpeg = use_mjpeg; + cam_info.fov = (f)s.fov; dt_mean = 0; cv::Mat tmp; diff --git a/tracker-pt/pt-api.hpp b/tracker-pt/pt-api.hpp index 95152772..ded5ef57 100644 --- a/tracker-pt/pt-api.hpp +++ b/tracker-pt/pt-api.hpp @@ -32,6 +32,7 @@ struct pt_camera_info final int res_x = 0; int res_y = 0; QString name; + bool use_mjpeg = false; }; struct pt_pixel_pos_mixin diff --git a/tracker-pt/pt-settings.hpp b/tracker-pt/pt-settings.hpp index ed13a1ec..e2004ad7 100644 --- a/tracker-pt/pt-settings.hpp +++ b/tracker-pt/pt-settings.hpp @@ -64,6 +64,7 @@ struct pt_settings final : options::opts value<int> init_phase_timeout { b, "init-phase-timeout", 250 }; value<bool> auto_threshold { b, "automatic-threshold", true }; value<pt_color_type> blob_color { b, "blob-color", pt_color_natural }; + value<bool> use_mjpeg { b, "use-mjpeg", false }; value<slider_value> threshold_slider { b, "threshold-slider", { 128, 0, 255 } }; diff --git a/video-opencv/impl-camera.cpp b/video-opencv/impl-camera.cpp index 3f2a1b1a..7e357d7c 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 + video_capture_backend); + cap.emplace(idx, cv::CAP_DSHOW); if (args.width > 0 && args.height > 0) { @@ -43,6 +43,9 @@ bool cam::start(info& args) if (args.fps > 0) cap->set(cv::CAP_PROP_FPS, args.fps); + if (args.use_mjpeg) + cap->set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); + if (!cap->isOpened()) goto fail; diff --git a/video/camera.hpp b/video/camera.hpp index 189f95e1..c3297876 100644 --- a/video/camera.hpp +++ b/video/camera.hpp @@ -53,6 +53,7 @@ struct OTR_VIDEO_EXPORT camera double fx = 0, fy = 0; // focal length double P_x = 0, P_y = 0; // principal point double dist_c[8] {}; // distortion coefficients + bool use_mjpeg = false; }; camera(); |