代碼:
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