如何将文本放在OpenCV C 中的图像中

How to put a text in an image in opencv c++

本文关键字:图像 OpenCV 文本      更新时间:2023-10-16

我当前正在处理我的作业,并在其中加载图像并在其中显示相同的图像。问题是我不知道如何使用putText函数。

这是我现在拥有的代码:

cvInitFont(CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0.0, 1, 8);
cvPutText(img, "You are drinking a lot of water. You may want to cut back.", cvPoint(20, 20), CV_FONT_HERSHEY_SIMPLEX, cvScalar(255, 0, 0));

请帮助我。预先感谢。

尝试这样的东西:

cv::Mat img(512, 512, CV_8UC3, cv::Scalar(0));
cv::putText(img, //target image
            "Hello, OpenCV!", //text
            cv::Point(10, img.rows / 2), //top-left position
            cv::FONT_HERSHEY_DUPLEX,
            1.0,
            CV_RGB(118, 185, 0), //font color
            2);
cv::imshow("Hello!", img);
cv::waitKey();

在512 * 512黑色图像上,代码写下"你好,opencv!"

此代码与OpenCV 2.x和3.x。

均兼容