Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

c++ - Drawing greek symbols in opencv using putText and FreeFontStyle

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!

question from:https://stackoverflow.com/questions/65877386/drawing-greek-symbols-in-opencv-using-puttext-and-freefontstyle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...