在运行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
应该就不会再报错了。文章来源:https://www.toymoban.com/news/detail-563020.html
注意再安装时的版本最好与之前一致,否者可能导致与其它库版本不兼容的情况。文章来源地址https://www.toymoban.com/news/detail-563020.html
到了这里,关于cv2.imshow error: (-2:Unspecified error) The function is not implemented.问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!