DrawEllipse绘制椭圆函数用法
void DrawEllipse(Mat img,double angle)
{
int thickness=2;
int lineType = 8;
ellipse(img,
Point(window_width / 2, window_width / 2),
Size(window_width / 4, window_width / 16),
angle,
0,
360,
Scalar(255,199,0),
thickness,
lineType);
}
DrawFilledCircle画实心圆函数
Drawpolygon多边形函数
c线函数
例子总出错(画图函数找不到标识符)
#include
#include
using namespace cv;
/***************************************【宏定义部分】****************************************/
#define WINDOW_NAME1 "【绘制图像1】"
#define WINDOW_NAEM2 "【绘制图像2】"
#define WINDOW_SIZE 500
/***************************************【全局函数声明部分】**********************************/
void DrawEllipse(Mat img,double angle);
void DrawFilledCircle(Mat img,Point center);
void DrawPolygon(Mat img);
void DrawLine(Mat img,Point start,Point end);
/********************************************【main函数】*************************************/
int main(int argc,char** argv)
{
Mat atomImg=Mat::zeros(WINDOW_SIZE,WINDOW_SIZE,CV_8UC3);
Mat rookImg=Mat::zeros(WINDOW_SIZE,WINDOW_SIZE,CV_8UC3);
DrawEllipse(atomImg,90);
DrawEllipse(atomImg,0);
DrawEllipse(atomImg,45);
DrawEllipse(atomImg,-45);
imshow("【第一步绘制出的椭圆图像】",atomImg);
DrawFilledCircle(atomImg,Point(WINDOW_SIZE/2,WINDOW_SIZE/2));
DrawPolygon(rookImg);
imshow("【多边形】",rookImg);
rectangle(rookImg,
Point(0,7*WINDOW_SIZE/8),
Point(WINDOW_SIZE,WINDOW_SIZE),
Scalar(0,255,255),
-1,
8);
imshow(WINDOW_NAME1,atomImg);
imshow(WINDOW_NAEM2,rookImg);
waitKey(0);
return 0;
}
对比如下混合输出文字,图像(正确)
#include
#include
#include
using namespace std;
using namespace cv;
void showLine(Mat &pic);
void showRect(Mat &pic);
void showEllipse(Mat &pic);
void showCircle(Mat &pic);
void showPoly(Mat &pic);
void showText(Mat &pic);
int main()
{
Size size(1000, 800);
Mat pic = Mat::zeros(size, CV_8UC3);
showLine(pic);
showRect(pic);
showEllipse(pic);
showCircle(pic);
showPoly(pic);
showText(pic);
namedWindow("show");
imshow("show", pic);
waitKey(0);
return 0;
}
void showLine(Mat &pic)
{
Point p1(100, 100), p2(500, 500);
Scalar color(0, 0, 255);
line(pic, p1, p2, color, 2, LINE_AA);
}
void showRect(Mat &pic)
{
Point p1(100, 100), p2(500, 500);
Rect rec(p1, p2);
Scalar color(0, 255, 0);
rectangle(pic, rec, color, 2, LINE_AA);
}
void showEllipse(Mat &pic)
{
Point cen(300, 300);
Size len(200, 100);
Scalar color(255, 0, 0);
ellipse(pic, cen, len, 0, 0, 360, color, 2, LINE_AA);
ellipse(pic, cen, len, 45, 0, 360, color, 2, LINE_AA);
ellipse(pic, cen, len, 90, 0, 180, color, 2, LINE_AA);
}
void showCircle(Mat &pic)
{
Point cen(300, 300);
Scalar color(255, 255, 255);
circle(pic, cen, 200, color, 2, LINE_AA);
}
void showPoly(Mat &pic)
{
Point p[1][4];
p[0][0] = Point(800, 300);
p[0][1] = Point(900, 500);
p[0][2] = Point(700, 500);
p[0][3] = Point(800, 300);
const Point* pp[] = { p[0] };
int np[] = { 4 };
Scalar color(0, 200, 100);
fillPoly(pic, pp, np, 1, color, 8);
}
void showText(Mat &pic)
{
Point p(300, 50);
Scalar color(0, 0, 255);
putText(pic, "Hello Matin!!!", p, CV_FONT_BLACK, 2.0, color, 2, LINE_AA);
}