Commit 39a8a79e authored by Thiago Santini's avatar Thiago Santini

Adjusts pupil detection and tracking interfaces to require a description

parent 957eb9a9
......@@ -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)
......
......@@ -6,7 +6,6 @@
using namespace cv;
std::string ElSe::desc = "ElSe (Fuhl et al. 2016)";
float ElSe::minArea = 0;
float ElSe::maxArea = 0;
......
......@@ -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
......@@ -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]) {
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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 };
......
......@@ -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());
......
......@@ -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> 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<TrackedPupil> 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> pupilDetectionMethod, const float& minPupilDiameterPx, const float& maxPupilDiameterPx);
cv::Rect estimateTemporalROI(const Timestamp& ts, const cv::Rect& roi);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment