[C++] opencv - fillPoly(填充多边形)函数介绍和使用场景
创始人
2024-11-10 19:42:38
0

fillPoly函数介绍

fillPoly()函数是OpenCV中用于绘制填充多边形的函数。函数原型如下:

/** @brief Fills the area bounded by one or more polygons.  The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill complex areas, for example, areas with holes, contours with self-intersections (some of their parts), and so forth.  @param img Image. @param pts Array of polygons where each polygon is represented as an array of points. @param color Polygon color. @param lineType Type of the polygon boundaries. See #LineTypes @param shift Number of fractional bits in the vertex coordinates. @param offset Optional offset of all points of the contours.  */ CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,                            const Scalar& color, int lineType = LINE_8, int shift = 0,                            Point offset = Point() );  /** @overload */ CV_EXPORTS void fillPoly(InputOutputArray img, const Point** pts,                          const int* npts, int ncontours,                          const Scalar& color, int lineType = LINE_8, int shift = 0,                          Point offset = Point() );  函数参数说明如下:  img:输入图像。 pts:多边形数组,其中每个多边形由点数组表示。 color:多边形的颜色。 lineType:多边形边界的类型。参见#LineTypes。 shift:顶点坐标中的分数位数。 offset:轮廓的所有点的可选偏移量。 此外,还提供了一个重载版本的fillPoly函数,它接受一个const Point**类型的pts参数,以及一个const int*类型的npts参数和一个表示轮廓数量的整数ncontours。

使用场景

fillPoly()函数适用于需要绘制填充多边形的场景,例如在图像上绘制一个封闭的图形、制作一个简单的遮罩等。

使用案例

绘制实心三角形

#include  #include   using namespace cv; using namespace std;  int main() {     // 创建一个黑色背景的图像     Mat img = Mat::zeros(300, 300, CV_8UC3);      // 定义三角形三个顶点的坐标     Point points[1][3]; 	points[0][0] = Point(50, 50); 	points[0][1] = Point(150, 200); 	points[0][2] = Point(200, 50);       // 定义三角形的颜色     Scalar color(0, 255, 0);      // 将三角形的顶点坐标存储到数组中     const Point* ppts[1] = {points[0]};     const int npts[] = {3};     // 在图像上绘制实心三角形     fillPoly(img, ppts, npts, 1, color);      // 显示结果     imshow("实心三角形", img);     waitKey(0);      return 0; }

绘制实心矩形

#include  #include  #include  #include  using namespace cv; using namespace std;  int main() {     // 创建一个空白图像     Mat image = Mat::zeros(400, 400, CV_8UC3);      // 定义矩形的顶点     Point pts[4];     pts[0] = Point(50, 50);     pts[1] = Point(200, 50);     pts[2] = Point(200, 200);     pts[3] = Point(50, 200);      // 将顶点放入一个vector中     vector poly;     for (int i = 0; i < 4; i++)     {         poly.push_back(pts[i]);     }      // 填充矩形     fillPoly(image, poly, Scalar(255, 0, 0));      // 显示图像     imshow("实心矩形", image);     waitKey(0);      return 0; }

 

绘制实心多边形

#include  #include  using namespace cv; using namespace std;  int main() {     // 创建一个空白图像     Mat image = Mat::zeros(512, 512, CV_8UC3);      // 定义矩形的顶点     Point pts[5];     pts[0] = Point(100, 100);     pts[1] = Point(300, 150);     pts[2] = Point(300, 350);     pts[3] = Point(250, 450);     pts[4] = Point(50, 450);      // 将顶点放入一个vector中     vector poly;     for (int i = 0; i < 5; i++)     {         poly.push_back(pts[i]);     }      // 填充多边形     fillPoly(image, poly, Scalar(255, 0, 0));      // 显示图像     imshow("实心多边形", image);     waitKey(0);      return 0; }

结论

fillPoly()函数是OpenCV中用于绘制填充多边形的函数。可以用来绘制实心三角形,实心矩形,实心多边形等。

相关内容

热门资讯

三分钟辅助!川川云脚本破解,竟... 三分钟辅助!川川云脚本破解,竟然真的有辅助插件(确实有挂)川川云脚本破解辅助器是一种具有地方特色的麻...
第四分钟辅助!天天贵阳app修... 第四分钟辅助!天天贵阳app修改器,一直真的有辅助挂(有挂辅助)1、在天天贵阳app修改器插件功能辅...
2分钟辅助!新荣耀房卡辅助,竟... 2分钟辅助!新荣耀房卡辅助,竟然是有辅助插件(有挂功能)暗藏猫腻,小编详细说明新荣耀房卡辅助破解器有...
七分钟辅助!随意玩辅助器视频,... 七分钟辅助!随意玩辅助器视频,确实是有辅助插件(有挂解密)1、下载好随意玩辅助器视频正确养号方法之后...
第2分钟辅助!新西游辅助,真是... 第2分钟辅助!新西游辅助,真是真的是有辅助挂(有挂总结)1、新西游辅助辅助软件下载优化,新西游辅助底...
一分钟辅助!情怀娱乐辅助器,确... 一分钟辅助!情怀娱乐辅助器,确实是有辅助教程(有挂教学)1)情怀娱乐辅助器辅助插件:进一步探索情怀娱...
第六分钟辅助!云南捞腌菜辅助,... 第六分钟辅助!云南捞腌菜辅助,本来存在有辅助工具(有挂攻略)暗藏猫腻,小编详细说明云南捞腌菜辅助破解...
第二分钟辅助!四川游戏家园万能... 第二分钟辅助!四川游戏家园万能辅助工具,确实是真的有辅助工具(确实有挂)1、很好的工具软件,可以解锁...
复盘辅助挂!hhpoker辅助... 复盘辅助挂!hhpoker辅助器,wepoker辅助器怎么弄,指南教程(有挂细节)1)wepoker...
一分钟辅助!川南九九辅助,果然... 一分钟辅助!川南九九辅助,果然是有辅助插件(真实有挂)1、下载好川南九九辅助透视辅助下载之后点击打开...