OpenCV—绘图相关函数

OpenCV—绘图相关函数

1、circle

CV_EXPORTS_W void circle(InputOutputArray img,           // 输入图像 
                         Point center,                   // 圆心 
                         int radius,                     // 半径 
                         const Scalar& color,            // 颜色 
                         int thickness = 1,              // 线宽
                         int lineType = LINE_8,          // 线型  4 or 8
                         int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat frame = cv::imread("G:\\proj\\opencv\\data\\pic\\1.JPG");

    cv::circle(frame,Point(334,246),200,Scalar(10,234,34),1); //thickness = -1 实心的
    imshow("1",frame);
    waitKey(0);
    return 0;
}

在这里插入图片描述
令 thickness = -1, 实心的
在这里插入图片描述

2 、ellipse() 椭圆

CV_EXPORTS_W void ellipse(InputOutputArray img,     // 图像 
                          Point center,             // 中心点
                          Size axes,                // 长轴,短轴  
                          double angle,             // 角度 
                          double startAngle,        // 起始角 
                          double endAngle,          // 结束角
                          const Scalar& color,      // 颜色 
                          int thickness = 1,
                          int lineType = LINE_8, 
                          int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat img =  cv::Mat::zeros(640,640,CV_8UC3);
    cv::ellipse(img,Point(320,320),Size(100,50),0,0,360,Scalar(10,234,34));
    imshow("2",img);
    waitKey(0);
    return 0;
}

在这里插入图片描述

3、fillPoly()填充多边形

CV_EXPORTS void fillPoly(Mat& img, 
						 const Point** pts,     // 二维点数组
                         const int* npts,       // 点个数
                         int ncontours,         //  
                         const Scalar& color,   // 颜色
                         int lineType = LINE_8, 
                         int shift = 0,
                         Point offset = Point() );
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
   
    Mat img =  cv::Mat::zeros(640,640,CV_8UC3);
    Point poly_points[1][5];
    poly_points[0][0] = Point(330,100);
    poly_points[0][1] = Point(280, 150);
    poly_points[0][2] = Point(280, 250);
    poly_points[0][3] = Point(380, 250);
    poly_points[0][4] = Point(380, 150);

    const Point* ppt[1] = { poly_points[0] };
    int npt[] = {5};
    cv::fillPoly(img, ppt, npt, 1,Scalar(0,240,0));
    imshow("Test", img);


    waitKey(0);
    return 0;
}

在这里插入图片描述

4、line()直线

CV_EXPORTS_W void line(InputOutputArray img, 
                       Point pt1, 
                       Point pt2, 
                       const Scalar& color,
                       int thickness = 1, 
                       int lineType = LINE_8, 
                       int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat img =  cv::Mat::zeros(640,640,CV_8UC3);
    cv::line(img,Point(100,100),Point(400,400),Scalar(100,10,100),2);
    imshow("3", img);
    waitKey(0);
    return 0;
}

在这里插入图片描述

5、rectangle() 画矩形

CV_EXPORTS_W void rectangle(InputOutputArray img, 
                            Point pt1, 
                            Point pt2,
                            const Scalar& color, 
                            int thickness = 1,
                            int lineType = LINE_8, 
                            int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
    Mat img =  cv::Mat::zeros(640,640,CV_8UC3);
    cv::line(img,Point(100,100),Point(400,400),Scalar(100,100,100),2);
    cv::rectangle(img,Point(100,100),Point(400,400),Scalar(100,10,100),2);
    imshow("3", img);

    waitKey(0);
    return 0;
}

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FlyDremever

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值