Hi
I’m implementing ofxDelaunay2D to triangulate a human silhouette. The triangulation basically works, however it draws triangles outside the user shape.
I calculated the centre triangle and then checked if there is a human shape on that point, having a kind of descent better shape, but still with errors, for example when user rises the arms, that calculated centre point touches the head and then it paints a triangle from the hands through the head.
What would be the best technique?
My approach is this one:
m_points are the user silhouette points
userTriangulation is the result after filtering.
m_triangulation = ofxDelaunay2D::triangulate(m_points);
userTriangulation.clear();
int numTtiangles = m_triangulation.getNumIndices() / 3;
if (numTtiangles > 3){
for (int t=0; t<numTtiangles; t++) {
//Get indices of the triangle t
int i1 = m_triangulation.getIndex( 3 * t );
int i2 = m_triangulation.getIndex( 3 * t + 1 );
int i3 = m_triangulation.getIndex( 3 * t + 2 );
//Get vertices of the triangle
const ofPoint &p1 = m_triangulation.getVertex( i1 );
const ofPoint &p2 = m_triangulation.getVertex( i2 );
const ofPoint &p3 = m_triangulation.getVertex( i3 );
//find the center point for each triangle
float x = (p1.x + p2.x + p3.x)/3.0;
float y = (p1.y + p2.y + p3.y)/3.0;
centerPoints.push_back(ofVec2f(x,y));
ofPixels spixels = userMask.getPixels();
int px = CLAMP(x,0,W);
int py = CLAMP(y,0,H);
int index = py*W + px;
int gray = spixels[index];
if(gray == 255){
userTriangulation.addVertex(p1);
userTriangulation.addVertex(p2);
userTriangulation.addVertex(p3);
}
}
}