Delaunay triangulation opencv c++

后端 未结 1 1085
眼角桃花
眼角桃花 2021-02-04 13:50

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

1条回答
  •  借酒劲吻你
    2021-02-04 14:16

    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);
          }
    
    
        }
    }
    

    0 讨论(0)
提交回复
热议问题