首页 > 解决方案 > Python cv2.imshow() 因中止陷阱而崩溃:6

问题描述

我的代码:

import cv2
print(cv2.__version__)
img = cv2.imread("img.jpg")
print(len(img))
print("now showing")
cv2.imshow("img",img)
cv2.waitkey(0)

我也尝试过waitkey(1),但错误似乎发生在cv2.imshow第 6 行

错误跟踪:

objc[73658]: Class RunLoopModeTracker is implemented in both /Users/j/opt/anaconda3/lib/python3.7/site-packages/cv2/.dylibs/QtCore (0x110aca7f0) and /Users/j/opt/anaconda3/lib/libQt5Core.5.9.7.dylib (0x128e18a80). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7f80b2434fa0) is not the object's thread (0x7f80b244ec40).
Cannot move to target thread (0x7f80b2434fa0)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: cocoa, minimal, offscreen.

Abort trap: 6

标签: pythonopencvanacondaqt5cv2

解决方案


我遇到了同样的问题并找到了解决方案。

  1. pip 卸载 opencv-python 或 opencv-contrib-python

  2. pip install opencv-python-headless


推荐阅读