I made a delaunay triangulation with openCv thanks to this code : example code (in partiluclar draw_subdiv). However, when I want to display the triangulation, I get the mesh a
Well I think it is easy. Just detect when the points are out of the image and dont draw them.
In your display function write:
void draw_subdiv(Mat &img, Subdiv2D& subdiv, Scalar delaunay_color)
{
bool draw;
vector triangleList;
subdiv.getTriangleList(triangleList);
vector pt(3);
for(size_t i = 0; i < triangleList.size(); ++i)
{
Vec6f t = triangleList[i];
pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
// MY PIECE OF CODE
draw=true;
for(int i=0;i<3;i++){
if(pt[i].x>img.width||pt[i].y>img.heigth||pt[i].x<0||pt[i].y<0)
draw=false;
}
if (draw){
line(img, pt[0], pt[1], delaunay_color, 1);
line(img, pt[1], pt[2], delaunay_color, 1);
line(img, pt[2], pt[0], delaunay_color, 1);
}
}
}