summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:12:57 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-02-21 20:12:57 +0100
commit28a5f315b368f8ac0bcb49e452fb44de821f22eb (patch)
tree75569efb281d94cb7c95a42610ee2498d3471f98
parentb2cbf1b156f20ebb72bd0ff93d041f0bcb8a4ccf (diff)
tracker/pt: resize the camera feed, not the preview
This makes the point size text and point crosses not alias due to the resize. Due to nice pixel coordinate system, the cross-drawing lambda only needs minimal changes.
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp38
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h5
-rw-r--r--tracker-pt/point_extractor.cpp21
-rw-r--r--tracker-pt/point_extractor.h2
4 files changed, 30 insertions, 36 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 08bf56c6..d196b2ee 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -58,7 +58,6 @@ void Tracker_PT::run()
#endif
apply_settings();
- cv::Mat frame_;
while((commands & ABORT) == 0)
{
@@ -70,17 +69,13 @@ void Tracker_PT::run()
{
QMutexLocker l(&camera_mtx);
new_frame = camera.get_frame(dt, frame, cam_info);
- if (new_frame)
- {
- if (frame.rows != frame_.rows || frame.cols != frame_.cols)
- frame_ = cv::Mat(frame.rows, frame.cols, CV_8UC3);
- }
- frame.copyTo(frame_);
}
- if (new_frame && !frame_.empty())
+ cv::resize(frame, preview_frame, cv::Size(preview_size.width(), preview_size.height()), 0, 0, cv::INTER_NEAREST);
+
+ if (new_frame && !frame.empty())
{
- point_extractor.extract_points(frame_, points);
+ point_extractor.extract_points(frame, preview_frame, points);
point_count = points.size();
f fx;
@@ -99,26 +94,20 @@ void Tracker_PT::run()
auto fun = [&](const vec2& p, const cv::Scalar& color)
{
- using std::round;
- using std::sqrt;
- using std::max;
-
- static constexpr int frame_size = 400;
- const double size = max(1., 1.5*sqrt(frame.rows*frame.rows + frame.cols*frame.cols) / frame_size);
- const int len = std::max(1, iround(size * 7.5));
+ static constexpr f len = 9;
- cv::Point p2(int(round(p[0] * frame_.cols + frame_.cols/2)),
- int(round(-p[1] * frame_.cols + frame_.rows/2)));
- cv::line(frame_,
+ cv::Point p2(iround(p[0] * preview_frame.cols + preview_frame.cols/2),
+ iround(-p[1] * preview_frame.cols + preview_frame.rows/2));
+ cv::line(preview_frame,
cv::Point(p2.x - len, p2.y),
cv::Point(p2.x + len, p2.y),
color,
- iround(size/2));
- cv::line(frame_,
+ 1);
+ cv::line(preview_frame,
cv::Point(p2.x, p2.y - len),
cv::Point(p2.x, p2.y + len),
color,
- iround(size/2));
+ 1);
};
for (unsigned i = 0; i < points.size(); i++)
@@ -140,7 +129,7 @@ void Tracker_PT::run()
fun(p_, cv::Scalar(0, 0, 255));
}
- video_widget->update_image(frame_);
+ video_widget->update_image(preview_frame);
}
}
qDebug() << "pt: thread stopped";
@@ -166,12 +155,13 @@ void Tracker_PT::apply_settings()
void Tracker_PT::start_tracker(QFrame* video_frame)
{
video_frame->setAttribute(Qt::WA_NativeWindow);
+ preview_size = video_frame->size();
video_widget = qptr<cv_video_widget>(video_frame);
layout = qptr<QHBoxLayout>(video_frame);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(video_widget.data());
video_frame->setLayout(layout.data());
- video_widget->resize(video_frame->width(), video_frame->height());
+ //video_widget->resize(video_frame->width(), video_frame->height());
video_frame->show();
start();
}
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index fcf74bff..e050f4ad 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -26,6 +26,7 @@
#include <QMutexLocker>
#include <QTime>
#include <QLayout>
+#include <QSize>
#include <atomic>
#include <memory>
#include <vector>
@@ -74,9 +75,11 @@ private:
settings_pt s;
Timer time;
- cv::Mat frame;
+ cv::Mat frame, preview_frame;
std::vector<vec2> points;
+ QSize preview_size;
+
volatile unsigned point_count;
volatile unsigned char commands;
volatile bool ever_success;
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp
index f7f63784..3109db09 100644
--- a/tracker-pt/point_extractor.cpp
+++ b/tracker-pt/point_extractor.cpp
@@ -76,7 +76,7 @@ PointExtractor::PointExtractor()
blobs.reserve(max_blobs);
}
-void PointExtractor::extract_points(cv::Mat& frame, std::vector<vec2>& points)
+void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame, std::vector<vec2>& points)
{
using std::sqrt;
using std::max;
@@ -193,19 +193,19 @@ void PointExtractor::extract_points(cv::Mat& frame, std::vector<vec2>& points)
blob b(radius, cv::Vec2d(m10 / N, m01 / N), N/sqrt(double(cnt)), rect);
blobs.push_back(b);
- static constexpr int frame_size = 400;
- const double size = std::max(1, iround(std::sqrt(frame.rows*frame.rows + frame.cols*frame.cols) / frame_size));
-
{
char buf[64];
sprintf(buf, "%.2fpx", radius);
- cv::putText(frame,
+ static const vec2 off(10, 7.5);
+ const f cx = preview_frame.cols / f(frame.cols),
+ cy = preview_frame.rows / f(frame.rows);
+ cv::putText(preview_frame,
buf,
- cv::Point((int)round(b.pos[0]+15*size), (int)round(b.pos[1]+10*size)),
+ cv::Point(iround(b.pos[0]*cx+off[0]), iround(b.pos[1]*cy+off[1])),
cv::FONT_HERSHEY_PLAIN,
- size,
+ 1,
cv::Scalar(0, 0, 255),
- iround(size));
+ 1);
}
if (idx >= max_blobs) goto end;
@@ -251,7 +251,7 @@ end:
points.reserve(max_blobs);
points.clear();
- for (auto& b : blobs)
+ for (const auto& b : blobs)
{
// note: H/W is equal to fx/fy
@@ -260,7 +260,8 @@ end:
}
}
-PointExtractor::blob::blob(double radius, const cv::Vec2d& pos, double brightness, cv::Rect& rect) : radius(radius), brightness(brightness), pos(pos), rect(rect)
+PointExtractor::blob::blob(double radius, const cv::Vec2d& pos, double brightness, cv::Rect& rect) :
+ radius(radius), brightness(brightness), pos(pos), rect(rect)
{
//qDebug() << "radius" << radius << "pos" << pos[0] << pos[1];
}
diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h
index 3ad8ed52..ad02d7f8 100644
--- a/tracker-pt/point_extractor.h
+++ b/tracker-pt/point_extractor.h
@@ -27,7 +27,7 @@ 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
- void extract_points(cv::Mat &frame, std::vector<vec2>& points);
+ void extract_points(const cv::Mat& frame, cv::Mat& preview_frame, std::vector<vec2>& points);
PointExtractor();
settings_pt s;