diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-20 13:38:02 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-20 13:38:02 +0200 |
commit | b864a6932fbb1f35b0d6fb8e4835307b1d5a2299 (patch) | |
tree | 3f4a19e62ac30bdf4c8cefae4a72cd567af06a24 | |
parent | 931541b7d58f747e09c59450f666fb34985d0536 (diff) | |
parent | 0c1b4510b3f7a744cc4cad94e0d4dde45925269d (diff) |
Merge branch 'unstable' into trackhat-ui
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 4 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 3 | ||||
-rw-r--r-- | ftnoir_tracker_pt/camera.cpp | 20 | ||||
-rw-r--r-- | ftnoir_tracker_pt/camera.h | 17 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 29 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.h | 12 | ||||
-rw-r--r-- | ftnoir_tracker_pt/point_tracker.cpp | 6 | ||||
-rw-r--r-- | opentrack/selected-libraries.cpp | 4 | ||||
-rw-r--r-- | opentrack/selected-libraries.hpp | 1 | ||||
-rw-r--r-- | opentrack/sleep.hpp | 22 | ||||
-rw-r--r-- | opentrack/work.hpp | 2 |
11 files changed, 44 insertions, 76 deletions
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 786be62d..8acddc28 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -18,6 +18,7 @@ #include <opencv2/videoio.hpp> #include "opentrack/camera-names.hpp" #include "opentrack/opencv-calibration.hpp" +#include "opentrack/sleep.hpp" typedef struct { int width; @@ -355,6 +356,9 @@ fail: if (frame.rows > 0) videoWidget->update_image(frame); } + + // give opencv time to exit camera threads, etc. + portable::sleep(500); } void Tracker::data(double *data) diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index 2ac614a2..ad13d716 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -4,6 +4,7 @@ #include "opentrack/plugin-api.hpp" #include <cmath> #include "opentrack/camera-names.hpp" +#include "opentrack/sleep.hpp" typedef struct { int width; @@ -158,6 +159,8 @@ void Tracker::run() } } } + // give opencv time to exit camera threads, etc. + portable::sleep(500); } void Tracker::data(double* data) diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 2e745f2a..2989c1fe 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -8,26 +8,10 @@ #include "camera.h" #include <string> #include <QDebug> +#include "opentrack/sleep.hpp" using namespace cv; -#ifdef OPENTRACK_API -#else -// ---------------------------------------------------------------------------- -void get_camera_device_names(std::vector<std::string>& device_names) -{ - videoInput VI; - VI.listDevices(); - std::string device_name; - for(int index = 0; ; ++index) { - device_name = VI.getDeviceName(index); - if (device_name.empty()) break; - device_names.push_back(device_name); - } -} -#endif - -// ---------------------------------------------------------------------------- void Camera::set_device_index(int index) { if (desired_index != index) @@ -113,6 +97,8 @@ void CVCamera::stop() cap->release(); delete cap; cap = nullptr; + // give opencv time to exit camera threads, etc. + portable::sleep(500); } active = false; } diff --git a/ftnoir_tracker_pt/camera.h b/ftnoir_tracker_pt/camera.h index 2c42652a..343446ac 100644 --- a/ftnoir_tracker_pt/camera.h +++ b/ftnoir_tracker_pt/camera.h @@ -8,21 +8,10 @@ #pragma once #include <opencv2/core/core.hpp> -#ifndef OPENTRACK_API -# include <boost/shared_ptr.hpp> -#else -# include <memory> -# include <opencv2/highgui/highgui.hpp> -# include <opencv2/highgui/highgui_c.h> -#endif +#include <memory> +#include <opencv2/highgui.hpp> #include <string> -#ifndef OPENTRACK_API -// ---------------------------------------------------------------------------- -void get_camera_device_names(std::vector<std::string>& device_names); -#endif - -// ---------------------------------------------------------------------------- struct CamInfo { CamInfo() : res_x(0), res_y(0), fps(0) {} @@ -89,7 +78,7 @@ public: void start() override; void stop() override; - operator cv::VideoCapture&() { return *cap; } + operator cv::VideoCapture*() { return cap; } protected: bool _get_frame(cv::Mat* frame) override; diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 716fddfd..dbf9cca0 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -85,6 +85,8 @@ void Tracker_PT::run() if (!log_file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream log_stream(&log_file); #endif + + apply_settings(); while((commands & ABORT) == 0) { @@ -165,6 +167,7 @@ void Tracker_PT::apply_settings() { qDebug()<<"Tracker:: Applying settings"; QMutexLocker l(&camera_mtx); + camera.stop(); camera.set_device_index(camera_name_to_index("PS3Eye Camera")); int res_x, res_y, cam_fps; switch (s.camera_mode) @@ -194,6 +197,7 @@ void Tracker_PT::apply_settings() camera.set_res(res_x, res_y); camera.set_fps(cam_fps); + camera.start(); cv::Mat intrinsics_ = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat dist_coeffs_ = cv::Mat::zeros(5, 1, CV_32FC1); intrinsics = cv::Mat(); @@ -228,23 +232,10 @@ void Tracker_PT::start_tracker(QFrame *parent_window) video_layout->addWidget(video_widget); video_frame->setLayout(video_layout); video_widget->resize(video_frame->width(), video_frame->height()); - apply_settings(); - camera.start(); start(); } -#ifndef OPENTRACK_API -void Tracker::StopTracker(bool exit) -{ - set_command(PAUSE); -} -#endif - -#ifdef OPENTRACK_API -#define THeadPoseData double -#endif - -void Tracker_PT::data(THeadPoseData *data) +void Tracker_PT::data(double *data) { if (ever_success) { @@ -279,13 +270,3 @@ void Tracker_PT::data(THeadPoseData *data) data[TZ] = t[2] / 10.0; } } - -//----------------------------------------------------------------------------- -#ifdef OPENTRACK_API -#else -#pragma comment(linker, "/export:GetTracker=_GetTracker@0") -OPENTRACK_EXPORT ITrackerPtr __stdcall GetTracker() -{ - return new Tracker_PT; -} -#endif diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index aeda7dd7..97aa54aa 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -8,9 +8,7 @@ #ifndef FTNOIR_TRACKER_PT_H #define FTNOIR_TRACKER_PT_H -#ifdef OPENTRACK_API -# include "opentrack/plugin-api.hpp" -#endif +#include "opentrack/plugin-api.hpp" #include "ftnoir_tracker_pt_settings.h" #include "camera.h" #include "point_extractor.h" @@ -24,11 +22,7 @@ #include <QMutexLocker> #include <QTime> #include <atomic> -#ifndef OPENTRACK_API -# include <boost/shared_ptr.hpp> -#else -# include <memory> -#endif +#include <memory> #include <vector> class TrackerDialog_PT; @@ -48,7 +42,7 @@ public: Affine pose() { QMutexLocker lock(&mutex); return point_tracker.pose(); } int get_n_points() { QMutexLocker lock(&mutex); return point_extractor.get_points().size(); } - void get_cam_info(CamInfo* info) { QMutexLocker lock(&mutex); *info = camera.get_info(); } + void get_cam_info(CamInfo* info) { QMutexLocker lock(&camera_mtx); *info = camera.get_info(); } public slots: void apply_settings(); protected: diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index bae89dbe..f141fe36 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -33,12 +33,10 @@ static void set_row(Matx33f& m, int i, const Vec3f& v) m(i,2) = v[2]; } -#ifdef OPENTRACK_API static bool d_vals_sort(const pair<float,int> a, const pair<float,int> b) { return a.first < b.first; } -#endif void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[], cv::Vec2f d) const { @@ -50,11 +48,7 @@ void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[] std::sort(d_vals.begin(), d_vals.end(), -#ifdef OPENTRACK_API d_vals_sort -#else - comp -#endif ); for (unsigned i = 0; i<points.size(); ++i) diff --git a/opentrack/selected-libraries.cpp b/opentrack/selected-libraries.cpp index 630b7db2..e3bac0c5 100644 --- a/opentrack/selected-libraries.cpp +++ b/opentrack/selected-libraries.cpp @@ -1,10 +1,6 @@ #include "opentrack/selected-libraries.hpp" #include <QDebug> -SelectedLibraries::~SelectedLibraries() -{ -} - SelectedLibraries::SelectedLibraries(QFrame* frame, mem<ITracker> t, dylibptr p, mem<IFilter> f) : pTracker(nullptr), pFilter(nullptr), diff --git a/opentrack/selected-libraries.hpp b/opentrack/selected-libraries.hpp index 547f5f54..7779c231 100644 --- a/opentrack/selected-libraries.hpp +++ b/opentrack/selected-libraries.hpp @@ -18,6 +18,5 @@ struct SelectedLibraries { mem<IProtocol> pProtocol; SelectedLibraries(QFrame* frame, mem<ITracker> t, dylibptr p, mem<IFilter> f); SelectedLibraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {} - ~SelectedLibraries(); bool correct; }; diff --git a/opentrack/sleep.hpp b/opentrack/sleep.hpp new file mode 100644 index 00000000..27920842 --- /dev/null +++ b/opentrack/sleep.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace portable +{ +#ifdef _WIN32 + #include <windows.h> + + template<typename = void> + void sleep(unsigned milliseconds) + { + Sleep(milliseconds); + } +#else + #include <unistd.h> + + template<typename = void> + void sleep(unsigned milliseconds) + { + usleep(milliseconds * 1000U); // takes microseconds + } +#endif +} diff --git a/opentrack/work.hpp b/opentrack/work.hpp index 39eb12fb..5d1f6b54 100644 --- a/opentrack/work.hpp +++ b/opentrack/work.hpp @@ -20,7 +20,7 @@ struct Work { main_settings& s; - SelectedLibraries libs; + SelectedLibraries& libs; mem<Tracker> tracker; mem<Shortcuts> sc; WId handle; |