so far I have used OpenCV with great pleasure. The documentation was superior and I really liked that almost everything worked out of the box. However I got to a point where I am struggeling right now.
I am using OpenCV for a computerVision Project on the rapsberry pi.
Therefore I like to include some Text Data onto images. As this includes technical data the ‘µ’ symbol shal be used, which only delivers ?? with the standard putText method. So I used google and found out about freeType.
The problem is, whereever I look, I cannot find a good tutorial how to compile openCV with Freetype. I installed Freetypewith apt-get, after that I compiled harfbuzz from source and then I tried to compile the new openCV 4.8 and set the Compiler Flag WITH_FREETYPE=ON. OpenCV did compile, however obviously I am missing one (or more) steps as still there is not freeType header available in my C++ project. Also in the /usr/local/include/opencv4/opencv2 path is no such File.
Is there a good documentation on how to integrate freeType into OpenCV for C++? A step-by-step guide would be nice, however I would also appreciate a list of compilerflags that cmake needs to compile openCV with Freetype or a hint saying, that Freetype needs to be compiled from source, … Basically anything that makes the process a bit more clear is highly appreciated.
you might have to deal with “harfbuzz” in addition to freetype.
if you’re lucky, you just have to install those (including dev package), and then cmake will pick them up for opencv.
if not, you might have to forage through opencv’s cmake files and figure out which cmake variables need setting so you tell the cmake process explicitly where those libraries can be found.
thanks for your reply. It sounds a bit like, what I have tried so far, but then I will maybe retry the process with an edited cmake File. Are there any other compiler flags needed apart from the WITH_FREETYPE=ON flag?
Ok, i narrowed it down. The CMakeLists.txt of the gapi module (where FreeType is located in) aborts after the command (I inserted a few message commands into the cMake File):
ocv_add_module(gapi
REQUIRED
opencv_imgproc
OPTIONAL
opencv_video opencv_calib3d
WRAP
python
)
This results in the following final command line output:
– OpenCV modules:
– To be built: core features2d flann highgui imgcodecs imgproc photo python3 video videoio
– Disabled: calib3d dnn gapi ml objdetect stitching ts world
I suspect, that FreeType is not included in the build, because gapi is on the Disbaled list. Am I right?
Thank you, that led me on the right course. I was able to build openCV with freetype now. Sometimes the error is located before the real problem happens. I was not aware, that the contrib modules where needed and excluded them from my build.
I will test my programm with it tomorrow and will write a mini guide on how to install on linux, if everything works out
SO now, the late answer (wanted to make it right) to how to install openCV on the Raspberry Pi with FreeType font support.
The easiest way is to install freetype from the official repositories and compile harfbuzz from source. Compiling Freetype from source is also possible however, if a newer version is required. I used harfbuzz version 8.0.1 (but also a newer version can be used probably).
First install harfbuzz dependencies (and compilers) by: