Qt-OpenCV学习笔记--绘制填充多边形--fillPoly()

概述

这个函数用于绘制一个填充的多边形。

函数

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

测试结果

参考

【OpenCV】OpenCV的fillPoly函数

OpenCV中绘制多边形的fillPoly和polylines函数

opencv 3.0 填充矩形 填充多边形 fillPoly

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值