使用python访问图像信息,运行到cv2.imshow()的代码段时图像卡死且无反应,运行中止,
点击启动Jupyter Notebook的终端程序,终端上会记录Jupyter Notebook的运行信息,最后几行显示错误提示
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.
解决办法:
一、pip install opencv-python-headless ?
?再重启jupyter就可以了,如果安装opencv-python-headless的时候报错,可以重装opencv-python,再安装opencv-python-headless。
二、在imshow()语句后面加
cv2.waitKey()
cv2.destroyAllWindows()
这是使用opencv的一个习惯问题,在c++下,通常会在最后增加一个destroyWindow的操作,在jupyter notebook下也要增加这个操作。
但我先进行了opencv-python-headless的 安装,所以后面只加cv2.waitKey()也可以成功运行。
|