程序运行结果:
程序代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
#define WINDOW_NAME1 "【绘制图】" //为窗口标题定义的宏
#define WINDOW_WIDTH 600//定义窗口大小的宏
void DrawEllipse( Mat img, double angle );//绘制椭圆
void DrawFilledCircle( Mat img, Point center );//绘制圆
int main( void )
{
// 创建空白的Mat图像
Mat atomImage = Mat::zeros( WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3 );
//先绘制出椭圆
DrawEllipse( atomImage, 90 );
DrawEllipse( atomImage, 0 );
//再绘制圆心
DrawFilledCircle( atomImage, Point( WINDOW_WIDTH/2, WINDOW_WIDTH/2) );
imshow( WINDOW_NAME1, atomImage );
moveWindow( WINDOW_NAME1, 0, 200 );
waitKey( 0 );
return(0);
}
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, 129, 0 ),
thickness,
lineType );
}
//自定义的绘制函数,实现了实心圆的绘制
void DrawFilledCircle( Mat img, Point center )
{
int thickness = -1;
int lineType = 8;
circle( img,
center,
WINDOW_WIDTH/32,
Scalar( 0, 0, 255 ),
thickness,
lineType );
}