Python 在 MacOS Mojave 中使用 OpenCV 崩溃

Python crashed with OpenCV in MacOS Mojave

我将 MacBook 升级到 MacOS Mojave 后不久我的 OpenCV 程序就坏了。

安装了以下组合,但似乎没有任何效果。

Python 3.6.5 with OpenCV 3.4.1

Python 3.7.0 with OpenCV 3.4.3

简单的测试程序

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

部分崩溃日志(完整日志点击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

根据@w-m 的建议,显然,最新的 macOS 变体在所有应用程序之上灌输了一个严密的安全层。

现在,当且仅当我使用本机终端应用程序时,我才能调用相机。希望 iTerm 很快推出更新。

干杯!

更新 (6/11/2018):iTerm 发布了一个更新,会请求相机权限。