diff options
Diffstat (limited to 'tracker-pt/module')
-rw-r--r-- | tracker-pt/module/frame.cpp | 25 | ||||
-rw-r--r-- | tracker-pt/module/frame.hpp | 2 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.cpp | 7 |
3 files changed, 27 insertions, 7 deletions
diff --git a/tracker-pt/module/frame.cpp b/tracker-pt/module/frame.cpp index ab110871..9247212b 100644 --- a/tracker-pt/module/frame.cpp +++ b/tracker-pt/module/frame.cpp @@ -8,19 +8,32 @@ namespace pt_module { Preview& Preview::operator=(const pt_frame& frame_) { - const cv::Mat& frame = frame_.as_const<const Frame>()->mat; + const cv::Mat& frame2 = frame_.as_const<const Frame>()->mat; + const cv::Mat* frame; - if (frame.channels() != 3) + if (frame2.channels() == 1) { - eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); + frame_tmp.create(frame2.rows, frame2.cols, CV_8UC3); + const cv::Mat channels[] = { frame2, frame2, frame2 }; + cv::merge(channels, std::size(channels), frame_tmp); + frame = &frame_tmp; + } + else + frame = &frame2; + + if (frame->channels() != 3) + { + eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame->channels()); + frame_copy.create(cv::Size{frame_out.cols, frame_out.rows}, CV_8UC3); + frame_copy.setTo({0}); return *this; } - const bool need_resize = frame.cols != frame_out.cols || frame.rows != frame_out.rows; + const bool need_resize = frame2.cols != frame_out.cols || frame2.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); + cv::resize(frame2, frame_copy, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST); else - frame.copyTo(frame_copy); + frame->copyTo(frame_copy); return *this; } diff --git a/tracker-pt/module/frame.hpp b/tracker-pt/module/frame.hpp index 89334599..ae0a0cbc 100644 --- a/tracker-pt/module/frame.hpp +++ b/tracker-pt/module/frame.hpp @@ -34,7 +34,7 @@ struct Preview final : pt_preview private: static void ensure_size(cv::Mat& frame, int w, int h, int type); - cv::Mat frame_copy, frame_out; + cv::Mat frame_copy, frame_out, frame_tmp; }; } // ns pt_module diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index a92c87c9..5e57ef34 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -124,6 +124,13 @@ void PointExtractor::filter_single_channel(const cv::Mat& orig_frame, float r, f void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) { + if (frame.channels() == 1) + { + output.create(frame.rows, frame.cols); + frame.copyTo(output); + return; + } + switch (s.blob_color) { case pt_color_green_only: |