opencv绘制图和文字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <istream>
#include <opencv2/opencv.hpp>
 
using namespace cv;
using namespace std;
 
int main(int argc, char **argv) {
    Mat src;
    //    加载图片
    src = imread("../../picture/bg1.webp", 1);
    if (!src.data) {
        printf("No image data \n");
        return -1;
    }
    // 画线
    Point p1 = Point(0,0),p2=Point(550,190);
    Scalar line_color =  Scalar(0,0,255);
    line(src,p1,p2,line_color,2,LINE_8);
    // 画框
    Rect rect = Rect(400,0,350,390);
    Scalar rect_color = Scalar(255,0,0);
    rectangle(src,rect,rect_color,2,LINE_8);
    // 画椭圆
    Scalar ellipse_color = Scalar(0,255,0);
    ellipse(src,Point(575,190),Size(190,170),90,0,360,ellipse_color,2,LINE_8);
    // 画圆
    Scalar circle_color = Scalar(255,255,0);
    circle(src,Point(575,190),100,circle_color,1,LINE_8);
    // 画多边形
    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 pts_color = Scalar(255,0,255);
    fillPoly(src,ppts,npt,1,pts_color,LINE_8);
    // 画字符
    Scalar text_color = Scalar(0,255,255);
    putText(src,"Beautiful Girl",Point(450,450),FONT_HERSHEY_COMPLEX,1.0,text_color,1,LINE_8);
    namedWindow("src", WINDOW_AUTOSIZE);
    imshow("src", src);
    //    等待按键
    waitKey(0);
    return 0;
}

 

posted @   NAVYSUMMER  阅读(56)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
交流群 编程书籍
点击右上角即可分享
微信分享提示