Ask Your Question
1

How to build opencv with freetype and HarfBuzz

asked 2017-08-30 14:41:26 -0600

tabibi gravatar image

updated 2017-08-30 14:47:18 -0600

I want to build opencv 3.2.0 with freetype and HarfBuzz enabled in shared(dll) mode on Windows using Visual Studio 2017. I use CMake but I don't know how to set on freetype. Should I use source code of these libraries? If true how? Or do I have to use their binaries??

edit retag flag offensive close merge delete

Comments

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?

sturkmen gravatar imagesturkmen ( 2017-08-30 15:21:25 -0600 )edit

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.

tabibi gravatar imagetabibi ( 2017-08-31 07:19:24 -0600 )edit

@LBerger if we use the new method Installation by Using git-bash will we get freetype enabled

sturkmen gravatar imagesturkmen ( 2017-08-31 10:04:44 -0600 )edit
1

I think this site is helpful to build harfbuzz and freetype libraries.

http://www.gregwessels.com/dev/2017/0...

hon_no_mushi gravatar imagehon_no_mushi ( 2017-08-31 15:53:49 -0600 )edit

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!

tabibi gravatar imagetabibi ( 2017-09-01 02:12:30 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2017-09-01 23:58:26 -0600

tabibi gravatar image

updated 2017-09-02 03:47:42 -0600

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) : "سلام" => "م ا ل س"

image description 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:

image description C:\fakepath\opencv_addText.jpg

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-08-30 14:41:26 -0600

Seen: 6,200 times

Last updated: Sep 02 '17