Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV putText UTF-8 characters

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 šŠčČžŽ?

like image 469
nejcb1 Avatar asked Mar 20 '13 09:03

nejcb1


2 Answers

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
like image 176
karlphillip Avatar answered Nov 07 '22 18:11

karlphillip


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))
like image 30
b_m Avatar answered Nov 07 '22 19:11

b_m