I'm attempting to draw some filled text onto an image stored in a cv::Mat object using OpenCV's C++ library.
Most of the existing tutorials out there make use of the putText function.
The following minimal example:
#include <opencv2/opencv.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/core/core.hpp>
int main()
{
cv::Mat img = cv::Mat::zeros(300, 300, CV_8UC3);
cv::putText(img, "TEST", cv::Point(50, 150), cv::FONT_HERSHEY_DUPLEX, 3, CV_RGB(255, 255, 255));
cv::imshow("test", img);
cv::waitKey(1);
std::system("pause");
return 0;
}
Produces the following output:
However, I would like the text to be filled, instead of only having the borders visible.
According to the putText documentation, the lineType argument should be used to make the text filled.
Attempting to pass the cv::FILLED enum as the lineType argument to the putText call as such:
cv::putText(img, "TEST", cv::Point(50, 150), cv::FONT_HERSHEY_DUPLEX, 3, CV_RGB(255, 255, 255), 1, cv::FILLED);
results in no apparent changes to the output image:
I'm aware that I can simply make the thickness argument to the putText call higher to simulate a text fill, however I'm looking for a way to actually fill the text here, ideally without any text borders at all.
What is the proper way to draw filled text onto a cv::Mat image using OpenCV's C++ library?
Thanks for reading my post, any guidance is appreciated.

