C/C++教程

opencv绘制图和文字

本文主要是介绍opencv绘制图和文字,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#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;
}

 

这篇关于opencv绘制图和文字的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!