diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-04-13 00:19:18 +0200 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-04-13 00:19:18 +0200 |
commit | 8b1003b25a85adef57d47fe7b26000e02157989a (patch) | |
tree | af19004ed7777a3fb2a246a118ea56170bc34045 /tracker-easy/frame.cpp | |
parent | 9c40d1724bb2d564a734f6be7d6d91e7c5be64f7 (diff) |
Easy Tracker: Support for single channel camera frames.
Diffstat (limited to 'tracker-easy/frame.cpp')
-rw-r--r-- | tracker-easy/frame.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/tracker-easy/frame.cpp b/tracker-easy/frame.cpp index 9243c6a1..2464f85f 100644 --- a/tracker-easy/frame.cpp +++ b/tracker-easy/frame.cpp @@ -5,21 +5,37 @@ #include <opencv2/imgproc.hpp> -Preview& Preview::operator=(const cv::Mat& frame) +Preview& Preview::operator=(const cv::Mat& aFrame) { - if (frame.channels() != 3) + // Make sure our frame is RGB + // Make an extra copy if needed + int channelCount = aFrame.channels(); + if (channelCount == 1) { - eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); + // Convert to RGB + cv::cvtColor(aFrame, iFrameRgb, cv::COLOR_GRAY2BGR); + } + else if (channelCount == 3) + { + iFrameRgb = aFrame; + } + else + { + eval_once(qDebug() << "tracker/easy: camera frame depth not supported" << aFrame.channels()); return *this; } - const bool need_resize = frame.cols != frame_out.cols || frame.rows != frame_out.rows; + const bool need_resize = iFrameRgb.cols != frame_out.cols || iFrameRgb.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(iFrameRgb, frame_copy, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST); + } else - frame.copyTo(frame_copy); - + { + iFrameRgb.copyTo(frame_copy); + } + return *this; } |