From ac8f7a3e7b29a5ce60ae751ee3a97e3b344c8f3f Mon Sep 17 00:00:00 2001 From: Stéphane Lenclud Date: Sat, 13 Apr 2019 12:31:56 +0200 Subject: Easy Tracker: Renaming frame to preview. --- tracker-easy/cv-point-extractor.cpp | 6 +-- tracker-easy/cv-point-extractor.h | 4 +- tracker-easy/frame.cpp | 92 --------------------------------- tracker-easy/frame.hpp | 29 ----------- tracker-easy/module.cpp | 2 - tracker-easy/preview.cpp | 100 ++++++++++++++++++++++++++++++++++++ tracker-easy/preview.h | 36 +++++++++++++ tracker-easy/tracker-easy.h | 2 +- 8 files changed, 142 insertions(+), 129 deletions(-) delete mode 100644 tracker-easy/frame.cpp delete mode 100644 tracker-easy/frame.hpp create mode 100644 tracker-easy/preview.cpp create mode 100644 tracker-easy/preview.h (limited to 'tracker-easy') diff --git a/tracker-easy/cv-point-extractor.cpp b/tracker-easy/cv-point-extractor.cpp index 7c0b00b5..56de4c0b 100644 --- a/tracker-easy/cv-point-extractor.cpp +++ b/tracker-easy/cv-point-extractor.cpp @@ -1,5 +1,5 @@ -/* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2015-2017 Stanislaw Halik +/* + * Copyright (c) 2019 Stephane Lenclud * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -7,7 +7,7 @@ */ #include "cv-point-extractor.h" -#include "frame.hpp" +#include "preview.h" #include "cv/numeric.hpp" #include "compat/math.hpp" diff --git a/tracker-easy/cv-point-extractor.h b/tracker-easy/cv-point-extractor.h index 8a8ed66b..405ca052 100644 --- a/tracker-easy/cv-point-extractor.h +++ b/tracker-easy/cv-point-extractor.h @@ -1,5 +1,5 @@ -/* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2015-2016 Stanislaw Halik +/* + * Copyright (c) 2019 Stephane Lenclud * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/tracker-easy/frame.cpp b/tracker-easy/frame.cpp deleted file mode 100644 index 12f70662..00000000 --- a/tracker-easy/frame.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "frame.hpp" - -#include "compat/math.hpp" - -#include - - -Preview& Preview::operator=(const cv::Mat& aFrame) -{ - - // 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(int w, int h) -{ - ensure_size(frame_out, w, h, CV_8UC4); - ensure_size(iFrameResized, w, h, CV_8UC3); - - iFrameResized.setTo(cv::Scalar(0, 0, 0)); -} - -QImage Preview::get_bitmap() -{ - 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); -} - -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); -} diff --git a/tracker-easy/frame.hpp b/tracker-easy/frame.hpp deleted file mode 100644 index 8493b4e9..00000000 --- a/tracker-easy/frame.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "tracker-easy-api.h" - -#include -#include - - - -struct Preview -{ - Preview(int w, int h); - - Preview& operator=(const cv::Mat& frame); - QImage get_bitmap(); - void draw_head_center(numeric_types::f x, numeric_types::f y); - - operator cv::Mat&() { return iFrameResized; } - operator cv::Mat const&() const { return iFrameResized; } - -private: - static void ensure_size(cv::Mat& frame, int w, int h, int type); - -public: - cv::Mat iFrameResized, frame_out; - cv::Mat iFrameRgb; -}; - - diff --git a/tracker-easy/module.cpp b/tracker-easy/module.cpp index d24a1336..0c360e80 100644 --- a/tracker-easy/module.cpp +++ b/tracker-easy/module.cpp @@ -1,9 +1,7 @@ #include "tracker-easy.h" #include "tracker-easy-dialog.h" #include "tracker-easy-api.h" - #include "module.hpp" -#include "frame.hpp" #include "cv-point-extractor.h" diff --git a/tracker-easy/preview.cpp b/tracker-easy/preview.cpp new file mode 100644 index 00000000..33758cfa --- /dev/null +++ b/tracker-easy/preview.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2019 Stephane Lenclud + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include "preview.h" + +#include "compat/math.hpp" + +#include + + +Preview& Preview::operator=(const cv::Mat& aFrame) +{ + + // 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(int w, int h) +{ + ensure_size(frame_out, w, h, CV_8UC4); + ensure_size(iFrameResized, w, h, CV_8UC3); + + iFrameResized.setTo(cv::Scalar(0, 0, 0)); +} + +QImage Preview::get_bitmap() +{ + 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); +} + +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); +} diff --git a/tracker-easy/preview.h b/tracker-easy/preview.h new file mode 100644 index 00000000..fc7ec9c9 --- /dev/null +++ b/tracker-easy/preview.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Stephane Lenclud + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + + +#pragma once + +#include "tracker-easy-api.h" + +#include +#include + +struct Preview +{ + Preview(int w, int h); + + Preview& operator=(const cv::Mat& frame); + QImage get_bitmap(); + void draw_head_center(numeric_types::f x, numeric_types::f y); + + operator cv::Mat&() { return iFrameResized; } + operator cv::Mat const&() const { return iFrameResized; } + +private: + static void ensure_size(cv::Mat& frame, int w, int h, int type); + +public: + cv::Mat iFrameResized, frame_out; + cv::Mat iFrameRgb; +}; + + diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h index 23c9252a..3055299b 100644 --- a/tracker-easy/tracker-easy.h +++ b/tracker-easy/tracker-easy.h @@ -13,7 +13,7 @@ #include "cv/numeric.hpp" #include "video/video-widget.hpp" #include "video/camera.hpp" -#include "frame.hpp" +#include "preview.h" #include #include -- cgit v1.2.3