Reputation: 33
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!
Upvotes: 1
Views: 2216
Reputation: 4367
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:
#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;
}
Upvotes: 2