Function name | description |
cv :: putText () | Draws the specified text in the picture |
cv::getTextSize() | Gets a character width and height |
Draw text [cv :: putText]
Detailed API follows
void cv::putText(
cv::Mat& img, // 待绘制的图像
const string& text, // 待绘制的文字
cv::Point origin, // 文本框的左下角
int fontFace, // 字体 (如cv::FONT_HERSHEY_PLAIN)
double fontScale, // 尺寸因子,值越大文字越大
cv::Scalar color, // 线条的颜色(RGB)
int thickness = 1, // 线条宽度
int lineType = 8, // 线型(4邻域或8邻域,默认8邻域)
bool bottomLeftOrigin = false // true='origin at lower left'
);
FontFace parameters which fonts are supported as follows
Identifier | description |
FONT_HERSHEY_SIMPLEX = 0 | ! <Normal size sans-serif font size Normal sans serif |
FONT_HERSHEY_PLAIN = 1 | ! <Small size sans-serif font small sans serif |
FONT_HERSHEY_DUPLEX = 2 | ! <Normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX) normal size sans serif |
FONT_HERSHEY_COMPLEX = 3 | ! <Normal size serif font sans serif normal size is more complex than FONT_HERSHEY_DUPLEX |
FONT_HERSHEY_TRIPLEX = 4 | !< normal size serif font (more complex than FONT_HERSHEY_COMPLEX Normal size sans-serif font, more complex than FONT_HERSHEY_COMPLEX |
FONT_HERSHEY_COMPLEX_SMALL = 5 | !< smaller version of FONT_HERSHEY_COMPLEX Trumpet version of FONT_HERSHEY_COMPLEX |
FONT_HERSHEY_SCRIPT_SIMPLEX = 6 | ! <Hand-writing style font handwriting font |
FONT_HERSHEY_SCRIPT_COMPLEX = 7 | !< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX More complex than FONT_HERSHEY_SCRIPT_SIMPLEX variants |
FONT_ITALIC = 16 | !< flag for italic font |
Any listed in the table to a font can be used in combination and CV :: FONT_ITALIC (or operated by) obtained in italics
Each font has a "natural" size, when fontScale than 1.0, before drawing the text font size by scaling the number
Validation code, and the following results
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace cv;
int main()
{
Mat img = imread("E:/myFile/picture/kobe.jpg");
const std::string str1 = "Hello Kobe!";
putText(img, str1, Point2i(40, 150), FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 180), FONT_HERSHEY_PLAIN, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 210), FONT_HERSHEY_DUPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 240), FONT_HERSHEY_COMPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 270), FONT_HERSHEY_TRIPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 300), FONT_HERSHEY_COMPLEX_SMALL, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 330), FONT_HERSHEY_SCRIPT_SIMPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 360), FONT_HERSHEY_SCRIPT_COMPLEX, 1, Scalar(0, 255, 0), 1, 8, false);
putText(img, str1, Point2i(40, 390), FONT_ITALIC | FONT_HERSHEY_PLAIN, 1, Scalar(0, 255, 0), 1, 8, false);
imshow("kobe", img);
waitKey(0);
return 0;
}
OpenCV Basics Tutorial - draw text cv :: getTextSize [2] See the following URL
https://blog.csdn.net/Gary_ghw/article/details/103746709