1

I've seen the following questions, in Python language, about how to write special characters that aren't supported by the Hershey Font Style used in putText function from Opencv: How to write russian letters in the console and How to draw chinese letter in the image and How to write greek letter in console.

I would like to draw greek letters using UTF-8 strings with freetype2 class using putText. The second link is slighty what I want, but I saw it use a PIL option as well, but I'm not using Python. Thanks!

arantxa
  • 33
  • 4

1 Answers1

2

As @berak mentioned in this answer, this is not possible by using putText(). It only supports ascii subset.

But you can achieve it by using addText() if you installed opencv with -D WITH_QT = ON

Here is the simple code with Greek letters and result:

enter image description here

#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    Mat img = Mat::zeros(Size(1000,1000),CV_8UC3);


    namedWindow("Window",0);
    cv::addText(img, "Greek Letters: ", cv::Point(50, 100), "Times",30,Scalar(0,255,255),QT_FONT_NORMAL,QT_STYLE_NORMAL);
    cv::addText(img, "alpha: α", cv::Point(50, 200), "Times",30,Scalar(0,255,255),QT_FONT_NORMAL,QT_STYLE_NORMAL);
    cv::addText(img, "betta: β", cv::Point(50, 300), "Times",30,Scalar(0,255,255),QT_FONT_NORMAL,QT_STYLE_NORMAL);
    cv::addText(img, "gamma: γ", cv::Point(50, 400), "Times",30,Scalar(0,255,255),QT_FONT_NORMAL,QT_STYLE_NORMAL);
    cv::addText(img, "delta: δ", cv::Point(50, 500), "Times",30,Scalar(0,255,255),QT_FONT_NORMAL,QT_STYLE_NORMAL);
    cv::addText(img, "epsilon: ε", cv::Point(50, 600), "Times",30,Scalar(0,255,255),QT_FONT_BOLD,QT_STYLE_NORMAL);


    imshow("Window",img);

    waitKey(0);

    return 0;
}
Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
  • 1
    Good to know! I'll check how to re-build my opencv with 'WITH_QT' enabled. I saw at the [documentation](https://docs.opencv.org/master/db/d05/tutorial_config_reference.html) that it is set off by default. How could I've lived without Qt functionalities all this time!? If i fail, I'll simply add the equation I want as image. – arantxa Jan 26 '21 at 12:37