summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2021-09-27 12:27:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2021-09-27 12:28:20 +0200
commit4596d0bf8d8659411ea9dbc380336ad01c366f7b (patch)
tree3e9c5527678dce72c2145a59d46113d3d089e5ad
parentdeff5fda016a18fd1d5a8a2b6c0611245757aaff (diff)
cv, tracker/pt: use cv::Mat::create()
-rw-r--r--cv/video-widget.cpp14
-rw-r--r--tracker-pt/module/frame.cpp15
-rw-r--r--tracker-pt/module/frame.hpp2
-rw-r--r--tracker-pt/module/point_extractor.cpp14
4 files changed, 12 insertions, 33 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp
index 289b9cee..ea5e13ac 100644
--- a/cv/video-widget.cpp
+++ b/cv/video-widget.cpp
@@ -13,15 +13,8 @@ void cv_video_widget::update_image(const cv::Mat& frame)
return;
cv::Mat const* __restrict scaled = nullptr;
-
- if (frame3.cols != W || frame3.rows != H)
- {
- frame3 = cv::Mat(H, W, frame.type());
- frame2 = cv::Mat(H, W, CV_8UC4);
-
- if (!frame2.isContinuous() || !frame3.isContinuous())
- std::abort();
- }
+ frame3.create(H, W, frame.type());
+ frame2.create(H, W, CV_8UC4);
if (frame.cols != W || frame.rows != H)
{
@@ -37,7 +30,6 @@ void cv_video_widget::update_image(const cv::Mat& frame)
scaled = &frame;
int color_cvt = cv::COLOR_COLORCVT_MAX;
- constexpr int nchannels = 4;
switch (scaled->channels())
{
@@ -47,7 +39,7 @@ void cv_video_widget::update_image(const cv::Mat& frame)
case 3:
color_cvt = cv::COLOR_BGR2BGRA;
break;
- case nchannels:
+ case 4:
break;
default:
unreachable();
diff --git a/tracker-pt/module/frame.cpp b/tracker-pt/module/frame.cpp
index b1690aa1..09d469f2 100644
--- a/tracker-pt/module/frame.cpp
+++ b/tracker-pt/module/frame.cpp
@@ -36,15 +36,14 @@ void Preview::set_last_frame(const pt_frame& frame_)
Preview::Preview(int w, int h)
{
- ensure_size(frame_out, w, h, CV_8UC4);
- ensure_size(frame_copy, w, h, CV_8UC3);
-
- frame_copy.setTo(cv::Scalar(0, 0, 0));
+ frame_out.create(w, h, CV_8UC4);
+ frame_copy.create(w, h, CV_8UC3);
+ frame_copy.setTo({0});
}
QImage Preview::get_bitmap()
{
- int stride = frame_out.step.p[0];
+ int stride = (int)frame_out.step.p[0];
if (stride < 64 || stride < frame_out.cols * 4)
{
@@ -80,10 +79,4 @@ void Preview::draw_head_center(f x, f y)
color, 1);
}
-void Preview::ensure_size(cv::Mat& frame, int w, int h, int type)
-{
- if (frame.cols != w || frame.rows != h || frame.type() != type)
- frame = cv::Mat(h, w, type);
-}
-
} // ns pt_module
diff --git a/tracker-pt/module/frame.hpp b/tracker-pt/module/frame.hpp
index 1e7c82b6..239a3474 100644
--- a/tracker-pt/module/frame.hpp
+++ b/tracker-pt/module/frame.hpp
@@ -32,8 +32,6 @@ struct Preview final : pt_preview
operator cv::Mat const&() const { return frame_copy; }
private:
- static void ensure_size(cv::Mat& frame, int w, int h, int type);
-
cv::Mat frame_copy, frame_out, frame_tmp;
};
diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp
index d8a23fcf..9814d974 100644
--- a/tracker-pt/module/point_extractor.cpp
+++ b/tracker-pt/module/point_extractor.cpp
@@ -87,21 +87,17 @@ PointExtractor::PointExtractor(const QString& module_name) : s(module_name)
void PointExtractor::ensure_channel_buffers(const cv::Mat& orig_frame)
{
- if (ch[0].rows != orig_frame.rows || ch[0].cols != orig_frame.cols)
- for (cv::Mat1b& x : ch)
- x = cv::Mat1b(orig_frame.rows, orig_frame.cols);
+ for (cv::Mat1b& x : ch)
+ x.create(orig_frame.rows, orig_frame.cols);
}
void PointExtractor::ensure_buffers(const cv::Mat& frame)
{
const int W = frame.cols, H = frame.rows;
- if (frame_gray.rows != W || frame_gray.cols != H)
- {
- frame_gray = cv::Mat1b(H, W);
- frame_bin = cv::Mat1b(H, W);
- frame_gray_unmasked = cv::Mat1b(H, W);
- }
+ frame_gray.create(H, W);
+ frame_bin.create(H, W);
+ frame_gray_unmasked.create(H, W);
}
void PointExtractor::extract_single_channel(const cv::Mat& orig_frame, int idx, cv::Mat1b& dest)