cv2.imshow error: (-2:Unspecified error) The function is not implemented.问题解决

在运行opencv的python代码时,调用cv2.imshow时报错,如下所示

cv2.imshow(opencv_title, out)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1268: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

先用以下命令,查看opencv安装情况

pip list

结果如图所示,opencv和contrib库都有安装,且版本一致。

 

几经周折,查到问题解决方法,参考https://github.com/opencv/opencv-python/issues/18

卸载掉opencv-python-headless即可

 pip uninstall opencv-python-headless

卸载完应该就可以正常运行了。

如果仍然无法运行,如以下报错:

AttributeError: module 'cv2' has no attribute 'imread'

则先全卸载

pip uninstall opencv-python
pip uninstall opencv-contrib-python

再安装

pip install opencv-contrib-python
pip install opencv-python

应该就不会再报错了。

注意再安装时的版本最好与之前一致,否者可能导致与其它库版本不兼容的情况。

你可能感兴趣的:(opencv,人工智能,计算机视觉)