hi all! thanks in advance for stopping by and looking at my topic.
i’m working on a project that involves detecting faces from a webcam and essentially removing the rest of video where the faces are not being detected (by making those pixels black, transparent, etc). the only relevant pixels are those that make up the detected faces.
right now i’m doing this with ofxFaceTracker2 by finding faces and their regions of interest before getting the polylines that represent each face outline. where i’m having trouble is understanding how to extract each face and draw only the detected faces to the buffer.
right now, i go through each pixel, check if it is outside the face polylines, and if it is, then set those pixels to a single color, while doing nothing to the pixels inside the face polyline. i load those pixels into an oftexture which is what i end up using in draw(). this kind of works, except it’s slow, and when there’s more than one face, neither face gets drawn and i only get the background color.
i have a few vectors that i prepare in setup:
for (int i = 0; i < MAX_FACES; i++)
{
faces.push_back(ofPolyline());
faceBounds.push_back(ofRectangle());
}
before finding faces in update:
void ofApp::update(){
....
cam.update();
if(cam.isFrameNew())
{
faceTracker.update(cam);
if (faceTracker.size() > 0)
{
for (std::size_t i = 0; i < faceTracker.getInstances().size(); i++)
{
ofxFaceTracker2Instance instance = faceTracker.getInstances()[i];
faces[i] = instance.getLandmarks().getImageFeature(ofxFaceTracker2Landmarks::FACE_OUTLINE);
faceBounds[i] = instance.getBoundingBox();
}
isolateFace();
}
}
....
}
and then using isolateFace():
void ofApp::isolateFace(){
ofPixels & pixels = cam.getPixels();
std::cout << faceTracker.getInstances().size() << std::endl;
for (std::size_t x = 0; x < pixels.getWidth(); x++)
{
for (std::size_t y = 0; y < pixels.getHeight(); y++)
{
glm::vec3 point = glm::vec3(x, y, 0);
for (std::size_t i = 0; i < faceTracker.getInstances().size(); i++)
{
if (!faces[i].inside(point.x, point.y))
{
pixels.setColor(x, y, ofColor(255));
}
else
{
}
}
}
}
facePixels = pixels;
faceTexture.loadData(facePixels);
and then in draw:
void ofApp::draw(){
...
faceTexture.draw(0, 0);
...
}
i haven’t really needed to work with pixels like this before so i’m not sure how to evaluate or compare this process, but i guess i’m just wondering if this way is effective for what i’d like to do? are there other ways to go about it that might make more sense, be more efficient, etc. also, are there names and terms for these processes because i had a hard time figuring out what to google, maybe some follow-up reading/videos on computer graphics i could look at that would be helpful? and ultimately, what’s wrong with how i’ve written this such that it only works for one face at a time, and not when multiple faces are present?
thanks! that’s all – am very appreciative of everyone’s time + energy.