Commit 178a692a authored by Thiago C. Santini's avatar Thiago C. Santini

Starts moving homography to own files

parent b60305dc
......@@ -25,7 +25,8 @@ SOURCES += \
$${TOP}/src/Trigger.cpp \
$${TOP}/src/GlobalTimer.cpp \
$${TOP}/src/PolyFit.cpp \
$${TOP}/src/CalibrationMethod.cpp
$${TOP}/src/CalibrationMethod.cpp \
src/Homography.cpp
HEADERS += \
$${TOP}/src/ImageProcessing.h \
......@@ -62,7 +63,8 @@ HEADERS += \
$${TOP}/else/filter_edges.h \
$${TOP}/else/find_best_edge.h \
$${TOP}/src/PolyFit.h \
$${TOP}/src/CalibrationMethod.h
$${TOP}/src/CalibrationMethod.h \
src/Homography.h
FORMS += \
$${TOP}/src/Gui.ui
......
......@@ -98,6 +98,18 @@ bool Calibration::calibrate()
{
bool success = true;
assert(pupilEstimates.size() == fieldPoints.size());
#ifdef CALIBRATION_DBG
for(unsigned int i=0; i<fieldPoints.size(); i++) {
qDebug()
<< "(" << fieldPoints[i].x << "," << fieldPoints[i].y
<< ") x ("
<< pupilEstimates[i].x << "," <<pupilEstimates[i].y
<< ")";
}
#endif
int minPointsForCalibration = settings.value("calibration/minPointsForCalibration").toInt();
if (fieldPoints.size() < minPointsForCalibration) {
QMessageBox::warning(NULL, "Calibration failed.",
......@@ -116,15 +128,6 @@ bool Calibration::calibrate()
success = false;
}
#ifdef CALIBRATION_DBG
for(unsigned int i=0; i<fieldPoints.size(); i++) {
qDebug()
<< "(" << fieldPoints[i].x << "," << fieldPoints[i].y
<< ") x ("
<< pupilEstimates[i].x << "," <<pupilEstimates[i].y
<< ")";
}
#endif
}
if (!success)
......
......@@ -55,7 +55,6 @@ private:
bool collecting;
QList<QPoint> pupilSamples;
std::vector<cv::Point2f> pupilEstimates;
};
......
#include "Homography.h"
Homography::Homography()
{
}
Homography::~Homography()
{
}
bool Homography::calibrate(vector<Point2d> leftPupil, vector<Point2d> rightPupil, vector<Point2d> field, QString &errorMsg)
{
int minPoints = 4;
if ( field.size() < minPoints) {
errorMsg = QString("Not enough calibration points.\nGot %1\nRequired: %2\nPlease start again.").arg(field.size()).arg(minPoints);
return false;
}
// TODO: binocular support
H = findHomography( leftPupil, field, RANSAC);
if ( H.empty() )
H = findHomography( leftPupil, field);
if (H.empty()) {
errorMsg = QString("Could not find perspective transformation.\nPlease start again.");
return false;
}
return true;
}
Point2d Homography::evaluate(Point2d leftPupil, Point2d rightPupil)
{
vector<Point2d> estimate;
vector<Point2d> pupil;
pupil.push_back( Point2d( leftPupil.x, leftPupil.y ) );
perspectiveTransform(pupil, estimate, H);
return estimate[0];
}
#ifndef HOMOGRAPHY_H
#define HOMOGRAPHY_H
#include <iostream>
#include <vector>
#include "opencv2/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <QString>
#include "CalibrationMethod.h"
using namespace std;
using namespace cv;
class Homography : public CalibrationMethod
{
public:
Homography();
~Homography();
bool calibrate(vector<Point2d> leftPupil, vector<Point2d> rightPupil, vector<Point2d> field, QString &errorMsg);
Point2d evaluate(Point2d leftPupil, Point2d rightPupil);
Mat H;
private:
};
#endif // HOMOGRAPHY_H
......@@ -19,8 +19,6 @@ bool PolyFit::calibrate(vector<Point2d> leftPupil, vector<Point2d> rightPupil, v
Mat x, y , xx, yy, xy, xxyy, zx, zy, A, iA;
// TODO: binocular; assume only one eye and that data comes in the leftPupil variable atm
assert(leftPupil.size() == field.size());
for (unsigned int i=0; i<field.size(); i++) {
x.push_back(leftPupil[i].x);
y.push_back(leftPupil[i].y);
......
......@@ -3,7 +3,6 @@
#include <iostream>
#include <vector>
#include <assert.h>
#include "opencv2/core.hpp"
......
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