cv2.imshow fail : Fontconfig error: failed reading config file

Viewed 1169

while runnning the code

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

im having an error :

Fontconfig error: failed reading config file

(python:5882): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion 'GTK_IS_WIDGET (widget)' failed

2 Answers

TL;DR: Now, this is not an excellent solution, but I've solved it by downgrading my version, so simply by running:

pip uninstall opencv-python

pip install -Iv opencv-python==4.2.0.34

I've been also having the same problem ever since I've moved to OpenCV 4.3.0.36. I use Ubuntu 16.04, and could narrow the problem down until the libfontconfig-42c558d2.so.1.11.1 library under opencv_python.libs directory.

Gotta mention, I use virtual environment by the way. In my opinion, this problem is due to a clash between the operating system's libfontconfig and OpenCV's own version because there is a statement in the licence file reading as follows.

libfontconfig is redistributed within all opencv-python Linux and macOS packages.

...and I haven't had any problem like that in the previous versions.

You can see the full list of CV versions here if that works for you. Hope this by-pass helps, especially if you have a deadline or something.

try to edit the cv2 import because sometimes it have errors try from cv2 import cv2 may works

Related