Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on imshow when setting a matplotlib backend beforehand #22485

Open
4 tasks done
epbuennig opened this issue Sep 8, 2022 · 2 comments
Open
4 tasks done

Segfault on imshow when setting a matplotlib backend beforehand #22485

epbuennig opened this issue Sep 8, 2022 · 2 comments

Comments

@epbuennig
Copy link

epbuennig commented Sep 8, 2022

The python repository issue-template mentioned that issues that have to be fixed in C++ as well should be reported here.
Although the example is purely python. The example relies on matplotlib and may not be caused by opencv directly, but the segfault happens when calling a opencv function, so I'm reporting it here.

System information (version)
  • OpenCV => 4.6.0-4 (this is the package I'm using, it looks like it's using gcc, but I honestly can't tell)
  • Python-OpenCV => 4.6.0.66
  • Operating System / Platform => Arch Linux 5.19.7-arch1-1 #1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
  • Compiler => gcc (GCC) 12.2.0 (see note above)
Detailed description

When importing matplotlib.pyplot and then setting a backend for matplotlib before using opencv the first call to imshow causes a segmentation fault.

Steps to reproduce
  1. Set up a python environment using Python 3.9.13 with the following packages:
cycler          0.11.0
fonttools       4.37.1
gobject         0.1.0
kiwisolver      1.4.4
matplotlib      3.5.3
numpy           1.23.2
opencv-python   4.6.0.66
packaging       21.3
Pillow          9.2.0
pip             22.2.2
pycairo         1.21.0
PyGObject       3.42.2
pyparsing       3.0.9
PyQt5-Qt5       5.15.2
PyQt5-sip       12.11.0
pyrealsense2    2.51.1.4348
python-dateutil 2.8.2
scipy           1.9.1
setuptools      60.2.0
six             1.16.0
wheel           0.37.1
  1. Prepare a python script like this:
import matplotlib as mpl
import cv2

# swapping the order of thsese also resolves the issue
from matplotlib import pyplot as plt # removing this import resoves the issue
mpl.use('GTK3Agg') # remvoing this also resovle the issue

def test():
    webcam = cv2.VideoCapture(0)

    try:
        while True:
            ret, frame = webcam.read()

            # segfault happens on the first call to `imshow`
            cv2.imshow('frame', frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
    finally:
        webcam.release()
        cv2.destroyAllWindows()


test()
  1. Running the script.
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc
@tacaswell
Copy link

I strongly suspect that this will reproduce using only gtk.

@tacaswell
Copy link

matplotlib/matplotlib#24364 (comment) it does reproduce with only gi / gtk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants