Opencv-python: No attribute 'freetype'

Created on 12 Aug 2018  路  5Comments  路  Source: opencv/opencv-python

I uninstalled opencv-python and pip installed opencv-contrib-python. I was trying to follow this example ( http://fireant.github.io/misc/2017/01/28/ttf-opencv.html ) of using freetype fonts under opencv:

Python 3.6.5 (default, Apr  1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.freetype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'freetype'

>>> cv2.__version__
'3.4.2'
>>> cv2.__file__
'/home/xxxx/.local/lib/python3.6/site-packages/cv2/cv2.cpython-36m-x86_64-linux-gnu.so'

I've checked the source code and seems freetype is not a non-free module? So it's supposed to be there.
OS: Ubuntu 18.04.

Most helpful comment

Maybe this situation should be documented explicitly. I spent a day trying to make it work.

All 5 comments

OpenCV has multiple 3rd party dependencies which are not enabled by default. In this case freetype2 itself exists but to enable it another dependency is needed: https://github.com/opencv/opencv_contrib/blob/3.4.2/modules/freetype/CMakeLists.txt. There's no HarfBuzz in the manylinux Docker images. HarfBuzz needs to be built to the Docker images or installed some other way.

If freetype is enabled on Linux it must be enabled on Windows and macOS too to provide consistent packages across different platforms.

I see. Thanks @skvark . I used PIL to draw text instead. Hope you'll find some free time to integrate it in the future :)

Maybe this situation should be documented explicitly. I spent a day trying to make it work.

There's no HarfBuzz in the manylinux Docker images. HarfBuzz needs to be built to the Docker images or installed some other way.

Hi skvark, I having the same issue here but I can't manage to make it work :(
I tried to install Harfbuzz following their installation (from tarball or from git clone) but I may miss something to make it work because I don't fully understand what is happening behind (maybe how to link the harfbuzz installation with the python module ?)

Here is my Dockerfile :
image

And my requirements.txt :
image

Thanks if you can help me !

As explained above, freetype is not supported in the pre-built wheels and you cannot enable it unless you build OpenCV from sources.

Was this page helpful?
0 / 5 - 0 ratings