Search code examples
pythonmacosopencvmacos-mojave

Python crashed with OpenCV in MacOS Mojave


My OpenCV program is broken soon after I upgraded my MacBook to MacOS Mojave.

Installed the below combinations and nothing seem to work.

Python 3.6.5 with OpenCV 3.4.1

Python 3.7.0 with OpenCV 3.4.3

Simple test program

import cv2

vid = cv2.VideoCapture(0)

while True:
    _, frame = vid.read()

    cv2.imshow("Frame", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

vid.release()
cv2.destroyAllWindows()

Part of the Crash Log (Full log click here)

Process:               Python [23472]
Path:                  /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.7.0 (3.7.0)
Code Type:             X86-64 (Native)
Parent Process:        zsh [22997]
Responsible:           Python [23472]
User ID:               501

Date/Time:             2018-10-09 14:39:32.725 +0800
OS Version:            Mac OS X 10.14 (18A391)
Report Version:        12
Anonymous UUID:        D946F646-E90A-A450-14FB-63EA96A4C90E


Time Awake Since Boot: 18000 seconds

System Integrity Protection: disabled

Crashed Thread:        3  Dispatch queue: com.apple.root.default-qos

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace TCC, Code 0x0

Solution

  • As per the suggestion from @w-m, apparently, the latest macOS variant has instilled a tight security layer on top of all apps.

    Now I can invoke the camera if and only if I used the native Terminal app. Hopefully, iTerm will roll out an update soon.

    Cheers!

    Update (6/11/2018): iTerm has released an update that will ask for camera permission.