summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-19 08:10:42 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-19 08:10:42 +0200
commit0b6289589656e957c070d46b65ef4e93707324f3 (patch)
tree0131cca6948035c1281a261fe8666013558e144d /tracker-pt
parent223ff7abf556d7af4b1aeb63a4dc1664fd9d6161 (diff)
tracker/pt: reduce locking
Diffstat (limited to 'tracker-pt')
-rw-r--r--tracker-pt/camera.cpp2
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp40
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h11
-rw-r--r--tracker-pt/point_extractor.cpp6
-rw-r--r--tracker-pt/point_extractor.h9
-rw-r--r--tracker-pt/point_tracker.cpp1
-rw-r--r--tracker-pt/point_tracker.h4
7 files changed, 46 insertions, 27 deletions
diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp
index 85a5a93b..beac9d24 100644
--- a/tracker-pt/camera.cpp
+++ b/tracker-pt/camera.cpp
@@ -112,7 +112,7 @@ void CVCamera::stop()
// give opencv time to exit camera threads, etc.
if (opened)
portable::sleep(500);
- qDebug() << "pt camera: assuming stopped";
+ qDebug() << "pt camera: stopped";
}
}
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index c58f3f6f..48dc19c5 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -20,10 +20,11 @@
//-----------------------------------------------------------------------------
Tracker_PT::Tracker_PT() :
- video_widget(NULL),
- video_frame(NULL),
- ever_success(false),
- commands(0)
+ video_widget(nullptr),
+ video_frame(nullptr),
+ point_count(0),
+ commands(0),
+ ever_success(false)
{
connect(s.b.get(), SIGNAL(saving()), this, SLOT(apply_settings()));
}
@@ -102,9 +103,11 @@ void Tracker_PT::run()
if (new_frame && !frame_.empty())
{
- const auto& points = point_extractor.extract_points(frame_);
+ point_extractor.extract_points(frame_, points);
+ point_count = points.size();
f fx;
+
if (!get_focal_length(fx))
continue;
@@ -116,8 +119,6 @@ void Tracker_PT::run()
ever_success = true;
}
- Affine X_CM = pose();
-
std::function<void(const vec2&, const cv::Scalar)> fun = [&](const vec2& p, const cv::Scalar color)
{
using std::round;
@@ -141,6 +142,12 @@ void Tracker_PT::run()
}
{
+ Affine X_CM;
+ {
+ QMutexLocker l(&data_mtx);
+ X_CM = point_tracker.pose();
+ }
+
Affine X_MH(mat33::eye(), vec3(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below
Affine X_GH = X_CM * X_MH;
vec3 p = X_GH.t; // head (center?) position in global space
@@ -236,6 +243,25 @@ void Tracker_PT::data(double *data)
}
}
+Affine Tracker_PT::pose()
+{
+ QMutexLocker l(&data_mtx);
+
+ return point_tracker.pose();
+}
+
+int Tracker_PT::get_n_points()
+{
+ return int(point_count);
+}
+
+bool Tracker_PT::get_cam_info(CamInfo* info)
+{
+ QMutexLocker lock(&camera_mtx);
+
+ return camera.get_info(*info);
+}
+
#include "ftnoir_tracker_pt_dialog.h"
OPENTRACK_DECLARE_TRACKER(Tracker_PT, TrackerDialog_PT, TrackerDll)
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index d2f69ac2..b5e11157 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -44,9 +44,9 @@ public:
void start_tracker(QFrame* parent_window) override;
void data(double* data) override;
- Affine pose() { return point_tracker.pose(); }
- int get_n_points() { return point_extractor.get_n_points(); }
- bool get_cam_info(CamInfo* info) { QMutexLocker lock(&camera_mtx); return camera.get_info(*info); }
+ Affine pose();
+ int get_n_points();
+ bool get_cam_info(CamInfo* info);
public slots:
void apply_settings();
protected:
@@ -63,6 +63,7 @@ private:
bool get_focal_length(f& ret);
QMutex camera_mtx;
+ QMutex data_mtx;
CVCamera camera;
PointExtractor point_extractor;
PointTracker point_tracker;
@@ -73,9 +74,11 @@ private:
settings_pt s;
Timer time;
cv::Mat frame;
+ std::vector<vec2> points;
- volatile bool ever_success;
+ volatile unsigned point_count;
volatile unsigned char commands;
+ volatile bool ever_success;
static constexpr f rad2deg = f(180/OPENTRACK_PI);
//static constexpr float deg2rad = float(OPENTRACK_PI/180);
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp
index 9dc1df6d..b12c139a 100644
--- a/tracker-pt/point_extractor.cpp
+++ b/tracker-pt/point_extractor.cpp
@@ -22,10 +22,9 @@
PointExtractor::PointExtractor()
{
blobs.reserve(max_blobs);
- points.reserve(max_blobs);
}
-const std::vector<PointExtractor::vec2>& PointExtractor::extract_points(cv::Mat& frame)
+void PointExtractor::extract_points(cv::Mat& frame, std::vector<PointExtractor::vec2>& points)
{
const int W = frame.cols;
const int H = frame.rows;
@@ -149,7 +148,7 @@ const std::vector<PointExtractor::vec2>& PointExtractor::extract_points(cv::Mat&
std::sort(blobs.begin(), blobs.end(), [](const blob& b1, const blob& b2) -> bool { return b2.radius < b1.radius; });
- QMutexLocker l(&mtx);
+ points.reserve(max_blobs);
points.clear();
for (auto& b : blobs)
@@ -157,5 +156,4 @@ const std::vector<PointExtractor::vec2>& PointExtractor::extract_points(cv::Mat&
vec2 p((b.pos[0] - W/2)/W, -(b.pos[1] - H/2)/W);
points.push_back(p);
}
- return points;
}
diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h
index 478418e6..f4839208 100644
--- a/tracker-pt/point_extractor.h
+++ b/tracker-pt/point_extractor.h
@@ -14,7 +14,6 @@
#include "ftnoir_tracker_pt_settings.h"
#include "opentrack-compat/pi-constant.hpp"
-#include <QMutex>
#include <vector>
@@ -24,23 +23,19 @@ public:
// extracts points from frame and draws some processing info into frame, if draw_output is set
// dt: time since last call in seconds
// WARNING: returned reference is valid as long as object
- const std::vector<vec2>& extract_points(cv::Mat &frame);
- int get_n_points() { QMutexLocker l(&mtx); return points.size(); }
+ void extract_points(cv::Mat &frame, std::vector<vec2>& points);
PointExtractor();
settings_pt s;
private:
static constexpr double pi = OPENTRACK_PI;
+ static constexpr int max_blobs = 16;
- std::vector<vec2> points;
- QMutex mtx;
cv::Mat frame_gray;
cv::Mat frame_bin;
cv::Mat hist;
cv::Mat frame_blobs;
- static constexpr int max_blobs = 16;
-
struct blob
{
double radius;
diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp
index 61c54fa4..adea578f 100644
--- a/tracker-pt/point_tracker.cpp
+++ b/tracker-pt/point_tracker.cpp
@@ -311,7 +311,6 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, f foc
if (nanp(t[i]))
return -1;
- QMutexLocker l(&mtx);
// apply results
X_CM.R = r;
X_CM.t[0] = t[0];
diff --git a/tracker-pt/point_tracker.h b/tracker-pt/point_tracker.h
index 559f7963..fab0e9ac 100644
--- a/tracker-pt/point_tracker.h
+++ b/tracker-pt/point_tracker.h
@@ -14,7 +14,6 @@
#include <memory>
#include <vector>
#include <QObject>
-#include <QMutex>
class Affine final : private pt_types
{
@@ -82,7 +81,7 @@ public:
// f : (focal length)/(sensor width)
// dt : time since last call
void track(const std::vector<vec2>& projected_points, const PointModel& model, f focal_length, bool dynamic_pose, int init_phase_timeout);
- Affine pose() { QMutexLocker l(&mtx); return X_CM; }
+ Affine pose() { return X_CM; }
vec2 project(const vec3& v_M, PointTracker::f focal_length);
private:
@@ -104,7 +103,6 @@ private:
Affine X_CM; // trafo from model to camera
Timer t;
- QMutex mtx;
bool init_phase;
};