菜鸟一枚
这是我的第二个博客,
刚刚入门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);
}
程序运行效果图:
谢谢大家的阅读!!!