8

Does anybody have alternative to OpenCV putText (with UTF-8 characters supported) ? As already said, putText is only working for ASCII characters, but not for UTF-8 such as šŠčČžŽ?

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
nejcb1
  • 131
  • 1
  • 2
  • 6

2 Answers2

4

If OpenCV was built with Qt support you can use cv::addText() to write that string:

cv::Mat img = cv::imread("C:\\snowflake.jpg");
if (img.empty())
{
    std::cout << "!!! Failed imread()" << std::endl;
    return;
}

cv::addText(img, "áéőúöüóí", cv::Point(100, 50), cv::fontQt("Times"));

However, if OpenCV was built without Qt support, calling cv::addText() will crash your application and the following error will be printed to the console:

OpenCV Error: The function/feature is not implemented (The library is compiled without QT support) in cv::fontQt, file C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\highgui\src\window.cpp, line 409
karlphillip
  • 92,053
  • 36
  • 243
  • 426
3

You didn't specify what language are you using. From Python I'd use the PIL's text drawing function:

draw.text((0, 0), unicode("áéőúöüóí","utf-8"), font=font, fill=(255,255,255))
b_m
  • 1,473
  • 2
  • 18
  • 29