Permalink
Please sign in to comment.
Showing
with
12,507 additions
and 0 deletions.
- +22 −0 .gitattributes
- +189 −0 .gitignore
- +75 −0 ConicSection.h
- +91 −0 EyeTab.cpp
- +40 −0 ReadMe.txt
- +64 −0 erase_specular.cpp
- +5 −0 erase_specular.h
- +144 −0 eye_center.cpp
- +7 −0 eye_center.h
- +223 −0 fit_ellipse.cpp
- +4 −0 fit_ellipse.h
- +114 −0 gaze_geometry.cpp
- +15 −0 gaze_geometry.h
- +40 −0 gaze_smoothing.cpp
- +6 −0 gaze_smoothing.h
- +174 −0 gaze_system.cpp
- +5 −0 gaze_system.h
- +106 −0 get_eyelids.cpp
- +11 −0 get_eyelids.h
- +109 −0 get_poss_limb_pts.cpp
- +5 −0 get_poss_limb_pts.h
- +10,930 −0 haarcascade_mcs_eyepair_big.xml
- BIN images/SS_0.jpg
- BIN images/SS_1.jpg
- BIN images/SS_2.jpg
- BIN images/SS_3.jpg
- BIN images/SS_4.jpg
- BIN images/SS_5.jpg
- BIN images/SS_6.jpg
- BIN images/andreas1_r.png
- BIN images/erroll1_l.png
- BIN images/phil1_l.png
- BIN images/poppy.jpg
- +8 −0 stdafx.cpp
- +15 −0 stdafx.h
- +8 −0 targetver.h
- +17 −0 utils.cpp
- +80 −0 utils.h
| @@ -0,0 +1,22 @@ | |||
| +# Auto detect text files and perform LF normalization | |||
| +* text=auto | |||
| + | |||
| +# Custom for Visual Studio | |||
| +*.cs diff=csharp | |||
| +*.sln merge=union | |||
| +*.csproj merge=union | |||
| +*.vbproj merge=union | |||
| +*.fsproj merge=union | |||
| +*.dbproj merge=union | |||
| + | |||
| +# Standard to msysgit | |||
| +*.doc diff=astextplain | |||
| +*.DOC diff=astextplain | |||
| +*.docx diff=astextplain | |||
| +*.DOCX diff=astextplain | |||
| +*.dot diff=astextplain | |||
| +*.DOT diff=astextplain | |||
| +*.pdf diff=astextplain | |||
| +*.PDF diff=astextplain | |||
| +*.rtf diff=astextplain | |||
| +*.RTF diff=astextplain | |||
189
.gitignore
| @@ -0,0 +1,75 @@ | |||
| +#ifndef __CONIC_SECTION_H__ | |||
| +#define __CONIC_SECTION_H__ | |||
| + | |||
| +// From http://www.cl.cam.ac.uk/research/rainbow/projects/pupiltracking/ | |||
| + | |||
| +template<typename T> | |||
| +class ConicSection_ | |||
| +{ | |||
| +public: | |||
| + T A,B,C,D,E,F; | |||
| + | |||
| + ConicSection_(cv::RotatedRect r) | |||
| + { | |||
| + cv::Point_<T> axis((T)std::cos(CV_PI/180.0 * r.angle), (T)std::sin(CV_PI/180.0 * r.angle)); | |||
| + cv::Point_<T> centre(r.center); | |||
| + T a = r.size.width/2; | |||
| + T b = r.size.height/2; | |||
| + | |||
| + initFromEllipse(axis, centre, a, b); | |||
| + } | |||
| + | |||
| + T algebraicDistance(cv::Point_<T> p) | |||
| + { | |||
| + return A*p.x*p.x + B*p.x*p.y + C*p.y*p.y + D*p.x + E*p.y + F; | |||
| + } | |||
| + | |||
| + T distance(cv::Point_<T> p) | |||
| + { | |||
| + // dist | |||
| + // ----------- | |||
| + // |grad|^0.45 | |||
| + | |||
| + T dist = algebraicDistance(p); | |||
| + cv::Point_<T> grad = algebraicGradient(p); | |||
| + | |||
| + T sqgrad = grad.dot(grad); | |||
| + | |||
| + return dist / std::pow(sqgrad, T(0.45/2)); | |||
| + } | |||
| + | |||
| + cv::Point_<T> algebraicGradient(cv::Point_<T> p) | |||
| + { | |||
| + return cv::Point_<T>(2*A*p.x + B*p.y + D, B*p.x + 2*C*p.y + E); | |||
| + } | |||
| + | |||
| + cv::Point_<T> algebraicGradientDir(cv::Point_<T> p) | |||
| + { | |||
| + cv::Point_<T> grad = algebraicGradient(p); | |||
| + T len = std::sqrt(grad.ddot(grad)); | |||
| + grad.x /= len; | |||
| + grad.y /= len; | |||
| + return grad; | |||
| + } | |||
| + | |||
| +protected: | |||
| + void initFromEllipse(cv::Point_<T> axis, cv::Point_<T> centre, T a, T b) | |||
| + { | |||
| + T a2 = a * a; | |||
| + T b2 = b * b; | |||
| + | |||
| + A = axis.x*axis.x / a2 + axis.y*axis.y / b2; | |||
| + B = 2*axis.x*axis.y / a2 - 2*axis.x*axis.y / b2; | |||
| + C = axis.y*axis.y / a2 + axis.x*axis.x / b2; | |||
| + D = (-2*axis.x*axis.y*centre.y - 2*axis.x*axis.x*centre.x) / a2 | |||
| + + (2*axis.x*axis.y*centre.y - 2*axis.y*axis.y*centre.x) / b2; | |||
| + E = (-2*axis.x*axis.y*centre.x - 2*axis.y*axis.y*centre.y) / a2 | |||
| + + (2*axis.x*axis.y*centre.x - 2*axis.x*axis.x*centre.y) / b2; | |||
| + F = (2*axis.x*axis.y*centre.x*centre.y + axis.x*axis.x*centre.x*centre.x + axis.y*axis.y*centre.y*centre.y) / a2 | |||
| + + (-2*axis.x*axis.y*centre.x*centre.y + axis.y*axis.y*centre.x*centre.x + axis.x*axis.x*centre.y*centre.y) / b2 | |||
| + - 1; | |||
| + } | |||
| +}; | |||
| +typedef ConicSection_<float> ConicSection; | |||
| + | |||
| +#endif // __CONIC_SECTION_H__ | |||
91
EyeTab.cpp
| @@ -0,0 +1,91 @@ | |||
| +#include "stdafx.h" | |||
| + | |||
| +#include <opencv2/objdetect/objdetect.hpp> | |||
| +#include <opencv2/highgui/highgui.hpp> | |||
| +#include <opencv2/imgproc/imgproc.hpp> | |||
| + | |||
| +#include <iostream> | |||
| +#include <stdio.h> | |||
| +#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */ | |||
| +#include <math.h> /* floor */ | |||
| + | |||
| +#include "eye_center.h" | |||
| +#include "erase_specular.h" | |||
| +#include "get_poss_limb_pts.h" | |||
| +#include "fit_ellipse.h" | |||
| +#include "utils.h" | |||
| +#include "get_eyelids.h" | |||
| +#include "gaze_system.h" | |||
| +#include "gaze_smoothing.h" | |||
| + | |||
| +using namespace std; | |||
| +using namespace cv; | |||
| + | |||
| +int num_screenshots = 0; | |||
| +String screenshot_filename; | |||
| + | |||
| +int main(int argc, const char** argv) | |||
| +{ | |||
| + // init modules | |||
| + lin_polar_init(); | |||
| + gaze_system_init(); | |||
| + //init_gaze_smoothing(); | |||
| + | |||
| + //setup video capture device | |||
| + // VideoCapture cap("C:\\Users\\Erroll\\Documents\\Part 3 Project (local)\\Gaze Data\\P01\\P01_L2_D1_20130517_133459.mp4"); | |||
| + // VideoCapture cap("C:\\Users\\Erroll\\Documents\\Part 3 Project (local)\\Gaze Data\\P03\\P03_L1_D1_20130517_163141.mp4"); | |||
| + // VideoCapture cap("C:\\Users\\Erroll\\Documents\\Part 3 Project (local)\\Gaze Data\\P06\\P06_L1_D1_20130520_154535.mp4"); | |||
| + | |||
| + int cam_idx = argc > 1 ? atoi(argv[1]) : 0; | |||
| + VideoCapture cap(cam_idx); | |||
| + cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280); | |||
| + cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720); | |||
| + | |||
| + bool rot_180 = argc > 2 ? true : false; | |||
| + | |||
| + //setup image files used in the capture process | |||
| + Mat captureFrame, grayscaleFrame, smallFrame; | |||
| + | |||
| + //create a window to present the results | |||
| + namedWindow("outputCapture", 1); | |||
| + //namedWindow("Gaze Output", 1); | |||
| + //moveWindow("Gaze Output", 0, 0); | |||
| + | |||
| + //create a loop to capture and find eye-pairs | |||
| + while(true) | |||
| + { | |||
| + clock_t start = clock(); | |||
| + | |||
| + //capture a new image frame | |||
| + cap >> captureFrame; | |||
| + // captureFrame = imread("images\\SS_0.jpg", CV_LOAD_IMAGE_COLOR); | |||
| + // flip(captureFrame,captureFrame,1); | |||
| + | |||
| + if (rot_180) | |||
| + flip(captureFrame, captureFrame, -1); | |||
| + | |||
| + //convert captured image to gray scale and equalize | |||
| + cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY); | |||
| + equalizeHist(grayscaleFrame, grayscaleFrame); | |||
| + | |||
| + track_gaze(captureFrame, grayscaleFrame); | |||
| + | |||
| + // Show calculated FPS | |||
| + String fps_string = to_string(int(1 / ( ((float)clock()-start) / CLOCKS_PER_SEC ))) + " FPS"; | |||
| + putText(captureFrame, fps_string, Point2i(11, 21), FONT_HERSHEY_SIMPLEX, 0.5, BLACK); | |||
| + putText(captureFrame, fps_string, Point2i(10, 20), FONT_HERSHEY_SIMPLEX, 0.5, WHITE); | |||
| + | |||
| + // Show the output | |||
| + imshow("outputCapture", captureFrame); | |||
| + | |||
| + switch (waitKey(5)){ | |||
| + case 's': | |||
| + screenshot_filename = "SS_" + to_string(num_screenshots++); | |||
| + imwrite(screenshot_filename + ".jpg", captureFrame); | |||
| + break; | |||
| + case 'q': return 0; | |||
| + } | |||
| + } | |||
| + | |||
| + return 0; | |||
| +} | |||
Oops, something went wrong.
0 comments on commit
613aa77