Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated EyeCalibration.

  • Loading branch information...
commit 18df0223472daad0e51dad668128ce967b3db7a6 1 parent 0df1744
@mdfeist authored
Showing with 70 additions and 11 deletions.
  1. +45 −7 BlinkAnalysis/EyeCalibration.cpp
  2. +25 −4 BlinkAnalysis/EyeCalibration.h
View
52 BlinkAnalysis/EyeCalibration.cpp
@@ -204,7 +204,7 @@ bool EyeCalibration::calibrate() {
// Sort Points
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Ordering Points ...\n");
- std::sort (orderedPoints.begin(), orderedPoints.end(), *this);
+ std::sort (orderedPoints.begin(), orderedPoints.end(), ComparePoints(this));
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Ordered Points\n");
// Clearing previous segments
@@ -276,6 +276,8 @@ bool EyeCalibration::calibrate() {
// Group Points
std::vector<CalibrationPoint> convexHullPoints;
std::vector<CalibrationPoint> innerPoints;
+ std::vector<CalibrationPoint> innerUnknownPoints;
+ std::vector<CalibrationPoint> outerUnknownPoints;
for (unsigned int i = 0; i < orderedPoints.size(); i++) {
CalibrationPoint point = orderedPoints.at(i);
@@ -290,7 +292,7 @@ bool EyeCalibration::calibrate() {
for (unsigned int i = 0; i < innerPoints.size(); i++) {
CalibrationPoint point = innerPoints.at(i);
- sprintf_s(buf, "Inner Point %d: (%d, %d))\n",
+ sprintf_s(buf, "Inner Point %d: (%d, %d)\n",
i + 1,
point.x(), point.y());
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog(buf);
@@ -300,17 +302,53 @@ bool EyeCalibration::calibrate() {
for (unsigned int i = 0; i < convexHullPoints.size(); i++) {
CalibrationPoint point = convexHullPoints.at(i);
- sprintf_s(buf, "Convex Hull Point %d: (%d, %d))\n",
+ sprintf_s(buf, "Convex Hull Point %d: (%d, %d)\n",
i + 1,
point.x(), point.y());
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog(buf);
}
- CalibrationPoint pointIn(740, 320, osg::Vec3(0.f, 0.f, 0.f));
- testPointInPolygon(pointIn);
+ unsigned int margin = + 2*ClientHandler::getDikablisViewingMargin();
+ for (unsigned int j = 0; j < ClientHandler::getDikablisViewingHeight() + margin; j++) {
+ for (unsigned int i = 0; i < ClientHandler::getDikablisViewingWidth() + margin; i++) {
+ int x = i - ClientHandler::getDikablisViewingMargin();
+ int y = j - ClientHandler::getDikablisViewingMargin();
- CalibrationPoint pointOut(232, 2, osg::Vec3(0.f, 0.f, 0.f));
- testPointInPolygon(pointOut);
+ // Create point
+ CalibrationPoint point(x, y, osg::Vec3(0.f, 0.f, 0.f));
+
+ // Check if point has an already known ray
+ bool alreadyKnown = false;
+ for (unsigned int i = 0; i < orderedPoints.size(); i++) {
+ CalibrationPoint knownPoint = orderedPoints.at(i);
+
+ if ((knownPoint.x() == point.x()) &&
+ (knownPoint.y() == point.y())) {
+ alreadyKnown = true;
+ break;
+ }
+ }
+
+ if (!alreadyKnown) {
+ // Check if point is inside the convex hull
+ if (pointInPolygon(point)) {
+ innerUnknownPoints.push_back(point);
+ } else {
+ outerUnknownPoints.push_back(point);
+ }
+ }
+ }
+ }
+
+ // Calculate Inner Interpolation
+ for (unsigned int i = 0; i < innerUnknownPoints.size(); i++) {
+ CalibrationPoint point = innerUnknownPoints.at(i);
+
+ std::vector<CalibrationPoint> knowPoints(orderedPoints);
+ std::sort (knowPoints.begin(), knowPoints.end(), ComparePointsDistanceFrom(this, point));
+ }
+
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Done\n");
return true;
}
View
29 BlinkAnalysis/EyeCalibration.h
@@ -55,6 +55,31 @@ class EyeCalibration {
bool isEdge(std::vector<CalibrationPoint> processingPoints, Segment edge);
int isLeft(Segment segment, CalibrationPoint r);
+ struct ComparePoints : std::binary_function<CalibrationPoint, CalibrationPoint, bool> {
+ ComparePoints(EyeCalibration * cal) : _cal(cal) {}
+ bool operator() (CalibrationPoint a, CalibrationPoint b) const {
+ return _cal->isLess(a, b);
+ }
+
+ EyeCalibration * _cal;
+ };
+
+ struct ComparePointsDistanceFrom : std::binary_function<CalibrationPoint, CalibrationPoint, bool> {
+ ComparePointsDistanceFrom(EyeCalibration * cal, CalibrationPoint point) : _cal(cal), _point(point) {}
+ bool operator() (CalibrationPoint a, CalibrationPoint b) {
+ float distanceA = sqrtf(_point.x()*a.x() + _point.y()*a.y());
+ float distanceB = sqrtf(_point.x()*b.x() + _point.y()*b.y());
+
+ if (distanceA < distanceB)
+ return true;
+
+ return false;
+ }
+
+ EyeCalibration * _cal;
+ CalibrationPoint _point;
+ };
+
public:
EyeCalibration(void);
~EyeCalibration(void) {};
@@ -71,10 +96,6 @@ class EyeCalibration {
bool calibrate();
bool pointInPolygon(CalibrationPoint point);
- bool operator()(CalibrationPoint a, CalibrationPoint b) {
- return isLess(a, b);
- }
-
void testPointInPolygon(CalibrationPoint point);
void createTestData();
};
Please sign in to comment.
Something went wrong with that request. Please try again.