Python cv2.imshow() crashes with Abort trap: 6

代码:

import cv2

img1 = cv2.imread('test.jpg')
cv2.imshow('img', img1)
cv2.waitKey(0)
cv2.destroyAllWindows()

报错如下:

objc[73658]: Class RunLoopModeTracker is implemented in both */anaconda3/lib/python3.7/site-packages/cv2/.dylibs/QtCore (0x110aca7f0) and */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

错误的原因在于opencv中有pyQt,而另外又装了PyQt5,二者不知道使用哪一个,造成冲突。
解决方案:卸载opencv,安装opencv-python-headless

pip uninstall opencv-python or opencv-contrib-python
pip install opencv-python-headless
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容