Permalink
Browse files

it builds, in theory

  • Loading branch information...
1 parent 346455b commit da13133c14feacca4a6661ebe73cf2005076d128 @rkabir rkabir committed Nov 25, 2011
Showing with 3,428 additions and 3 deletions.
  1. +92 −0 BlinkDetector.h
  2. +90 −0 BlinkDetector.mm
  3. +62 −0 Calibrator.h
  4. +123 −0 Calibrator.mm
  5. +65 −0 Containers.h
  6. +3 −0 Containers.mm
  7. +22 −0 EyeExtractor.h
  8. +56 −0 EyeExtractor.mm
  9. +16 −0 FMatrixAffineCompute.h
  10. +69 −0 FMatrixAffineCompute.mm
  11. +15 −0 FaceDetector.h
  12. +59 −0 FaceDetector.mm
  13. +13 −0 FeatureDetector.h
  14. +33 −0 FeatureDetector.mm
  15. +83 −0 GaussianProcess.mm
  16. +21 −0 GazeArea.h.bak
  17. +86 −0 GazeArea.mm.bak
  18. +64 −0 GazeTracker.h
  19. +166 −0 GazeTracker.mm
  20. +25 −0 GraphicalPointer.h
  21. +22 −0 GraphicalPointer.mm
  22. +38 −0 HeadCompensation.mm
  23. +29 −0 HeadTracker.h
  24. +258 −0 HeadTracker.mm
  25. +25 −0 LeastSquares.h
  26. +46 −0 LeastSquares.mm
  27. +57 −0 MainGazeTracker.h
  28. +190 −0 MainGazeTracker.mm
  29. +36 −0 OutputMethods.h
  30. +68 −0 OutputMethods.mm
  31. +34 −0 Point.h.bak
  32. +76 −0 Point.mm.bak
  33. +48 −0 PointTracker.h
  34. +187 −0 PointTracker.mm
  35. +23 −0 TrackingSystem.h
  36. +153 −0 TrackingSystem.mm
  37. +12 −0 WindowStore.h
  38. +12 −0 WindowStore.mm
  39. +406 −3 og3.xcodeproj/project.pbxproj
  40. +7 −0 og3.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  41. BIN og3.xcodeproj/project.xcworkspace/xcuserdata/rkabir.xcuserdatad/UserInterfaceState.xcuserstate
  42. +5 −0 og3.xcodeproj/xcuserdata/rkabir.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
  43. +84 −0 og3.xcodeproj/xcuserdata/rkabir.xcuserdatad/xcschemes/og3.xcscheme
  44. +22 −0 og3.xcodeproj/xcuserdata/rkabir.xcuserdatad/xcschemes/xcschememanagement.plist
  45. +1 −0 og3/AppDelegate.h
  46. +2 −0 og3/og3-Prefix.pch
  47. +39 −0 ogPoint.h
  48. +76 −0 ogPoint.mm
  49. +138 −0 opengazerHighGui.mm
  50. +151 −0 utils.h
  51. +20 −0 utils.mm
View
@@ -0,0 +1,92 @@
+#pragma once
+#include "utils.h"
+
+using namespace std;
+using namespace boost;
+
+struct StateNode {
+ int minduration, maxduration;
+ double threshold;
+ StateNode(int minduration, int maxduration, double threshold);
+ bool isSatisfied(double value) const;
+};
+
+class LinearStateSystem {
+ const vector<StateNode> states;
+ int currentState, duration;
+public:
+ LinearStateSystem(const vector<StateNode> &states);
+ void updateState(double value);
+ void setState(int state);
+ int getState();
+ bool isFinalState();
+};
+
+class LambdaAccumulator {
+ const double lambda;
+ double current;
+ public:
+ LambdaAccumulator(double lambda, double initial);
+ void update(double value);
+ double getValue();
+};
+
+class BlinkDetector {
+ scoped_ptr<IplImage> averageEye;
+ LambdaAccumulator acc;
+ LinearStateSystem states;
+ static vector<StateNode> constructStates();
+ public:
+ BlinkDetector();
+ void update(const scoped_ptr<IplImage> &image);
+ int getState();
+};
+
+
+
+/* template <class T> */
+/* class TwoClassDetector { */
+/* const T class0, class1; */
+/* public: */
+/* TwoClassDetector(const T& class0, const T& class1): */
+/* class0(class0), class1(class1) {} */
+
+/* double classify(const T& object) { */
+/* double dist0 = distance(class0, object); */
+/* double dist1 = distance(class0, object); */
+/* return dist0 / (dist0 + dist1); */
+/* }; */
+/* }; */
+
+/* template <class T, class Func> */
+/* class Accumulator { */
+/* T accumulator; */
+/* Func func; */
+/* public: */
+/* Accumulator(const T& initial, const Func& func): */
+/* accumulator(initial), func(func) */
+/* {}; */
+/* void update(const T& object) { */
+/* accumulator = func(accumulator, object); */
+/* } */
+/* T get() { */
+/* return accumulator; */
+/* } */
+/* }; */
+
+/* template <T> */
+/* class GetFurtherObject { */
+/* T referenceobject; */
+/* public: */
+/* T operator()(const T& one, const T& two) { */
+/* if (distance(referenceobject, one) > distance(referenceobject, two)) */
+/* return one; */
+/* else */
+/* return two; */
+/* } */
+/* }; */
+
+/* Accumulator<shared_ptr<IplImage> > */
+/* blink(currentimage, GetFurtherObject(average)); */
+
+/* typedef TwoClassDetector<shared_ptr<IplImage> > BlinkDetector(average, blink.get()); */
View
@@ -0,0 +1,90 @@
+#include "BlinkDetector.h"
+#include <iostream>
+#include "EyeExtractor.h"
+#include "utils.h"
+
+StateNode::StateNode(int minduration, int maxduration, double threshold):
+ minduration(minduration), maxduration(maxduration), threshold(threshold)
+{
+}
+
+bool StateNode::isSatisfied(double value) const {
+ if (threshold > 0)
+ return value >= threshold;
+ else
+ return value <= -threshold;
+}
+
+LinearStateSystem::LinearStateSystem(const vector<StateNode> &states):
+ states(states), currentState(0), duration(0)
+{
+ assert(!states.empty());
+}
+
+void LinearStateSystem::updateState(double value) {
+ cout << "update state: " << value << endl;
+ duration++;
+ if (currentState > 0 &&
+ ((duration < states[currentState].minduration &&
+ !states[currentState].isSatisfied(value)) ||
+ duration > states[currentState].maxduration))
+ setState(0);
+
+ if (!isFinalState() && states[currentState+1].isSatisfied(value))
+ setState(currentState+1);
+}
+
+void LinearStateSystem::setState(int state) {
+ currentState = state;
+ duration = 0;
+}
+
+int LinearStateSystem::getState() {
+ return currentState;
+}
+
+bool LinearStateSystem::isFinalState() {
+ return currentState == (int)states.size() - 1;
+}
+
+LambdaAccumulator::LambdaAccumulator(double lambda, double initial):
+ lambda(lambda), current(initial)
+{
+}
+
+void LambdaAccumulator::update(double value) {
+ current = (1-lambda)*current + lambda*value;
+}
+
+double LambdaAccumulator::getValue() {
+ return current;
+}
+
+BlinkDetector::BlinkDetector():
+ averageEye(cvCreateImage(EyeExtractor::eyesize, IPL_DEPTH_32F, 1)),
+ acc(0.1, 1000.0),
+ states(constructStates())
+{
+}
+
+vector<StateNode> BlinkDetector::constructStates() {
+ vector<StateNode> states;
+ states.push_back(StateNode(0, 0, +0.00));
+ states.push_back(StateNode(1, 8, +1.50));
+ states.push_back(StateNode(1, 8, -1.20)); // blink
+ states.push_back(StateNode(1, 8, +1.50));
+ states.push_back(StateNode(1, 8, -1.20)); // double blink
+ return states;
+}
+
+void BlinkDetector::update(const scoped_ptr<IplImage> &eyefloat) {
+ double distance = cvNorm(eyefloat.get(), averageEye.get(), CV_L2);
+ acc.update(distance);
+ cout << "update distance" << distance << " -> " << acc.getValue() << endl;
+ states.updateState(distance / acc.getValue());
+ cvRunningAvg(eyefloat.get(), averageEye.get(), 0.05);
+}
+
+int BlinkDetector::getState() {
+ return states.getState();
+}
View
@@ -0,0 +1,62 @@
+#pragma once
+#include "utils.h"
+#include "TrackingSystem.h"
+#include "Containers.h"
+#include "GraphicalPointer.h"
+#include "FeatureDetector.h"
+
+using std::vector;
+
+class FrameProcessing;
+
+class FrameFunction:
+public Containee<FrameProcessing, FrameFunction>
+{
+ const int &frameno;
+ int startframe;
+ protected:
+ int getFrame() { return frameno - startframe; }
+public:
+ FrameFunction(const int &frameno): frameno(frameno), startframe(frameno) {}
+ virtual void process()=0;
+ virtual ~FrameFunction();
+};
+
+class FrameProcessing:
+public ProcessContainer<FrameProcessing,FrameFunction> {};
+
+class MovingTarget: public FrameFunction {
+ shared_ptr<WindowPointer> pointer;
+ public:
+ MovingTarget(const int &frameno,
+ const vector<OpenGazer::Point>& points,
+ const shared_ptr<WindowPointer> &pointer,
+ int dwelltime=20);
+ virtual ~MovingTarget();
+ virtual void process();
+ protected:
+ vector<OpenGazer::Point> points;
+ const int dwelltime;
+ int getPointNo();
+ int getPointFrame();
+ bool active();
+};
+
+class Calibrator: public MovingTarget {
+ static const OpenGazer::Point defaultpointarr[];
+ shared_ptr<TrackingSystem> trackingsystem;
+ scoped_ptr<FeatureDetector> averageeye;
+public:
+ static vector<OpenGazer::Point> defaultpoints;
+ static vector<OpenGazer::Point> loadpoints(istream& in);
+ Calibrator(const int &frameno,
+ const shared_ptr<TrackingSystem> &trackingsystem,
+ const vector<OpenGazer::Point>& points,
+ const shared_ptr<WindowPointer> &pointer,
+ int dwelltime=20);
+ virtual ~Calibrator();
+ virtual void process();
+ static vector<OpenGazer::Point> scaled(const vector<OpenGazer::Point>& points, double x, double y);
+};
+
+
View
@@ -0,0 +1,123 @@
+#include "Calibrator.h"
+
+Calibrator::~Calibrator() {
+#ifdef DEBUG
+ cout << "Destroying calibrator" << endl;
+#endif
+}
+
+FrameFunction::~FrameFunction() {
+#ifdef DEBUG
+ cout << "Destroying framefunction" << endl;
+#endif
+}
+
+MovingTarget::MovingTarget(const int &frameno,
+ const vector<OpenGazer::Point>& points,
+ const shared_ptr<WindowPointer> &pointer,
+ int dwelltime):
+ FrameFunction(frameno),
+ points(points), dwelltime(dwelltime), pointer(pointer)
+{
+};
+
+MovingTarget::~MovingTarget() {
+ int id = getFrame() / dwelltime;
+}
+
+void MovingTarget::process() {
+ if (active()) {
+ int id = getPointNo();
+ if (getPointFrame() == 1)
+ pointer->setPosition((int)points[id].x, (int)points[id].y);
+ }
+ else
+ detach();
+}
+
+bool MovingTarget::active() {
+ return getPointNo() < (int) points.size();
+}
+
+int MovingTarget::getPointNo() {
+ return getFrame() / dwelltime;
+}
+
+int MovingTarget::getPointFrame() {
+ return getFrame() % dwelltime;
+}
+
+Calibrator::Calibrator(const int &framecount,
+ const shared_ptr<TrackingSystem> &trackingsystem,
+ const vector<OpenGazer::Point>& points,
+ const shared_ptr<WindowPointer> &pointer,
+ int dwelltime):
+ MovingTarget(framecount, points, pointer, dwelltime),
+ trackingsystem(trackingsystem)
+{
+ trackingsystem->gazetracker.clear();
+ // todo: remove all calibration points
+}
+
+
+void Calibrator::process() {
+ if (active()) {
+ int id = getPointNo();
+ int frame = getPointFrame();
+ if (frame == 1) // start
+ averageeye.reset(new FeatureDetector(EyeExtractor::eyesize));
+
+ if (frame >= dwelltime/2) // middle
+ averageeye->addSample(trackingsystem->eyex.eyefloat.get());
+
+ if (frame == dwelltime-1) { // end
+ trackingsystem->gazetracker.
+ addExemplar(points[id], averageeye->getMean().get(),
+ trackingsystem->eyex.eyegrey.get());
+ }
+ }
+ MovingTarget::process();
+}
+
+const OpenGazer::Point Calibrator::defaultpointarr[] = {OpenGazer::Point(0.5, 0.5),
+ OpenGazer::Point(0.1, 0.5), OpenGazer::Point(0.9, 0.5),
+ OpenGazer::Point(0.5, 0.1), OpenGazer::Point(0.5, 0.9),
+ OpenGazer::Point(0.1, 0.1), OpenGazer::Point(0.1, 0.9),
+ OpenGazer::Point(0.9, 0.9), OpenGazer::Point(0.9, 0.1),
+ OpenGazer::Point(0.3, 0.3), OpenGazer::Point(0.3, 0.7),
+ OpenGazer::Point(0.7, 0.7), OpenGazer::Point(0.7, 0.3)};
+
+vector<OpenGazer::Point>
+Calibrator::defaultpoints(Calibrator::defaultpointarr,
+ Calibrator::defaultpointarr+
+ (sizeof(Calibrator::defaultpointarr) /
+ sizeof(Calibrator::defaultpointarr[0])));
+
+vector<OpenGazer::Point> Calibrator::loadpoints(istream& in) {
+ vector<OpenGazer::Point> result;
+
+ for(;;) {
+ double x, y;
+ in >> x >> y;
+ if (in.rdstate()) break; // break if any error
+ result.push_back(OpenGazer::Point(x, y));
+ }
+
+ return result;
+}
+
+vector<OpenGazer::Point> Calibrator::scaled(const vector<OpenGazer::Point> &points,
+ double x, double y)
+{
+// double dx = x > y ? (x-y)/2 : 0.0;
+// double dy = y > x ? (y-x)/2 : 0.0;
+// double scale = x > y ? y : x;
+
+ vector<OpenGazer::Point> result;
+
+ xforeach(iter, points)
+ result.push_back(OpenGazer::Point(iter->x * x, iter->y * y));
+// result.push_back(OpenGazer::Point(iter->x * scale + dx, iter->y * scale + dy));
+
+ return result;
+}
Oops, something went wrong.

0 comments on commit da13133

Please sign in to comment.