Commit 9fdfb9ac authored by Thiago Santini's avatar Thiago Santini

Brings back outlier detection based on the residuals

parent 0e0c6000
...@@ -18,9 +18,6 @@ string BinocularPolyFit::description() const ...@@ -18,9 +18,6 @@ string BinocularPolyFit::description() const
bool BinocularPolyFit::calibrate(vector<CollectionTuple>& calibrationTuples, QString& errorMsg) bool BinocularPolyFit::calibrate(vector<CollectionTuple>& calibrationTuples, QString& errorMsg)
{ {
if (!PolyFit::calibrate(calibrationTuples, errorMsg))
return false;
PointVector leftPupil; PointVector leftPupil;
PointVector rightPupil; PointVector rightPupil;
PointVector gaze; PointVector gaze;
...@@ -39,9 +36,50 @@ bool BinocularPolyFit::calibrate(vector<CollectionTuple>& calibrationTuples, QSt ...@@ -39,9 +36,50 @@ bool BinocularPolyFit::calibrate(vector<CollectionTuple>& calibrationTuples, QSt
binocularCalibrated = calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.x, bcx, errorMsg) binocularCalibrated = calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.x, bcx, errorMsg)
&& calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.y, bcy, errorMsg); && calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.y, bcy, errorMsg);
if (!binocularCalibrated)
return binocularCalibrated;
const auto& ref = calibrationTuples[0];
float threshold = 0.01f * hypot(ref.field.width, ref.field.height);
vector<CollectionTuple> inliers;
for (const auto& tuple : calibrationTuples) {
GazeEstimate l, r, b;
l.pupilConfidence = tuple.lEye.pupil.confidence;
r.pupilConfidence = tuple.rEye.pupil.confidence;
estimateBinocular2d(tuple, l, r, b);
Point2f gt = { tuple.field.collectionMarker.center.x, tuple.field.collectionMarker.center.y };
if (cv::norm(gt - b.gp) < threshold)
inliers.push_back(tuple);
}
binocularCalibrated = calibrateWithInliers(inliers, errorMsg);
return binocularCalibrated; return binocularCalibrated;
} }
bool BinocularPolyFit::calibrateWithInliers(std::vector<CollectionTuple>& calibrationTuples, QString& errorMsg)
{
if (!PolyFit::calibrate(calibrationTuples, errorMsg))
return false;
PointVector leftPupil;
PointVector rightPupil;
PointVector gaze;
for (const auto& tuple : calibrationTuples) {
leftPupil.insert(PolyFit::normalize(tuple.lEye.pupil.center, tuple.lEye.input));
rightPupil.insert(PolyFit::normalize(tuple.rEye.pupil.center, tuple.rEye.input));
gaze.insert(PolyFit::normalize(tuple.field.collectionMarker.center, tuple.field.input));
}
if (gaze.size() < binocularUnknowns) {
errorMsg = QString("Not enough calibration points (%1/%2).").arg(gaze.size()).arg(binocularUnknowns);
return false;
}
return calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.x, bcx, errorMsg)
&& calibrate(plType, leftPupil.x, leftPupil.y, rightPupil.x, rightPupil.y, gaze.y, bcy, errorMsg);
}
bool BinocularPolyFit::calibrate(const PlType& type, const Mat& lx, const Mat& ly, const Mat& rx, const Mat& ry, const Mat& z, Mat1d& c, QString& errorMsg) bool BinocularPolyFit::calibrate(const PlType& type, const Mat& lx, const Mat& ly, const Mat& rx, const Mat& ry, const Mat& z, Mat1d& c, QString& errorMsg)
{ {
......
...@@ -18,6 +18,7 @@ private: ...@@ -18,6 +18,7 @@ private:
cv::Mat1d bcy; cv::Mat1d bcy;
bool calibrate(const PlType& type, const cv::Mat& lx, const cv::Mat& ly, const cv::Mat& rx, const cv::Mat& ry, const cv::Mat& z, cv::Mat1d& c, QString& errorMsg); bool calibrate(const PlType& type, const cv::Mat& lx, const cv::Mat& ly, const cv::Mat& rx, const cv::Mat& ry, const cv::Mat& z, cv::Mat1d& c, QString& errorMsg);
bool calibrateWithInliers(std::vector<CollectionTuple>& calibrationTuples, QString& errorMsg);
}; };
#endif // BINOCULARPOLYFIT_H #endif // BINOCULARPOLYFIT_H
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