summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-16 08:59:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-16 08:59:21 +0100
commit6cf93c06abad63721bf66f695587a98377b6178d (patch)
treeaf029c638c9a62d6c34bc95a4dc3060c5d2f8921 /tracker-pt
parent88849a1ca4b7c253f7427d361443a496c1b5fe28 (diff)
cv/video-frame, tracker/pt: add hidpi preview support
Diffstat (limited to 'tracker-pt')
-rw-r--r--tracker-pt/frame.cpp8
-rw-r--r--tracker-pt/frame.hpp2
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp25
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h12
-rw-r--r--tracker-pt/module.cpp4
-rw-r--r--tracker-pt/point_extractor.cpp12
6 files changed, 38 insertions, 25 deletions
diff --git a/tracker-pt/frame.cpp b/tracker-pt/frame.cpp
index ca72bd16..79cf62fc 100644
--- a/tracker-pt/frame.cpp
+++ b/tracker-pt/frame.cpp
@@ -12,8 +12,7 @@ using namespace pt_module;
Preview& Preview::operator=(const pt_frame& frame_)
{
const cv::Mat& frame = frame_.as_const<const Frame>()->mat;
- const int w = frame.cols, h = frame.rows;
- ensure_size(frame_copy, w, h, CV_8UC3);
+ ensure_size(frame_copy, frame_out.cols, frame_out.rows, CV_8UC3);
if (frame.channels() != 3)
{
@@ -21,9 +20,9 @@ Preview& Preview::operator=(const pt_frame& frame_)
return *this;
}
- const bool need_resize = w != frame_out.cols || h != frame_out.rows;
+ const bool need_resize = frame.cols != frame_out.cols || frame.rows != frame_out.rows;
if (need_resize)
- cv::resize(frame, frame_copy, cv::Size(frame_resize.cols, frame_resize.rows), 0, 0, cv::INTER_NEAREST);
+ cv::resize(frame, frame_copy, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST);
else
frame.copyTo(frame_copy);
@@ -32,7 +31,6 @@ Preview& Preview::operator=(const pt_frame& frame_)
Preview::Preview(int w, int h)
{
- ensure_size(frame_resize, w, h, CV_8UC4);
ensure_size(frame_out, w, h, CV_8UC4);
frame_out.setTo(cv::Scalar(0, 0, 0, 0));
diff --git a/tracker-pt/frame.hpp b/tracker-pt/frame.hpp
index f8c33ebe..9e4f809a 100644
--- a/tracker-pt/frame.hpp
+++ b/tracker-pt/frame.hpp
@@ -30,7 +30,7 @@ private:
static void ensure_size(cv::Mat& frame, int w, int h, int type);
bool fresh = true;
- cv::Mat frame_copy, frame_color, frame_resize, frame_out;
+ cv::Mat frame_copy, frame_color, frame_out;
};
} // ns pt_module
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 467334de..05959066 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -23,14 +23,13 @@
using namespace types;
-static constexpr inline int preview_width = 320, preview_height = 240;
-
-Tracker_PT::Tracker_PT(const pt_runtime_traits& traits) :
- s { traits.get_module_name() },
- point_extractor { traits.make_point_extractor() },
- camera { traits.make_camera() },
- frame { traits.make_frame() },
- preview_frame { traits.make_preview(preview_width, preview_height) }
+Tracker_PT::Tracker_PT(pointer<pt_runtime_traits> traits) :
+ traits { traits },
+ s { traits->get_module_name() },
+ point_extractor { traits->make_point_extractor() },
+ camera { traits->make_camera() },
+ frame { traits->make_frame() },
+ preview_frame { traits->make_preview(preview_width, preview_height) }
{
cv::setBreakOnError(true);
@@ -106,6 +105,16 @@ void Tracker_PT::run()
}
video_widget->update_image(preview_frame->get_bitmap());
+
+ {
+ int w = -1, h = -1;
+ video_widget->get_preview_size(w, h);
+ if (w != preview_width || h != preview_height)
+ {
+ preview_width = w, preview_height = h;
+ preview_frame = traits->make_preview(w, h);
+ }
+ }
}
}
qDebug() << "pt: thread stopped";
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index c9c15bc7..0b2a8578 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -40,8 +40,11 @@ class Tracker_PT : public QThread, public ITracker
friend class ::TrackerDialog_PT;
+ template<typename t>
+ using pointer = typename pt_runtime_traits::pointer<t>;
+
public:
- Tracker_PT(const pt_runtime_traits& pt_runtime_traits);
+ Tracker_PT(pointer<pt_runtime_traits> pt_runtime_traits);
~Tracker_PT() override;
module_status start_tracker(QFrame* parent_window) override;
void data(double* data) override;
@@ -56,12 +59,11 @@ public slots:
protected:
void run() override;
private:
+ pointer<pt_runtime_traits> traits;
+
QMutex camera_mtx;
QMutex data_mtx;
- template<typename t>
- using pointer = typename pt_runtime_traits::pointer<t>;
-
PointTracker point_tracker;
pt_settings s;
@@ -69,6 +71,8 @@ private:
std::unique_ptr<QLayout> layout;
std::vector<vec2> points;
+ int preview_width = 320, preview_height = 240;
+
pointer<pt_point_extractor> point_extractor;
pointer<pt_camera> camera;
pointer<cv_video_widget> video_widget;
diff --git a/tracker-pt/module.cpp b/tracker-pt/module.cpp
index c73b771e..5c298ca5 100644
--- a/tracker-pt/module.cpp
+++ b/tracker-pt/module.cpp
@@ -44,7 +44,7 @@ struct pt_module_traits final : pt_runtime_traits
struct tracker_pt : Tracker_PT
{
- tracker_pt() : Tracker_PT(pt_module_traits())
+ tracker_pt() : Tracker_PT(pointer<pt_runtime_traits>(new pt_module_traits))
{
}
};
@@ -64,8 +64,6 @@ class metadata_pt : public Metadata
using namespace pt_module;
-
-
dialog_pt::dialog_pt() : TrackerDialog_PT(module_name) {}
OPENTRACK_DECLARE_TRACKER(tracker_pt, dialog_pt, metadata_pt)
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp
index 0904d9cb..defdcedc 100644
--- a/tracker-pt/point_extractor.cpp
+++ b/tracker-pt/point_extractor.cpp
@@ -323,7 +323,9 @@ end:
{
blob& b = blobs[k];
- static const f offx = 10, offy = 7.5;
+ const f dpi = preview_frame.cols / f(320);
+ const f offx = 10 * dpi, offy = 7.5 * dpi;
+
const f cx = preview_frame.cols / f(frame.cols),
cy = preview_frame.rows / f(frame.rows),
c_ = (cx+cy)/2;
@@ -337,7 +339,9 @@ end:
? cv::Scalar(192, 192, 192)
: cv::Scalar(255, 255, 0);
- cv::circle(preview_frame, p, iround((b.radius + 3.3) * c_ * c_fract), circle_color, 1, cv::LINE_AA, fract_bits);
+ const f overlay_size = dpi > 1.5 ? 2 : 1;
+
+ cv::circle(preview_frame, p, iround((b.radius + 3.3) * c_ * c_fract), circle_color, overlay_size, cv::LINE_AA, fract_bits);
char buf[16];
buf[sizeof(buf)-1] = '\0';
@@ -349,8 +353,8 @@ end:
cv::Point pos(iround(b.pos[0]*cx+offx), iround(b.pos[1]*cy+offy));
cv::putText(preview_frame, buf, pos,
- cv::FONT_HERSHEY_PLAIN,
- 1, text_color, 1);
+ cv::FONT_HERSHEY_PLAIN, overlay_size, text_color,
+ 1);
}
// End of mean shift code. At this point, blob positions are updated with hopefully less noisy less biased values.