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

本文介绍使用fillConvexPoly函数高效绘制填充凸多边形的方法。该函数不仅速度快,还可以处理无自交点的单调多边形。通过示例代码展示了如何在OpenCV中应用此函数,并给出了具体参数说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

综述

fillConvexPoly绘制一个填充的凸多边形。
这个函数比fillPoly函数快得多。它不仅可以填充凸多边形,也可以填充任何无自交点的单调多边形。

函数

void fillConvexPoly
(
    InputOutputArray img,
    InputArray points,
    const Scalar& color,
    int lineType = LINE_8,
    int shift = 0
);
img输出目标
points顶点坐标集合
color填充颜色
linType边线类型
shift顶点坐标中的小数位数。

测试代码

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

    vector<Point> pts;
    pts.push_back(Point(100,100));
    pts.push_back(Point(300,50));
    pts.push_back(Point(510,150));
    pts.push_back(Point(300,330));
    pts.push_back(Point(150,220));

    cv::Scalar color(0,255,0);

    fillConvexPoly(mat,pts,color,8);

    //显示
    imshow("mat",mat);

}

Widget::~Widget()
{
    delete ui;
}

测试结果

参考

OpenCV 填充多边形 fillConvexPoly 和 fillPoly

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值