pythonopencvfreetype

AttributeError: module 'cv2.cv2' has no attribute 'freetype' in OpenCV


I'm using a docker container with minimal packages installed. I installed opencv-contrib-python using pip3 install opencv-contrib-python and it installed the latest build 4.1.025 and have verified that it was running and my program was ok with it. However, now I need the freetype module but when I try:

import cv2 as cv
ft = cv.freetype.createFreeType2()

It throws the AttributeError as in the title. I tried reinstalling different versions namely: 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25 to no avail. I am using the headless version mainly(since I'm using docker and I don't need any gui functionality). Another thing I found out was not all the modules can be imported I have tried (ccalib, tracking, sfm, xobjdetect etc) and these modules throw the same error. Does this mean that some modules are not available through the pip3 installation? Thank you.


Solution

  • I'm pretty late to this issue, but I hope this helps someone.

    I've added links to an easy to follow guide at the bottom.

    Here are the essential steps, you'd need to follow:

    There's a comprehensive written guide over here:

    Also, I've made a video inspired by the same tutorial, which can be found here:

    I would recommend watching the video and keeping this guide open on the side.

    Cheers!