|
|
详解OpenCV的文本绘制函数putText()
函数putText()用于在图像上绘制文本内容。
C++原型如下:
- void cv::putText(InputOutputArray img,
- const String & text,
- Point org,
- int fontFace,
- double fontScale,
- Scalar color,
- int thickness = 1,
- int lineType = LINE_8,
- bool bottomLeftOrigin = false)
复制代码
各参数意义如下:
img---待绘制文本的图像。
text---待绘制文本的具体内容。
org---文本在图像img中的原点坐标,默认原点为文本内容的左下角,可通过下面的参数bottomLeftOrigin控制原点坐标的位置。
fontFace---文本的字体。
fontScale---文本的缩放比例。
color---文本的颜色。
thickness---文本线条的粗细,默认值为1。
lineType---文本线条的类型,默认值为LINE_8。
bottomLeftOrigin---如果这个值为true,则表示把图像的左下角视为图像的原点;如果值为False,则表示把图像的左上角视为图像的原点。
示例代码如下:
- //出处:昊虹AI笔记网(hhai.cc)
- //用心记录计算机视觉和AI技术
- //博主微信/QQ 2487872782
- //QQ群 271891601
- //欢迎技术交流与咨询
- //OpenCV版本 OpenCV3.0
- #include <opencv2/opencv.hpp>
- #include <iostream>
- using namespace cv;
- void main()
- {
- Mat org = imread("F:/material/images/P0039-all_blue.bmp");
- Point org_point = Point(100, 150);
- putText(org, "www.hhai.cc", org_point, FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 0, 220), 1, 8);
- imshow("img", org);
- cv::waitKey(0);
- }
复制代码
运行结果如下:

|
|