Last active
November 5, 2019 11:24
-
-
Save aaronsherwood/00aadb6e9ee97b4cfcec0b1b38337060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CLOSEST | |
{ | |
int closest = 0; | |
float closestX=0; | |
float closestY=0; | |
ofPixels & pix = grayImage.getPixels(); | |
for (int y=0;y<depthHeight;y++){ | |
for (int x=0; x<depthWidth; x++) { | |
int index = x+y*depthWidth; | |
if(pix[index] < nearThreshold && pix[index] > farThreshold) { | |
if (pix[index]>closest){ | |
closest=pix[index]; | |
closestX=x; | |
closestY=y; | |
} | |
pix[index] = 255; | |
} else { | |
pix[index] = 0; | |
} | |
} | |
} | |
if (closestX>0 || closestY>0){ | |
trackingX=closestX; | |
trackingY=closestY; | |
} | |
} | |
//AVERAGE | |
{ | |
int amount = 0; | |
float averageX = 0; | |
float averageY = 0; | |
ofPixels & pix = grayImage.getPixels(); | |
for (int y=0;y< depthHeight;y++){ | |
for (int x=0; x<depthWidth; x++) { | |
int index = x+y*depthWidth; | |
if(pix[index] < nearThreshold && pix[index] > farThreshold) { | |
averageX += x; | |
averageY += y; | |
amount ++; | |
pix[index] = 255; | |
} else { | |
pix[index] = 0; | |
} | |
} | |
} | |
if (amount>0){ | |
averageX /= amount; | |
averageY /= amount; | |
trackingX=averageX; | |
trackingY=averageY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment