diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-03-18 15:20:09 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-03-18 15:20:09 +0100 |
commit | 5023b54ba76325bb0b5598d59714bdad2d55d81e (patch) | |
tree | 15cc639eff7dbfa12eeccaa52d7fd251f18969e6 /tracker-aruco | |
parent | 3aababf6fd53a7b0312c2c1492bab6b43584b613 (diff) |
video: add support for camera modules
Issue: #910
Diffstat (limited to 'tracker-aruco')
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.cpp | 43 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.h | 4 |
2 files changed, 31 insertions, 16 deletions
diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index 8928566f..d9674755 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -6,8 +6,6 @@ */ #include "ftnoir_tracker_aruco.h" -#include "cv/video-property-page.hpp" -#include "compat/camera-names.hpp" #include "compat/sleep.hpp" #include "compat/math-imports.hpp" @@ -75,7 +73,6 @@ aruco_tracker::~aruco_tracker() wait(); // fast start/stop causes breakage portable::sleep(1000); - camera.release(); } module_status aruco_tracker::start_tracker(QFrame* videoframe) @@ -166,16 +163,18 @@ bool aruco_tracker::open_camera() QMutexLocker l(&camera_mtx); - camera = cv::VideoCapture(camera_name_to_index(s.camera_name)); + camera = video::make_camera(s.camera_name); + video::impl::camera::info args {}; + if (res.width) { - camera.set(cv::CAP_PROP_FRAME_WIDTH, res.width); - camera.set(cv::CAP_PROP_FRAME_HEIGHT, res.height); + args.width = res.width; + args.height = res.height; } if (fps) - camera.set(cv::CAP_PROP_FPS, fps); + args.fps = fps; - if (!camera.isOpened()) + if (!camera->start(args)) { qDebug() << "aruco tracker: can't open camera"; return false; @@ -372,14 +371,28 @@ void aruco_tracker::run() { QMutexLocker l(&camera_mtx); - if (!camera.read(color)) + auto [ img, res ] = camera->get_frame(); + + if (!res) { portable::sleep(100); continue; } - } - cv::cvtColor(color, grayscale, cv::COLOR_BGR2GRAY); + color = cv::Mat(img.height, img.width, CV_8UC(img.channels), (void*)img.data, img.stride); + + switch (img.channels) + { + case 1: + grayscale.setTo(color); break; + case 3: + cv::cvtColor(color, grayscale, cv::COLOR_BGR2GRAY); + break; + default: + qDebug() << "aruco: can't handle" << img.channels << "color channels"; + return; + } + } #ifdef DEBUG_UNSHARP_MASKING { @@ -496,7 +509,9 @@ aruco_dialog::aruco_dialog() : tracker = nullptr; calib_timer.setInterval(100); - ui.cameraName->addItems(get_camera_names()); + + for (const auto& str : video::camera_names()) + ui.cameraName->addItem(str); tie_setting(s.camera_name, ui.cameraName); tie_setting(s.resolution, ui.resolution); @@ -572,10 +587,10 @@ void aruco_dialog::camera_settings() if (tracker) { QMutexLocker l(&tracker->camera_mtx); - video_property_page::show_from_capture(tracker->camera, camera_name_to_index(s.camera_name)); + (void)tracker->camera->show_dialog(); } else - video_property_page::show(camera_name_to_index(s.camera_name)); + (void)video::show_dialog(s.camera_name); } void aruco_dialog::update_camera_settings_state(const QString& name) diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index 1d6fd107..0a33f02b 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -13,6 +13,7 @@ #include "api/plugin-api.hpp" #include "cv/video-widget.hpp" #include "compat/timer.hpp" +#include "video/camera.hpp" #include "aruco/markerdetector.h" @@ -27,7 +28,6 @@ #include <cinttypes> #include <opencv2/core.hpp> -#include <opencv2/videoio.hpp> // value 0->1 //#define DEBUG_UNSHARP_MASKING .75 @@ -77,7 +77,7 @@ public: void getRT(cv::Matx33d &r, cv::Vec3d &t); QMutex camera_mtx; - cv::VideoCapture camera; + std::unique_ptr<video::impl::camera> camera; private: bool detect_with_roi(); |