zoukankan      html  css  js  c++  java
  • opencvputText绘字

        cv::Mat src(500, 500, CV_8UC3, cv::Scalar(0,0,0));
        std::string text = "Hello World!";
        cv::putText(src,text, cv::Point(10,50), cv::FONT_HERSHEY_PLAIN,4, cv::Scalar(255,0,0),3);
        /*
        参数1:待绘制的图像
        参数2:待绘制的文字
        参数3:文本框的左下角
        参数4:字体    支持的字体见下图
        参数5:尺寸因子,值越大文字越大
        参数6:线条的颜色
        参数7:线条宽度
        参数8:线型(4邻域或8邻域,默认8邻域)
        参数9:bool bottomLeftOrigin = false // true='origin at lower left'
        */
        
        cv::imshow("src", src);

        cv::Mat src(500, 500, CV_8UC3, cv::Scalar(255,0,0));
        std::string text = "Hello World!";
    
        int baseline;
        cv::Size text_size = cv::getTextSize(text, 3, 2, 2, &baseline);//获取文本框的长宽
        /*
        参数1:待绘制的文字
        参数2: int fontFace: 文字字体类型
        参数3:double fontScale: 字体缩放系数
        参数4:int thickness: 字体笔画线宽
        参数5:CV_OUT int* baseLine: 文字最底部y坐标
        */
        
        cv::putText(src, text, cv::Point(10, 50), 3, 2, cv::Scalar(0, 255, 255), 2, 8, 0);
    
        std::cerr << text_size << std::endl;
        std::cerr << baseline << std::endl;
    
        cv::imshow("src", src);

    绘制中文

    opencv默认不能使用中文,要使用中文请下载插件:https://download.csdn.net/download/lm68140318/39694201

    解压后把两个文件复制到工程中

    添加头文件和源文件

    导入头文件:#include "puttextzh.h"

        cv::Mat src(500, 500, CV_8UC3, cv::Scalar(0,0,0));
        putTextZH(src, "欢迎你使用中文", cv::Point(10,50), cv::Scalar(255,0,0),30, "黑体", true,true);
        /*
        参数1:待绘制的图像
        参数2:待绘制的文字
        参数3:文本框的左下角
        参数4:字体颜色
        参数5:字体大小,值越大文字越大
        参数6:字体(默认使用Arial字体,也可以设置成操作系统中已经安装的字体,如“宋体”、“微软雅黑”、“Times New Roman”等;默认显示非斜体、非下划线)
        参数7:是否斜体
        参数8:是否有下划线
        
        */
        
        cv::imshow("src", src);

  • 相关阅读:
    POJ3320 Jessica's Reading Problem
    POJ3320 Jessica's Reading Problem
    CodeForces 813B The Golden Age
    CodeForces 813B The Golden Age
    An impassioned circulation of affection CodeForces
    An impassioned circulation of affection CodeForces
    Codeforces Round #444 (Div. 2) B. Cubes for Masha
    2013=7=21 进制转换
    2013=7=15
    2013=7=14
  • 原文地址:https://www.cnblogs.com/liming19680104/p/15530647.html
Copyright © 2011-2022 走看看