Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

EyeCalibration finds bounding polygons around points.

  • Loading branch information...
commit ca2f6aa2fafdd3c9d833b78f4763445029301119 1 parent e784c69
@mdfeist authored
Showing with 102 additions and 12 deletions.
  1. +99 −9 BlinkAnalysis/EyeCalibration.cpp
  2. +3 −3 BlinkAnalysis/EyeCalibration.h
View
108 BlinkAnalysis/EyeCalibration.cpp
@@ -288,7 +288,7 @@ bool EyeCalibration::calibrate() {
for (unsigned int i = 0; i < orderedPoints.size(); i++) {
CalibrationPoint point = orderedPoints.at(i);
- if (pointInPolygon(convexHull, point))
+ if (pointInPolygon(convexHull, point) < 0)
innerPoints.push_back(point);
else
convexHullPoints.push_back(point);
@@ -337,7 +337,7 @@ bool EyeCalibration::calibrate() {
if (!alreadyKnown) {
// Check if point is inside the convex hull
- if (pointInPolygon(convexHull, point)) {
+ if (pointInPolygon(convexHull, point) <= 0) {
innerUnknownPoints.push_back(point);
} else {
outerUnknownPoints.push_back(point);
@@ -346,12 +346,101 @@ bool EyeCalibration::calibrate() {
}
}
+ // Print Convex Hull
+ for (unsigned int j = 0; j < ClientHandler::getDikablisViewingHeight() + margin; j+=20) {
+ for (unsigned int i = 0; i < ClientHandler::getDikablisViewingWidth() + margin; i+=20) {
+ int x = i - ClientHandler::getDikablisViewingMargin();
+ int y = j - ClientHandler::getDikablisViewingMargin();
+
+ // Create point
+ CalibrationPoint point(x, y, osg::Vec3(0.f, 0.f, 0.f));
+
+ // Check if point is inside the convex hull
+ if (pointInPolygon(convexHull, point) <= 0) {
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("1");
+ } else {
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("0");
+ }
+ }
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("\n");
+ }
+
// Calculate Inner Interpolation
+ std::vector<CalibrationPoint> boundingPoints;
+ std::vector<Segment> subHull;
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));
+ bool foundBoundingHull = false;
+
+ if (boundingPoints.size() >= 4 && subHull.size() != 0) {
+ if (pointInPolygon(subHull, point) <= 0) {
+ foundBoundingHull = true;
+ }
+ }
+
+ if (!foundBoundingHull) {
+ std::vector<CalibrationPoint> possibleBoundingPoints(orderedPoints);
+ std::sort (possibleBoundingPoints.begin(), possibleBoundingPoints.end(), ComparePointsDistanceFrom(this, point));
+
+ unsigned int pi = 0;
+ while (pi < 4) {
+ CalibrationPoint boundingPoint = possibleBoundingPoints.at(pi);
+ boundingPoints.push_back(boundingPoint);
+
+ pi++;
+ }
+
+ while (!foundBoundingHull) {
+ subHull = calculateConvexHull(boundingPoints);
+ if (pointInPolygon(subHull, point) <= 0) {
+ foundBoundingHull = true;
+ } else {
+
+ for (int _times = 0; _times < 2; _times++) {
+
+ for (int _rm = boundingPoints.size() - 1; _rm >= 0; _rm--) {
+ if (pointInPolygon(convexHull, boundingPoints.at(_rm)) < 0) {
+ boundingPoints.erase(boundingPoints.begin() + _rm);
+ break;
+ }
+ }
+ }
+
+ if (boundingPoints.size() >= 4) {
+ sprintf_s(buf, "Point %d: (%d, %d) pi %d\n",
+ i + 1,
+ point.x(), point.y(), pi + 1);
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog(buf);
+
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Failed: Unable to create bounding box for point.\n");
+ break;
+ }
+
+ while (pi < possibleBoundingPoints.size() && boundingPoints.size() < 4) {
+ boundingPoints.push_back(possibleBoundingPoints.at(pi));
+ pi++;
+ }
+
+ if (boundingPoints.size() < 4) {
+
+ sprintf_s(buf, "Point %d: (%d, %d) pi %d\n",
+ i + 1,
+ point.x(), point.y(), pi + 1);
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog(buf);
+
+
+ EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Unable to create bounding box for point.\n");
+ break;
+ }
+ }
+ }
+ }
+
+
+
+ if (!foundBoundingHull)
+ continue;
}
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog("Done\n");
@@ -359,7 +448,7 @@ bool EyeCalibration::calibrate() {
return true;
}
-bool EyeCalibration::pointInPolygon(std::vector<Segment> hull, CalibrationPoint point) {
+int EyeCalibration::pointInPolygon(std::vector<Segment> hull, CalibrationPoint point) {
unsigned int n = hull.size();
@@ -371,17 +460,18 @@ bool EyeCalibration::pointInPolygon(std::vector<Segment> hull, CalibrationPoint
{
Segment segment = hull.at(i);
- if(isLeft(segment, point) >= 0)
- return false;
+ int left = isLeft(segment, point);
+ if(left >= 0)
+ return left;
}
- return true;
+ return -1;
}
void EyeCalibration::testPointInPolygon(CalibrationPoint point) {
char buf[512];
- if (pointInPolygon(convexHull, point)) {
+ if (pointInPolygon(convexHull, point) < 0) {
sprintf_s(buf, "Point (%d, %d) is inside.\n", point.x(), point.y());
EyeCalibrationWizardFormController::getInstance()->calibrationOutputLog(buf);
} else {
View
6 BlinkAnalysis/EyeCalibration.h
@@ -72,8 +72,8 @@ class EyeCalibration {
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());
+ float distanceA = (_point.x()-a.x())*(_point.x()-a.x()) + (_point.y()-a.y())*(_point.y()-a.y());
+ float distanceB = (_point.x()-b.x())*(_point.x()-b.x()) + (_point.y()-b.y())*(_point.y()-b.y());
if (distanceA < distanceB)
return true;
@@ -99,7 +99,7 @@ class EyeCalibration {
bool addPoint();
bool calibrate();
- bool pointInPolygon(std::vector<Segment> hull, CalibrationPoint point);
+ int pointInPolygon(std::vector<Segment> hull, CalibrationPoint point);
void testPointInPolygon(CalibrationPoint point);
void createTestData();
Please sign in to comment.
Something went wrong with that request. Please try again.