Finally I was able to build OpenCV 3.3.0 with freetype and HarfBuzz enabled! Thanks to "hon_no_mush" and "Tsukasa Sugiura".
Steps to build succesfully opencv with freetype and hafbuzz:
1- Build freetype and harfbuzz dlls using the method has described in: http://www.gregwessels.com/dev/2017/0...
2- Download and extract OpenCV 3.3.0 and OpenVC-Contrib 3.3.0
3- Replace CMakeList.txt on freetype module (opencv-contrib) with that has described by "Tsukasa Sugiura" : https://gist.github.com/UnaNancyOwen/
4- Using CMake to create a Visual Studio 2017 project for OpenCV.
5- Build the project.
BUT there is another problem! When I use freetype with persian(or Arabic) strings, letters are rendered separately! (See the attached image) : "سلام" => "م ا ل س"
C:\fakepath\opencv_freetype.jpg
My Code:
#include "stdafx.h"
#include <opencv2\opencv.hpp>
#include <opencv2\freetype.hpp>
const char* InitImage = "Initial Image";
int main()
{
cv::namedWindow(InitImage);
cv::Mat mat = cv::imread("C:\\Users\\ATabibi\\Pictures\\texture00.png");
cv::imshow(InitImage, mat);
//----------------
// Create FreeType2
cv::Ptr<cv::freetype::FreeType2> ft2 = cv::freetype::createFreeType2();
// Load Font Data
ft2->loadFontData("BHoma.otf", 0);
// Put Text
ft2->putText(mat, u8"سلام", cv::Point(50, 50), 44, cv::Scalar(255, 255, 255), -1, cv::LINE_AA, false);
cv::imshow(InitImage, mat);
cv::waitKey();
return 0;
}
//----Update-----:
Today I learned another method to insert UTF-8 strings to an image in opencv: If opencv libs have built with Qt support, we can use cv::addText function (instead puttext) and all problems are solved!!
#include <opencv2\opencv.hpp>
const char* InitImage = "Initial Image";
int main()
{
cv::namedWindow(InitImage);
cv::Mat mat = cv::imread("C:\\Users\\ATabibi\\Pictures\\texture00.png");
cv::addText(mat, u8"سلام", cv::Point(150, 150), "B Nazanin", 24,cv::Scalar(255,0,100));
cv::imshow(InitImage, mat);
cv::waitKey();
return 0;
}
and result:
C:\fakepath\opencv_addText.jpg
freetype module also not available for me and i want to enable it.let us wait together for someone's response for a while. if we will not get any response we will work to enable. i recommend you to compile with the latest source of OpenCV. is there a reason to use 3.2 version?
I will use the latest stable release (3.3.0) as soon as possible. But I don't think there are any important differences between these minor versions. My problem is not opencv or opencv_contrib but I don't know how to use freetype and Harfbuzz with them! Of course I've been able to build those statically(thanks to Tsukasa Sugiura: https://gist.github.com/UnaNancyOwen/...), but I couldn't build as shared libs.
@LBerger if we use the new method Installation by Using git-bash will we get freetype enabled
I think this site is helpful to build harfbuzz and freetype libraries.
http://www.gregwessels.com/dev/2017/0...
thank you hon_no_mush! I built shard libs of freetype-2.8 and HarfBuzz-1.5 with help of your link. I will build opencv using them and will write result here. Thank you very much!