Opencv-学习笔记(二)-画图

菜鸟一枚
这是我的第二个博客,
刚刚入门opencv,
想将自己的学习过程分享给大家!!!

#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>    //Opencv highgui 模块
#include <opencv2/imgproc/imgproc.hpp>    //Opencv 图像处理头文件

using namespace cv;

Mat srcImage;

void aline();
void arect();
void aellipse();
void acircle();
void astuff();

int main()
{
	srcImage = imread("D:/opencv/opencvSRC/dog.jpg");   //载入原图
	aline();
	arect();
	aellipse();
	acircle();
	astuff();
	putText(srcImage, "Holle Opencv !", Point(250, 450), CV_FONT_HERSHEY_COMPLEX, 1.0, Scalar(255, 0, 85), 1, 8);  //输出文本文字

	imshow("画形状", srcImage);

	waitKey(0);

	return 0;
}

void aline()     //画直线
{
	Point p1 = Point(10, 8);   //p1点
	Point p2 = Point(500, 300);  //p2点
	line(srcImage, p1, p2, Scalar(155, 50, 255), 3, 8);
}

void arect()   //画矩形
{
	Rect rect = Rect(200, 100, 300, 300);
	Scalar color = Scalar(255, 0, 85);
	rectangle(srcImage, rect, color, 3, 8);
}

void aellipse()  //画椭圆
{
	ellipse(srcImage, Point(srcImage.cols / 2, srcImage.rows / 2), Size(srcImage.cols / 4, srcImage.rows / 8), 0, 0, 360, Scalar(255, 0, 85), 2, 8);
}

void acircle()  //画圆
{
	circle(srcImage, Point(srcImage.cols / 2, srcImage.rows / 2), 150, Scalar(155, 50, 255), 3, 8);
}

void astuff()  //画填充
{
	Point pts[1][5];   //构成区域
	pts[0][0] = Point(100, 100);
	pts[0][1] = Point(100, 200);
	pts[0][2] = Point(200, 200);
	pts[0][3] = Point(200, 100);
	pts[0][4] = Point(100, 100);

	const Point*ppts[] = { pts[0] };
	int npt[] = { 5 };
	Scalar color = Scalar(255, 0, 85);
	fillPoly(srcImage, ppts, npt, 1, color, 8);
}
  程序运行效果图:

在这里插入图片描述

谢谢大家的阅读!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值