static void draw_subdiv( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color ) { #if 1 vector<Vec6f> triangleList; subdiv.getTriangleList(triangleList); vector<Point> 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])); line(img, pt[0], pt[1], delaunay_color, 1, CV_AA, 0); line(img, pt[1], pt[2], delaunay_color, 1, CV_AA, 0); line(img, pt[2], pt[0], delaunay_color, 1, CV_AA, 0); } #else vector<Vec4f> edgeList; subdiv.getEdgeList(edgeList); for( size_t i = 0; i < edgeList.size(); i++ ) { Vec4f e = edgeList[i]; Point pt0 = Point(cvRound(e[0]), cvRound(e[1])); Point pt1 = Point(cvRound(e[2]), cvRound(e[3])); line(img, pt0, pt1, delaunay_color, 1, CV_AA, 0); } #endif }
void AAM::displayTriangulation(Subdiv2D subdiv) { Mat img=Mat::zeros(ImageWidth, ImageHeight, CV_8UC1); Scalar delaunay_color=Scalar(255, 0, 0); bool draw; vector<Vec6f> triangleList; subdiv.getTriangleList(triangleList); vector<Point> pt(3); for(int 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])); draw=true; for(int i=0;i<3;i++) { if(pt[i].x>img.rows||pt[i].y>img.cols||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); } } imshow("triangulacja", img); }
// Draw delaunay triangles static void draw_delaunay( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color ) { vector<Vec6f> triangleList; subdiv.getTriangleList(triangleList); vector<Point> pt(3); Size size = img.size(); Rect rect(0,0, size.width, size.height); 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])); // Draw rectangles completely inside the image. if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2])) { line(img, pt[0], pt[1], delaunay_color, 1, CV_AA, 0); line(img, pt[1], pt[2], delaunay_color, 1, CV_AA, 0); line(img, pt[2], pt[0], delaunay_color, 1, CV_AA, 0); } } }
static void draw_subdiv( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color ) { vector<Vec6f> triangleList; subdiv.getTriangleList(triangleList); vector<Point> 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])); bool draw=true; for(int i=0;i<3;i++){ if(pt[i].x>img.cols||pt[i].y>img.rows||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); } } }