summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2021-09-27 16:51:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2021-09-27 16:51:16 +0200
commitcca0f96a0c8330a3c1f23c786129148de1073798 (patch)
tree03f48e11d40dfec3b1d22191389e45f6b32ceac2 /tracker-pt
parent60201f181eed06fed6112530c3283453a5e45688 (diff)
tracker/pt: remove useless image copies in video preview
Diffstat (limited to 'tracker-pt')
-rw-r--r--tracker-pt/module/frame.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/tracker-pt/module/frame.cpp b/tracker-pt/module/frame.cpp
index be966424..8549e5fd 100644
--- a/tracker-pt/module/frame.cpp
+++ b/tracker-pt/module/frame.cpp
@@ -8,30 +8,33 @@ namespace pt_module {
void Preview::set_last_frame(const pt_frame& frame_)
{
- const cv::Mat& frame2 = frame_.as_const<const Frame>()->mat;
- const cv::Mat* frame;
+ const cv::Mat& frame = frame_.as_const<const Frame>()->mat;
+ const bool need_resize = frame.size != frame_copy.size;
- if (frame2.channels() == 1)
+ if (frame.channels() == 1)
{
- frame_tmp.create(frame2.rows, frame2.cols, CV_8UC3);
- cv::cvtColor(frame2, frame_tmp, cv::COLOR_GRAY2BGR);
- frame = &frame_tmp;
+ if (need_resize)
+ {
+ frame_tmp.create(frame.size(), CV_8UC3);
+ cv::cvtColor(frame, frame_tmp, cv::COLOR_GRAY2BGR);
+ cv::resize(frame_tmp, frame_copy, frame_copy.size(), 0, 0, cv::INTER_NEAREST);
+ }
+ else
+ cv::cvtColor(frame, frame_copy, cv::COLOR_GRAY2BGR);
}
- else
- frame = &frame2;
-
- if (frame->channels() != 3)
+ else if (frame.channels() == 3)
{
- eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame->channels());
- frame_copy.create(cv::Size{frame_out.rows, frame_out.cols}, CV_8UC3);
- frame_copy.setTo(cv::Scalar{0, 0, 0});
+ if (need_resize)
+ cv::resize(frame, frame_copy, frame_copy.size(), 0, 0, cv::INTER_NEAREST);
+ else
+ frame.copyTo(frame_copy);
}
-
- 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_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST);
else
- frame->copyTo(frame_copy);
+ {
+ eval_once(qDebug() << "tracker/pt: camera frame depth" << frame.channels() << "!= 3");
+ frame_copy.create(frame_copy.size(), CV_8UC3);
+ frame_copy.setTo({0});
+ }
}
Preview::Preview(int w, int h)