From 39a8a79eafcae36fa2754cba836106e1542f06f3 Mon Sep 17 00:00:00 2001 From: Thiago Santini Date: Thu, 17 Jan 2019 11:31:40 +0100 Subject: [PATCH] Adjusts pupil detection and tracking interfaces to require a description --- EyeRecToo/src/EyeImageProcessor.h | 4 +-- EyeRecToo/src/pupil-detection/ElSe.cpp | 1 - EyeRecToo/src/pupil-detection/ElSe.h | 6 ++-- EyeRecToo/src/pupil-detection/ExCuSe.cpp | 4 +-- EyeRecToo/src/pupil-detection/ExCuSe.h | 3 +- EyeRecToo/src/pupil-detection/PuRe.cpp | 4 --- EyeRecToo/src/pupil-detection/PuRe.h | 2 +- .../pupil-detection/PupilDetectionMethod.h | 6 ++-- EyeRecToo/src/pupil-tracking/PuReST.cpp | 2 -- EyeRecToo/src/pupil-tracking/PuReST.h | 2 +- .../src/pupil-tracking/PupilTrackingMethod.h | 31 +++++++++---------- 11 files changed, 26 insertions(+), 39 deletions(-) diff --git a/EyeRecToo/src/EyeImageProcessor.h b/EyeRecToo/src/EyeImageProcessor.h index e00190f..7b19e38 100644 --- a/EyeRecToo/src/EyeImageProcessor.h +++ b/EyeRecToo/src/EyeImageProcessor.h @@ -45,8 +45,8 @@ public: , undistort(false) , coarseDetection(false) , processingDownscalingFactor(1) - , pupilDetectionMethod(PuRe::desc.c_str()) - , pupilTrackingMethod(PuReST::desc.c_str()) + , pupilDetectionMethod(PuRe().description().c_str()) + , pupilTrackingMethod(PuReST().description().c_str()) , roi(0.0f, 0.0f, 1.f, 1.f) , minPupilDiameterRatio(0.0f) , maxPupilDiameterRatio(0.27f) diff --git a/EyeRecToo/src/pupil-detection/ElSe.cpp b/EyeRecToo/src/pupil-detection/ElSe.cpp index 31118bb..49c506d 100644 --- a/EyeRecToo/src/pupil-detection/ElSe.cpp +++ b/EyeRecToo/src/pupil-detection/ElSe.cpp @@ -6,7 +6,6 @@ using namespace cv; -std::string ElSe::desc = "ElSe (Fuhl et al. 2016)"; float ElSe::minArea = 0; float ElSe::maxArea = 0; diff --git a/EyeRecToo/src/pupil-detection/ElSe.h b/EyeRecToo/src/pupil-detection/ElSe.h index 0a659ea..7e3a8be 100644 --- a/EyeRecToo/src/pupil-detection/ElSe.h +++ b/EyeRecToo/src/pupil-detection/ElSe.h @@ -20,14 +20,14 @@ public: static float minArea; static float maxArea; - ElSe() { mDesc = desc; } Pupil implDetect(const cv::Mat& frame, cv::Rect roi, const float& userMinPupilDiameterPx, const float& userMaxPupilDiameterPx) override; bool hasConfidence() override { return false; } bool hasCoarseLocation() override { return false; } - static std::string desc; + std::string description() { return "ElSe (Fuhl et al. 2016)"; } private: - cv::RotatedRect run(const cv::Mat& frame); + cv::RotatedRect + run(const cv::Mat& frame); }; #endif // ELSE_H diff --git a/EyeRecToo/src/pupil-detection/ExCuSe.cpp b/EyeRecToo/src/pupil-detection/ExCuSe.cpp index 601190f..940a52d 100644 --- a/EyeRecToo/src/pupil-detection/ExCuSe.cpp +++ b/EyeRecToo/src/pupil-detection/ExCuSe.cpp @@ -4,8 +4,6 @@ using namespace std; using namespace cv; -std::string ExCuSe::desc = "ExCuSe (Fuhl et al. 2015)"; - #define MAX_LINE 10000 static void matlab_bwselect(cv::Mat* strong, cv::Mat* weak, cv::Mat* check) @@ -282,7 +280,7 @@ static bool peek(cv::Mat* pic, double* stddev, int start_x, int end_x, int start for (int i = 0; i < 256; i++) if (gray_hist[i] > 0) { - mean_gray += gray_hist[i]*i; + mean_gray += gray_hist[i] * i; mean_gray_cnt++; if (max_gray < gray_hist[i]) { diff --git a/EyeRecToo/src/pupil-detection/ExCuSe.h b/EyeRecToo/src/pupil-detection/ExCuSe.h index ef83a7c..1e0761a 100644 --- a/EyeRecToo/src/pupil-detection/ExCuSe.h +++ b/EyeRecToo/src/pupil-detection/ExCuSe.h @@ -17,11 +17,10 @@ class ExCuSe : public PupilDetectionMethod { public: - ExCuSe() { mDesc = desc; } Pupil implDetect(const cv::Mat& frame, cv::Rect roi, const float& userMinPupilDiameterPx, const float& userMaxPupilDiameterPx) override; bool hasConfidence() override { return false; } bool hasCoarseLocation() override { return false; } - static std::string desc; + std::string description() { return "ExCuSe (Fuhl et al. 2015)"; } private: cv::RotatedRect run(const cv::Mat& frame); diff --git a/EyeRecToo/src/pupil-detection/PuRe.cpp b/EyeRecToo/src/pupil-detection/PuRe.cpp index 9c4a1e6..100f215 100644 --- a/EyeRecToo/src/pupil-detection/PuRe.cpp +++ b/EyeRecToo/src/pupil-detection/PuRe.cpp @@ -49,15 +49,11 @@ using namespace std; using namespace cv; -string PuRe::desc = "PuRe (Santini et. al 2018a)"; - PuRe::PuRe() : expectedFrameSize(-1, -1) , outlineBias(5) , baseSize(320, 240) { - mDesc = desc; - /* * 1) Canthi: * Using measurements from white men diff --git a/EyeRecToo/src/pupil-detection/PuRe.h b/EyeRecToo/src/pupil-detection/PuRe.h index 9ab8a95..31171e5 100644 --- a/EyeRecToo/src/pupil-detection/PuRe.h +++ b/EyeRecToo/src/pupil-detection/PuRe.h @@ -171,7 +171,7 @@ public: Pupil implDetect(const cv::Mat& frame, cv::Rect roi, const float& userMinPupilDiameterPx, const float& userMaxPupilDiameterPx) override; bool hasConfidence() override { return true; } bool hasCoarseLocation() override { return false; } - static std::string desc; + std::string description() { return "PuRe (Santini et. al 2018a)"; }; float meanCanthiDistanceMM; float maxPupilDiameterMM; diff --git a/EyeRecToo/src/pupil-detection/PupilDetectionMethod.h b/EyeRecToo/src/pupil-detection/PupilDetectionMethod.h index cb27f73..74619c4 100644 --- a/EyeRecToo/src/pupil-detection/PupilDetectionMethod.h +++ b/EyeRecToo/src/pupil-detection/PupilDetectionMethod.h @@ -91,7 +91,7 @@ Q_DECLARE_METATYPE(Pupil) class PupilDetectionMethod { public: - virtual ~PupilDetectionMethod() {} + virtual ~PupilDetectionMethod() = default; Pupil detect(const cv::Mat& frame, cv::Rect roi = { 0, 0, 0, 0 }, const float& userMinPupilDiameterPx = -1, const float& userMaxPupilDiameterPx = -1) { @@ -101,8 +101,7 @@ public: virtual bool hasConfidence() = 0; virtual bool hasCoarseLocation() = 0; - - std::string description() { return mDesc; } + virtual std::string description() = 0; // Pupil detection interface used in the tracking Pupil detectWithConfidence(const cv::Mat& frame, cv::Rect roi = { 0, 0, 0, 0 }, const float& userMinPupilDiameterPx = -1, const float& userMaxPupilDiameterPx = -1) @@ -128,7 +127,6 @@ public: protected: virtual Pupil implDetect(const cv::Mat& frame, cv::Rect roi, const float& userMinPupilDiameterPx, const float& userMaxPupilDiameterPx) = 0; - std::string mDesc; void sanitizeROI(const cv::Mat& frame, cv::Rect& roi) { cv::Rect froi = cv::Rect(0, 0, frame.cols - 1, frame.rows - 1); diff --git a/EyeRecToo/src/pupil-tracking/PuReST.cpp b/EyeRecToo/src/pupil-tracking/PuReST.cpp index 36fdb7b..c37d512 100644 --- a/EyeRecToo/src/pupil-tracking/PuReST.cpp +++ b/EyeRecToo/src/pupil-tracking/PuReST.cpp @@ -50,8 +50,6 @@ using namespace cv; //#define DBG_OUTLINE_TRACKER //#define DBG_GREEDY_TRACKER -std::string PuReST::desc = "PuReST (Santini et al. 2018c)"; - void PuReST::calculateHistogram(const cv::Mat& in, cv::Mat& histogram, const int& bins, const Mat& mask) { int channels[] = { 0 }; diff --git a/EyeRecToo/src/pupil-tracking/PuReST.h b/EyeRecToo/src/pupil-tracking/PuReST.h index 5269a18..9b5cdd1 100644 --- a/EyeRecToo/src/pupil-tracking/PuReST.h +++ b/EyeRecToo/src/pupil-tracking/PuReST.h @@ -78,12 +78,12 @@ class PuReST : public PupilTrackingMethod, private PuRe { public: PuReST() { - PupilTrackingMethod::mDesc = desc; openKernel = cv::getStructuringElement(cv::MORPH_ELLIPSE, { 7, 7 }); dilateKernel = cv::getStructuringElement(cv::MORPH_ELLIPSE, { 15, 15 }); } static std::string desc; void track(const cv::Mat& frame, const cv::Rect& roi, const Pupil& previousPupil, Pupil& pupil, const float& userMinPupilDiameterPx = -1, const float& userMaxPupilDiameterPx = -1); + std::string description() { return "PuReST (Santini et al. 2018c)"; } private: void calculateHistogram(const cv::Mat& in, cv::Mat& histogram, const int& bins, const cv::Mat& mask = cv::Mat()); diff --git a/EyeRecToo/src/pupil-tracking/PupilTrackingMethod.h b/EyeRecToo/src/pupil-tracking/PupilTrackingMethod.h index 889638d..563c7ad 100644 --- a/EyeRecToo/src/pupil-tracking/PupilTrackingMethod.h +++ b/EyeRecToo/src/pupil-tracking/PupilTrackingMethod.h @@ -36,24 +36,9 @@ public: // Tracking and detection logic virtual void detectAndTrack(const Timestamp& ts, const cv::Mat& frame, const cv::Rect& roi, Pupil& pupil, std::shared_ptr pupilDetectionMethod = nullptr, const float& minPupilDiameterPx = -1, const float& maxPupilDiameterPx = -1); - // Detection implementation (can be overridden by providing a valid pointer to the detectAndTrack method, allowing the user to mix detectors and trackers) - virtual Pupil detect(const cv::Mat& frame, const cv::Rect& roi, const float& minPupilDiameterPx = -1, const float& maxPupilDiameterPx = -1) - { - (void)frame; - (void)roi; - (void)minPupilDiameterPx; - (void)maxPupilDiameterPx; - qWarning() << Q_FUNC_INFO << "should never be called. Either implement it in the derived class or pass a valid pointer to the detectAndTrack method."; - return Pupil(); - } - - // Tracking implementation - virtual void track(const cv::Mat& frame, const cv::Rect& roi, const Pupil& previousPupil, Pupil& pupil, const float& minPupilDiameterPx = -1, const float& maxPupilDiameterPx = -1) = 0; - - std::string description() { return mDesc; } + virtual std::string description() = 0; protected: - std::string mDesc; cv::Size expectedFrameSize = { 0, 0 }; TrackedPupil previousPupil; std::deque previousPupils; @@ -66,6 +51,20 @@ protected: void reset(); private: + // Detection implementation (can be overridden by providing a valid pointer to the detectAndTrack method, allowing the user to mix detectors and trackers) + virtual Pupil detect(const cv::Mat& frame, const cv::Rect& roi, const float& minPupilDiameterPx = -1, const float& maxPupilDiameterPx = -1) + { + (void)frame; + (void)roi; + (void)minPupilDiameterPx; + (void)maxPupilDiameterPx; + qWarning() << Q_FUNC_INFO << "should never be called. Either implement it in the derived class or pass a valid pointer to the detectAndTrack method."; + return Pupil(); + } + + // Tracking implementation + virtual void track(const cv::Mat& frame, const cv::Rect& roi, const Pupil& previousPupil, Pupil& pupil, const float& minPupilDiameterPx = -1, const float& maxPupilDiameterPx = -1) = 0; + Pupil invokeDetection(const cv::Mat& frame, const cv::Rect& roi, std::shared_ptr pupilDetectionMethod, const float& minPupilDiameterPx, const float& maxPupilDiameterPx); cv::Rect estimateTemporalROI(const Timestamp& ts, const cv::Rect& roi); }; -- GitLab