#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void drawLine(Mat &image);
void drawRectangle(Mat& image);
void drawEllipse(Mat& image);
void drawCricle(Mat& image);
int main()
{
Mat MyBG = imread("C:/Users/zhou_/Desktop/1.png");
drawLine(MyBG);
drawRectangle(MyBG);
drawEllipse(MyBG);
drawCricle(MyBG);
//MyBG是背景图,"666"是画上去的文字,Point表示画的起点
//FONT_HERSHEY_SIMPLEX是字体,2表示粗细
//Scalar是颜色,3是代表字体的线条宽度
putText(MyBG, "666", Point(200, 50), \
FONT_HERSHEY_SIMPLEX, 2, Scalar(255, 0, 0),\
3, LINE_AA);
imshow("BG", MyBG);
waitKey(0);
return 0;
}
void drawLine(Mat& image)
{
//Point是点的数据结构
Point p1(0, 0);
Point p2(533, 300);
Scalar color = Scalar(255, 0, 0);
//image表示在哪儿画,p1,p2是线段的端点,color是线的颜色,3代表线的粗细,LINE_AA表示反走样
line(image, p1, p2, color,3,LINE_AA);
}
void drawRectangle(Mat& image)
{
//在坐标(100,100)处,画一个长和宽都是100的矩形
Rect rect = Rect(100, 100, 100, 100);
Scalar color = Scalar(0, 255, 0);
//rect表示要画的矩形形状如何。
rectangle(image, rect, color, 1, LINE_AA);
}
void drawEllipse(Mat& image)
{
Scalar color = Scalar(0, 0, 255);
//image表示在哪儿画,Point表示椭圆的中心,Size表示椭圆的长短半轴的长度
//第一个0表示从0位置开始画
//第二个0和360表示画的椭圆的范围是0-360°
ellipse(image, Point(image.cols / 2, image.rows / 2),\
Size(image.cols / 2, image.rows / 4),\
0, 0, 360, color, 2, LINE_AA);
}
void drawCricle(Mat& image)
{
Point center(image.cols / 2, image.rows / 2);
int r = 100;
Scalar color = Scalar(0, 0, 0);
//center表示圆心,r是圆的半径
circle(image, center, r, color, 3, LINE_AA);
}
运行效果如下所示:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有