opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第1张图片

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);

}

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第2张图片

DrawFilledCircle画实心圆函数

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第3张图片

Drawpolygon多边形函数

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第4张图片
opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第5张图片

c线函数

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第6张图片

例子总出错(画图函数找不到标识符)

#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);  

    //------------------------------------绘制原子的示例图------------------------------------  
    //【1】先绘制出椭圆  
    DrawEllipse(atomImg,90);  
    DrawEllipse(atomImg,0);  
    DrawEllipse(atomImg,45);  
    DrawEllipse(atomImg,-45);  
    imshow("【第一步绘制出的椭圆图像】",atomImg);  
    //【2】再绘制出圆心  
    DrawFilledCircle(atomImg,Point(WINDOW_SIZE/2,WINDOW_SIZE/2));  


    //-----------------------------------绘制组合图像----------------------------------------  
    //【1】先绘制会多边形  
    DrawPolygon(rookImg);  
    imshow("【多边形】",rookImg);  
    //【2】在绘制矩形  
    rectangle(rookImg,  
        Point(0,7*WINDOW_SIZE/8),      //两个对角定点  
        Point(WINDOW_SIZE,WINDOW_SIZE),  
        Scalar(0,255,255),             //矩阵颜色图像  
        -1,                            //由于线粗为-1,,此举真将被填充  
        8);  
    //-----------------------------------显示绘制出的图像-------------------------------------  
    imshow(WINDOW_NAME1,atomImg);  
    imshow(WINDOW_NAEM2,rookImg);  
    waitKey(0);  
    return 0;  
}  

opencv学习(九)图像绘制DrawEllipse/ Drawpolygon/ DrawFilledCircle/ DrawFilledCircle/ Rectangle(无法识别标识符,待解_第7张图片

对比如下混合输出文字,图像(正确)

#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] };//获取const Point的二维数组指针  
    int np[] = { 4 };//代表点数  
    Scalar color(0, 200, 100);
    fillPoly(pic, pp, np, 1, color, 8);//pp和np必须要这么写,第四个参数写1就行,表示画一圈,这个函数很死板  
}
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);
}

你可能感兴趣的:(opencv学习)