#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
string text = "I Love You Baby ! ";
int fontface = FONT_HERSHEY_COMPLEX_SMALL;
double fontscale = 2;
int thickness = 3;
Mat image(700, 900, CV_8UC3, Scalar::all(0));
int baseline = 0;
Size textsize = getTextSize(text, fontface, fontscale, thickness, &baseline);
baseline += thickness;
Point textorg((image.cols - textsize.width) / 2,
(image.rows + textsize.height) / 2);
rectangle(image, textorg + Point(0, baseline), textorg + Point(textsize.width,
-textsize.height), Scalar(0, 0, 255));
line(image, textorg + Point(0, thickness), textorg + Point(textsize.width, thickness),
Scalar(0, 0, 255));
putText(image, text, textorg, fontface, fontscale, Scalar::all(255), thickness, 8);
imshow("添加文档:"
使用C++进行文本文字插入(opencv)
最新推荐文章于 2024-08-11 21:46:18 发布
本文介绍如何利用C++和OpenCV库在图像中插入文本,提供了详细的步骤和参考链接,帮助读者理解并实践相关技术。
摘要由CSDN通过智能技术生成