如何使用CV2.Imshow解决未指定的错误?

发布于 2025-01-30 08:43:07 字数 633 浏览 1 评论 0原文

我的代码仅在使用cv2.imshow()函数的点上破裂。它显示此错误: 错误:(-2:未指定的错误)未实现该函数。用Windows,GTK+ 2.X或可可支持重建库。如果您在Ubuntu或Debian上,请安装libgtk2.0-dev和pkg-config,然后重新运行cmake或在函数'cvshowimage'中配置脚本,

直到我安装了另一个库后,它一直工作正常,但是我'我不确定这会如何弄乱。我尝试卸载该额外的库,但这并没有采取任何措施来解决这个问题。有什么想法吗?我在网上发现的一些解决方案是使用PIP安装OpenCV-Python安装,但这就是我最初安装的方式。我还尝试卸载和重新安装OpenCV,但无济于事。

基于后续问题的其他详细信息:我使用Pycharm IDE在Windows计算机上,并且我一直在Minconda应用中使用PIP安装库。

这是代码的样子。我每当我尝试使用IMShow时都会发生错误,因此这是我运行的代码的一个示例,该示例会导致错误:

import cv2

img = cv2.imread("Tropical-tree.jpg")

cv2.imshow("Image", img)
cv2.waitKey(0)

My code keeps breaking only at points where I use the cv2.imshow() function. It displays this error:
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'

It was working fine until after I installed another library, but I'm not sure how that would mess it up. I tried uninstalling that extra library but that didn't do anything to fix the issue. Any ideas? Some of the solutions I've found online are to install with pip install opencv-python, but that's how I installed it initially. I have also tried uninstalling and reinstalling opencv to no avail.

Additional details based on follow-up questions: I'm on a Windows computer using the Pycharm IDE, and I've been installing libraries using pip in the Miniconda app.

Here is what the code looks like. The error happens anytime I try to use imshow, so here's one example of code I run that causes the error:

import cv2

img = cv2.imread("Tropical-tree.jpg")

cv2.imshow("Image", img)
cv2.waitKey(0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断肠人 2025-02-06 08:43:07

如果没有其他人遇到这个问题,则可以将来参考,这是我解决的方法,

我一直在使用Miniconda3程序中创建的环境。为了解决这个问题,我使用此命令为新的环境(也在Minconda中)进行了:
conda create -name new_env python = 3.6

openCV与python 3.6而不是最新更新最有效,因此在创建环境时指定版本很重要。然后,我使用pip install opencv-python重新安装了OpenCV,然后在Pycharm中我切换到使用该环境,并且效果很好。希望这对遇到这一目标的其他人有帮助!

For future reference if anyone else has this issue, here's how I solved it

I had been using an environment I made in the Miniconda3 program. To fix the issue, I made a new environment (also in Miniconda) using this command:
conda create --name new_env python=3.6

Opencv works best with python 3.6 rather than the newest update, so it's important to specify the version when creating the environment. Then I went in the environment and reinstalled opencv using pip install opencv-python, and then in Pycharm I switched to use that environment and it worked fine. Hope this helps anyone else who runs into this!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文