Skip to content

Instantly share code, notes, and snippets.

@aaronsherwood
Last active November 5, 2019 11:24
Show Gist options
  • Save aaronsherwood/00aadb6e9ee97b4cfcec0b1b38337060 to your computer and use it in GitHub Desktop.
Save aaronsherwood/00aadb6e9ee97b4cfcec0b1b38337060 to your computer and use it in GitHub Desktop.
//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