diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-04-13 12:59:22 +0200 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-04-13 12:59:22 +0200 |
commit | 2a90f867d29f7080159a502230535fa397cb2adf (patch) | |
tree | d269bc7228f64474daf6fe5a9318696013d815f8 /tracker-easy/preview.cpp | |
parent | 4e79bfa83a92fd14ab7f453ac786b682079a0086 (diff) |
EasyTracker: Adding namespace. Reducing number of classes.
Diffstat (limited to 'tracker-easy/preview.cpp')
-rw-r--r-- | tracker-easy/preview.cpp | 142 |
1 files changed, 74 insertions, 68 deletions
diff --git a/tracker-easy/preview.cpp b/tracker-easy/preview.cpp index 33758cfa..404ad299 100644 --- a/tracker-easy/preview.cpp +++ b/tracker-easy/preview.cpp @@ -13,88 +13,94 @@ #include <opencv2/imgproc.hpp> -Preview& Preview::operator=(const cv::Mat& aFrame) +namespace EasyTracker { - // Make sure our frame is RGB - // Make an extra copy if needed - int channelCount = aFrame.channels(); - if (channelCount == 1) - { - // 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; - } - - return *this; -} + Preview& Preview::operator=(const cv::Mat& aFrame) + { -Preview::Preview(int w, int h) -{ - ensure_size(frame_out, w, h, CV_8UC4); - ensure_size(iFrameResized, w, h, CV_8UC3); + // Make sure our frame is RGB + // Make an extra copy if needed + int channelCount = aFrame.channels(); + if (channelCount == 1) + { + // 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; + } - iFrameResized.setTo(cv::Scalar(0, 0, 0)); -} -QImage Preview::get_bitmap() -{ - int stride = frame_out.step.p[0]; + return *this; + } - if (stride < 64 || stride < frame_out.cols * 4) + Preview::Preview(int w, int h) { - eval_once(qDebug() << "bad stride" << stride - << "for bitmap size" << iFrameResized.cols << iFrameResized.rows); - return QImage(); + ensure_size(frame_out, w, h, CV_8UC4); + ensure_size(iFrameResized, w, h, CV_8UC3); + + iFrameResized.setTo(cv::Scalar(0, 0, 0)); } - // Resize if needed - const bool need_resize = iFrameRgb.cols != frame_out.cols || iFrameRgb.rows != frame_out.rows; - if (need_resize) + QImage Preview::get_bitmap() { - cv::resize(iFrameRgb, iFrameResized, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST); + int stride = frame_out.step.p[0]; + + if (stride < 64 || stride < frame_out.cols * 4) + { + eval_once(qDebug() << "bad stride" << stride + << "for bitmap size" << iFrameResized.cols << iFrameResized.rows); + return QImage(); + } + + // Resize if needed + const bool need_resize = iFrameRgb.cols != frame_out.cols || iFrameRgb.rows != frame_out.rows; + if (need_resize) + { + cv::resize(iFrameRgb, iFrameResized, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST); + } + else + { + iFrameRgb.copyTo(iFrameResized); + } + + cv::cvtColor(iFrameResized, frame_out, cv::COLOR_BGR2BGRA); + + return QImage((const unsigned char*)frame_out.data, + frame_out.cols, frame_out.rows, + stride, + QImage::Format_ARGB32); } - else + + void Preview::draw_head_center(numeric_types::f x, numeric_types::f y) { - iFrameRgb.copyTo(iFrameResized); + int px = iround(x), py = iround(y); + + constexpr int len = 9; + + static const cv::Scalar color(0, 255, 255); + cv::line(iFrameRgb, + cv::Point(px - len, py), + cv::Point(px + len, py), + color, 1); + cv::line(iFrameRgb, + cv::Point(px, py - len), + cv::Point(px, py + len), + color, 1); } - cv::cvtColor(iFrameResized, frame_out, cv::COLOR_BGR2BGRA); - - return QImage((const unsigned char*) frame_out.data, - frame_out.cols, frame_out.rows, - stride, - QImage::Format_ARGB32); -} - -void Preview::draw_head_center(numeric_types::f x, numeric_types::f y) -{ - int px = iround(x), py = iround(y); - - constexpr int len = 9; - - static const cv::Scalar color(0, 255, 255); - cv::line(iFrameRgb, - cv::Point(px - len, py), - cv::Point(px + len, py), - color, 1); - cv::line(iFrameRgb, - cv::Point(px, py - len), - cv::Point(px, py + len), - color, 1); -} + void Preview::ensure_size(cv::Mat& frame, int w, int h, int type) + { + if (frame.cols != w || frame.rows != h) + frame = cv::Mat(h, w, type); + } -void Preview::ensure_size(cv::Mat& frame, int w, int h, int type) -{ - if (frame.cols != w || frame.rows != h) - frame = cv::Mat(h, w, type); } |