opencv: OpenCV 4.4.0 macOS Catalina "segmentation fault"

PIP opencv-python package issue: https://github.com/skvark/opencv-python/issues/376

System information (version)
  • OpenCV => ❔
  • Operating System / Platform => ❔
  • Compiler => ❔

Model Name: MacBook Air Model Identifier: MacBookAir7,2 Processor Name: Dual-Core Intel Core i5 Processor Speed: 1.8 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Hyper-Threading Technology: Enabled Memory: 8 GB

python --version Python 3.8.5 [3.7,3.6]

❯ pip --version pip 20.2.2 from /Users/xxx/.pyenv/versions/3.8.5/envs/AI-3.8.5/lib/python3.8/site-packages/pip (python 3.8)

Python 3.8.5 (default, Aug 12 2020, 19:20:20) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

import cv2 cv2.version ‘4.4.0’

Detailed description

Got "[1] 26545 segmentation fault " While running the official OpenCV documentation tutorial code from https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

Tested 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()

Error message: “”" python test.py [1] 60134 segmentation fault python test.py

╭─ ~/Projects/cv2 ✘ SEGV  AI-3.8.5 3.8.5 21:39:57 “”"

What I’ve. tried :

  1. Used different terminals to run the code. (system terminal app, JetBrains PyCharm terminal, viscose terminal, iterm2, iterm2 is setup for camera access )
  2. Used different Python versions (3.6,3.7,3.8)
  3. Tried to build from source code. (same problem)
Steps to reproduce
Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues, answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

opencv-python version 4.5.4.58 still presents this very same issue on Manjaro Linux as of november 2021. After having dowgraded to opencv-python 4.5.3.56 the issue is resolved

UPDATE: (temp fix)

Just checked the previous versions. The issue persists on 4.3.0.38, but not on ‘4.3.0.36’. So whatever is causing it, started on that version.

I guess I continue using ‘4.3.0.36’ for now…

opencv-python version 4.5.4.58 still presents this very same issue on Manjaro Linux as of november 2021. After having dowgraded to opencv-python 4.5.3.56 the issue is resolved

Thanks, I faced this issue on ubuntu 20.04, default install. Downgrade to 4.5.3.56 fixed it.

pip uninstall opencv-python
pip install --upgrade opencv-python==4.5.3.56

I’ve checked package 42 and it works fine. Thank you!

Please try to upgrade to the new 4.4.0.42 release which should have this issue fixed.

Yeah, I looked into Qt sources too. That PyQt link was helpful. The issue surfaced in the latest opencv-python versions because Qt version changed from 5.13 to 5.15. Qt 5.14 introduced those changes which apparently require the Info.plist file to exist. I can add it to the packages if I manage to figure out the paths and correct location. I do not own a Mac, so it would be helpful if someone could have a look into this locally on a Mac and test for a possible solution. I did open an issue about this here: https://github.com/skvark/opencv-python/issues/376

Now, as I tested a lot, I can confirm that the problem was produced by ‘cv2.imshow()’.

Found similar problem: https://riverbankcomputing.com/pipermail/pyqt/2020-January/042419.html

Looks like Qt looks for Qt bundle (‘org.qt-project.QtCore’) and can not find it. Not sure if it is possible to trick it somehow, as I understand Info.plist file should exist. It crashes at this line: https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qlibraryinfo.cpp#n502 or here: https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qlibraryinfo.cpp#n512 or here: https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qlibraryinfo.cpp#n432

Perhaps it is possible to define QT_LIBINFIX and name the bundle correspondingly.

@magiwanders @bestel74 Please follow the issue here: https://github.com/opencv/opencv-python/issues/572

This issue is related to macOS and has been fixed.

This issue cannot be fixed in this repository. It’s very specific to the unofficial opencv-python pre-built binary packages: https://github.com/skvark/opencv-python/issues/376

I just encountered similar problem in pycharm. I was using latest version of opencv-python and python 3.7. When i use cv2.imshow(), i got the err: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

So I installed the 4.3.0.36 version, then cv2.VideoCapture and cv2.imshow() works