You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operating System / Platform => macOS Catalina 10.15.7
Compiler => Xcode 12.2
Detailed description
The older putText() function works on both CV_8UC3 and CV_32FC3 (probably all) types of Mat.
The version of putText() that uses FreeType2 and (e.g.) .ttf files appears to only work on CV_8UC3 Mats, according to the assert that fails while trying to put text on a 3xfloat Mat.
This seems easy enough to work around, so should be considered a low priority bug. But since I ran into it I thought I should file this report with code to reproduce.
Note that the documentation (here) does not mention the restriction to CV_8UC3.
Steps to reproduce
Run this function, passing in the pathname of a .ttf file:
voidcompare_putTexts(const std::string& ttf_pathname)
{
auto two_putTexts = [&](const std::string& window, int type, int bright)
{
// Make white mat of given type.
cv::Mat mat(300, 300, type, cv::Scalar::all(bright));
// Draw text the original way.cv::putText(mat, "hello world", cv::Point(20, 100), cv::FONT_HERSHEY_SIMPLEX,
1, CV_RGB(0, 0, 0), 1, cv::LINE_AA);
cv::namedWindow(window);
cv::imshow(window, mat);
cv::waitKey();
// Draw text using TTF.
cv::Ptr<cv::freetype::FreeType2> ft2;
ft2 = cv::freetype::createFreeType2();
ft2->loadFontData(ttf_pathname, 0);
ft2->putText(mat, "hello world", cv::Point(20, 200),
30, CV_RGB(0, 0, 0), cv::FILLED, cv::LINE_AA, true);
cv::imshow(window, mat);
cv::waitKey();
};
two_putTexts("window 1", CV_8UC3, 255); // 3 x 8bit colortwo_putTexts("window 2", CV_32FC3, 1); // 3 x float color
}
A window appears with text drawn by the old putText() on a CV_8UC3 Mat.
Type any key to proceed.
The window will show a second line of text using FreeType2.
Type any key to proceed.
A second window appears with a CV_32FC3 Mat.
Type any key to proceed.
Crashes with an assert failure:
terminating with uncaught exception of type cv::Exception: OpenCV(4.5.0) /tmp/opencv-20201123-26930-m95s1u/opencv-4.5.0/opencv_contrib/modules/freetype/src/freetype.cpp:197: error: (-215:Assertion failed) ( _img.empty() == false ) && ( _img.isMat() == true ) && ( _img.depth() == CV_8U ) && ( _img.dims() == 2 ) && ( _img.channels() == 3 ) in function 'putText'
Issue submission checklist
I report the issue, it's not a question
I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution
I updated to latest OpenCV version and the issue is still there
There is reproducer code and related data files: videos, images, onnx, etc
The text was updated successfully, but these errors were encountered:
System information (version)
Detailed description
The older
putText()
function works on bothCV_8UC3
andCV_32FC3
(probably all) types ofMat
.The version of
putText()
that uses FreeType2 and (e.g.).ttf
files appears to only work onCV_8UC3 Mat
s, according to theassert
that fails while trying to put text on a 3xfloatMat
.This seems easy enough to work around, so should be considered a low priority bug. But since I ran into it I thought I should file this report with code to reproduce.
Note that the documentation (here) does not mention the restriction to
CV_8UC3
.Steps to reproduce
Run this function, passing in the pathname of a
.ttf
file:A window appears with text drawn by the old
putText()
on aCV_8UC3 Mat
.Type any key to proceed.
The window will show a second line of text using FreeType2.
Type any key to proceed.
A second window appears with a
CV_32FC3 Mat
.Type any key to proceed.
Crashes with an assert failure:
terminating with uncaught exception of type cv::Exception: OpenCV(4.5.0) /tmp/opencv-20201123-26930-m95s1u/opencv-4.5.0/opencv_contrib/modules/freetype/src/freetype.cpp:197: error: (-215:Assertion failed) ( _img.empty() == false ) && ( _img.isMat() == true ) && ( _img.depth() == CV_8U ) && ( _img.dims() == 2 ) && ( _img.channels() == 3 ) in function 'putText'
Issue submission checklist
answers.opencv.org, Stack Overflow, etc and have not found solution
The text was updated successfully, but these errors were encountered: