概述
这个函数用于绘制一个填充的多边形。
函数
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 | 指向数组,包含多边形的顶点坐标,必须是const修饰 |
npts | 指向数组,包含多边形的顶点数量 |
ncontours | 绘制图形的数量 |
color | 填充的颜色 |
lineType | 边缘线条的类型 |
shift | 顶点坐标中的小数位数 |
offset | 轮廓的所有点的可选偏移 |
测试代码
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
using namespace cv;
using namespace std;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//新建一个图像
cv::Mat mat(500,600,CV_8UC3,Scalar(200,200,200));
//定义二维数组
Point points[2][4];
//定义第一个图形的坐标点
points[0][0]=Point(100,100);
points[0][1]=Point(450,80);
points[0][2]=Point(360,200);
points[0][3]=Point(170,250);
//定义第二个图形的坐标点
points[1][0]=Point(330,270);
points[1][1]=Point(460,300);
points[1][2]=Point(430,420);
points[1][3]=Point(290,430);
//定义一个指针数组,指向坐标数组
const Point* ppt[2]= {points[0],points[1]};
//定义一个数组,包含绘制图形的顶点数量
int npt[]= {4,4};
//绘制图形
cv::fillPoly(mat,ppt,npt,2,Scalar(0,255,0));
//显示
imshow("mat",mat);
}
Widget::~Widget()
{
delete ui;
}