Skip to content

Commit

Permalink
smoothing of glint blobs and recomputing the centroids from smoothed …
Browse files Browse the repository at this point in the history
…blobs
  • Loading branch information
kylemcdonald committed Oct 20, 2010
1 parent 620ed1e commit 1ad445b
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 14 deletions.
11 changes: 5 additions & 6 deletions eyeWriterTrackerCK/RemoteEyeTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
E47FBD8B1269010300937867 /* baseScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47FBD831269010300937867 /* baseScene.cpp */; };
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; };
E4B69E210A3A1BDC003C02F2 /* testApp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */; };
E4C2422B10CC554B004149E2 /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2421E10CC549C004149E2 /* openFrameworksDebug.a */; };
E4C2422B10CC554B004149E2 /* openFrameworks.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2421E10CC549C004149E2 /* openFrameworks.a */; };
E4C2424710CC5A17004149E2 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2424410CC5A17004149E2 /* AppKit.framework */; };
E4C2424810CC5A17004149E2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2424510CC5A17004149E2 /* Cocoa.framework */; };
E4C2424910CC5A17004149E2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2424610CC5A17004149E2 /* IOKit.framework */; };
Expand Down Expand Up @@ -475,7 +475,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E4C2422B10CC554B004149E2 /* openFrameworksDebug.a in Frameworks */,
E4C2422B10CC554B004149E2 /* openFrameworks.a in Frameworks */,
E45BE0AA0E8CC67C009D7055 /* GLee.a in Frameworks */,
E45BE2E40E8CC69C009D7055 /* rtAudio.a in Frameworks */,
E45BE97B0E8CC7DD009D7055 /* AGL.framework in Frameworks */,
Expand Down Expand Up @@ -1386,7 +1386,7 @@
E4C2421710CC549C004149E2 /* Products */ = {
isa = PBXGroup;
children = (
E4C2421E10CC549C004149E2 /* openFrameworksDebug.a */,
E4C2421E10CC549C004149E2 /* openFrameworks.a */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -1496,7 +1496,6 @@
isa = PBXProject;
buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "RemoteEyeTracker" */;
compatibilityVersion = "Xcode 2.4";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Expand All @@ -1521,10 +1520,10 @@
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
E4C2421E10CC549C004149E2 /* openFrameworksDebug.a */ = {
E4C2421E10CC549C004149E2 /* openFrameworks.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = openFrameworksDebug.a;
path = openFrameworks.a;
remoteRef = E4C2421D10CC549C004149E2 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
Expand Down
2 changes: 1 addition & 1 deletion eyeWriterTrackerCK/bin/data/Settings/inputSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- mode, input 0 = live, 1 = video -->

<mode>0</mode>
<mode>1</mode>


<!-- some per mode settings -->
Expand Down
59 changes: 55 additions & 4 deletions eyeWriterTrackerCK/src/Tracking/GlintFinder/glintFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,51 @@ void glintFinder::setup(int eyeWidth, int eyeHeight, float _magRatio, float IMwi

}

void glintFinder::smoothBlobs(vector<ofxCvBlob>& blobs, int smoothingSize, float smoothingAmount) {
for(int i = 0; i < blobs.size(); i++) {
// should precompute weightSum, weights, and total normalization
smoothBlob(blobs[i], smoothingSize, smoothingAmount);
}
}

void glintFinder::smoothBlob(ofxCvBlob& blob, int smoothingSize, float smoothingAmount) {
vector<ofPoint> ref = blob.pts;
vector<ofPoint>& cur = blob.pts;
int n = cur.size();
for(int i = 0; i < n; i++) {
cur[i].set(0, 0);
float weightSum = 0;
for(int j = 1; j <= smoothingSize; j++) {
int leftPosition = (n + i - j) % n;
int rightPosition = (i + j) % n;
ofPoint& left = ref[leftPosition];
ofPoint& right = ref[rightPosition];

float weight = ofMap(j, 0, smoothingSize, 1, smoothingAmount);
weightSum += weight;
cur[i] += (left + right) * weight;
}

ofPoint& center = ref[i];
cur[i] += center;
cur[i] /= 1 + 2 * weightSum;
}

recomputeCentroid(blob);
}

void glintFinder::recomputeCentroid(ofxCvBlob& blob) {
vector<ofPoint>& pts = blob.pts;
int n = pts.size();
blob.centroid.set(0, 0);
for(int i = 0; i < n; i++) {
blob.centroid += pts[i];
}
blob.centroid /= n;
}

//--------------------------------------------------------------------
bool glintFinder::update(ofxCvGrayscaleAdvanced & blackEyeImg, float threshold, float minBlobSize, float maxBlobSize, bool bUseBrightEyeCheck) {
bool glintFinder::update(ofxCvGrayscaleAdvanced & blackEyeImg, float threshold, float minBlobSize, float maxBlobSize, bool bUseBrightEyeCheck, int blobSmoothingSize, float blobSmoothingAmount) {

bFound = false;

Expand All @@ -64,7 +107,15 @@ bool glintFinder::update(ofxCvGrayscaleAdvanced & blackEyeImg, float threshold,
if (bFourGlints) nGlints = 4;
else nGlints = 2;

contourFinder.findContours(eyeImage, minBlobSize, maxBlobSize, nGlints + 4, true, true);
bool willSmooth = (blobSmoothingAmount > 0);
// if blobSmoothing is on, we need to make sure we're not approximating the contour
// otherwise the contour points won't be evenly distributed for the smoothing pass
contourFinder.findContours(eyeImage, minBlobSize, maxBlobSize, nGlints + 4, true, !willSmooth);

if(willSmooth) {
smoothBlobs(contourFinder.blobs, blobSmoothingSize, blobSmoothingAmount);
}

eyeImage.resetROI();

if (nGlints == 2){ // for now
Expand Down Expand Up @@ -237,7 +288,7 @@ void glintFinder::drawCross(ofPoint & pos, float x, float y, float width, float
void glintFinder::draw(float x, float y) {

// ofTranslate didn't work well easily because of glScissor.

ofEnableAlphaBlending();

ofSetColor(255,255,255);
Expand All @@ -258,7 +309,7 @@ void glintFinder::draw(float x, float y) {

ofSetColor(255, 255, 255);
ofDrawBitmapString("glintFinder", x + 1, y + eyeImage.height + 12);

}

//--------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion eyeWriterTrackerCK/src/Tracking/GlintFinder/glintFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ class glintFinder {
public:

void setup(int eyeWidth,int eyeHeight, float _magRatio, float IMwidth, float IMheight);
bool update(ofxCvGrayscaleAdvanced & blackEyeImg, float threshold, float minBlobSize, float maxBlobSize, bool bUseBrightEyeCheck);
bool update(ofxCvGrayscaleAdvanced & blackEyeImg, float threshold, float minBlobSize, float maxBlobSize, bool bUseBrightEyeCheck, int blobSmoothingSize, float blobSmoothingAmount);
void drawLine(float x, float y, float width, float height, float len);
void drawLineOnBrightGlint(float x, float y, float width, float height, float len);
void draw(float x, float y);
void findGlintCandidates(ofxCvGrayscaleAdvanced & eyeImg, float _threshold, float minBlobSize, float maxBlobSize, bool isBrightEye);
ofPoint getGlintPosition(int glintID);

void smoothBlobs(vector<ofxCvBlob>& blobs, int smoothingSize, float smoothingAmount);
void smoothBlob(ofxCvBlob& blob, int smoothingSize, float smoothingAmount);
void recomputeCentroid(ofxCvBlob& blob);

glintLineChecker gLineChecker;
ofxCvContourFinder contourFinder;
ofxCvContourFinder contourFinderBright;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void glintLineChecker::draw(int x, int y){
ofSetColor(255, 0, 0, 80);

myStripesImage.draw(x, y);
linesFinder.draw(x,y);
//linesFinder.draw(x,y);

ofDisableAlphaBlending();
}
Expand Down
2 changes: 1 addition & 1 deletion eyeWriterTrackerCK/src/Tracking/eyeTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void eyeTracker::update(ofxCvGrayscaleImage & grayImgFromCam) {
else threshold_g = threshold_g_frompanel;

// get glint position with dark eye image.
gFinder.update(magCurrentImg, threshold_g, minBlobSize_g, maxBlobSize_g, bUseGlintinBrightEye);
gFinder.update(magCurrentImg, threshold_g, minBlobSize_g, maxBlobSize_g, bUseGlintinBrightEye, blobSmoothingSize, blobSmoothingAmount);

if (gFinder.bFound){

Expand Down
2 changes: 2 additions & 0 deletions eyeWriterTrackerCK/src/Tracking/eyeTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class eyeTracker {
float threshold_g;
float minBlobSize_g;
float maxBlobSize_g;
float blobSmoothingAmount;
int blobSmoothingSize;

//Bright/Dark Threshold
bool bFoundOne;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void trackingManager::setupGui(){

panel.addSlider("min blob(glint)","MIN_BLOB_GLINT",5,0,2000,true);
panel.addSlider("max blob(glint)","MAX_BLOB_GLINT",500,0,20000,true);
panel.addSlider("blob smoothing size(glint)","GLINT_BLOB_SMOOTHING_SIZE",1,1,10,true);
panel.addSlider("blob smoothing amount(glint)","GLINT_BLOB_SMOOTHING_AMOUNT",0,0,1,false);

panel.addToggle("draw line(pupil)", "B_DRAW_LINE_P", true);
panel.addToggle("draw line(glint)", "B_DRAW_LINE_G", true);
Expand Down Expand Up @@ -290,6 +292,8 @@ void trackingManager::updateGui(){
tracker.threshold_g_frompanel = panel.getValueF("THRESHOLD_GLINT");
tracker.minBlobSize_g = panel.getValueF("MIN_BLOB_GLINT");
tracker.maxBlobSize_g = panel.getValueF("MAX_BLOB_GLINT");
tracker.blobSmoothingSize = panel.getValueI("GLINT_BLOB_SMOOTHING_SIZE");
tracker.blobSmoothingAmount = panel.getValueF("GLINT_BLOB_SMOOTHING_AMOUNT");

tracker.gFinder.pctGlintROIorigin.x = panel.getValueF("ROI_ORIGIN_X");
tracker.gFinder.pctGlintROIorigin.y = panel.getValueF("ROI_ORIGIN_Y");
Expand Down

0 comments on commit 1ad445b

Please sign in to comment.