cv2.imshow()安装easyocr时不起作用

发布于 2025-01-31 11:13:59 字数 535 浏览 3 评论 0原文

我使用pip install easyocr 在新创建的Python环境中安装了easyocr。 然后我安装了opencv-python

当我尝试执行代码时 -

import cv2

img = cv2.imread('2.jpg')
cv2.imshow('sd',img)
cv2.waitKey(0)

这是错误的错误

openCV(4.5.5)d:\ a \ opencv-python \ opencv-python \ opencv \ imules \ highgui \ src \ src \ window.cpp:1268:error:( - 2:未指定的错误)未实现该功能。 。用Windows,GTK+ 2.X或可可支持重建库。如果您在ubuntu或debian上,请安装libgtk2.0-dev和pkg-config,然后重新运行cmake或在函数中配置脚本'cvshowimage'

I installed easyocr in a newly created python environment using pip install easyocr.
Then i installed opencv-python.

when i try to execute the code -

import cv2

img = cv2.imread('2.jpg')
cv2.imshow('sd',img)
cv2.waitKey(0)

It's giving 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'

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

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

发布评论

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

评论(1

小…楫夜泊 2025-02-07 11:13:59

问题:

如果您已经在系统/环境中拥有现有OpenCV版本;安装easyocr可以更改它。通过 sumplliences.txt file.txt fileeasyocropencv-python-headless被安装。

以下摘录摘自 opencv-python-headless document> document> document ::

服务器(无头)环境的软件包(例如Docker,云环境等),没有GUI库依赖项

这些软件包比上面的其他两个软件包小,因为它们不包含任何GUI功能(不包含QT /其他GUI组件)。这意味着这些软件包避免了X11库的较重依赖链,因此您将有较小的Docker图像。如果您不使用CV2.Imshow等人,则应始终使用这些软件包。或者,您正在使用其他一些软件包(例如pyqt)来创建您的GUI。

tldr;

简而言之,easyocr禁用现有的GUI功能。它是专门针对容器化的应用程序和/或服务器部署而设计的。

解决方案:

要使用easyocr使用opencv,您可以尝试以下任一项:

1。更改安装顺序:

可以使用pip:首先安装EasyOROCR进行所有以下操作

  • 卸载OpenCV-Python-Headless
  • 安装opencv-python

2。使用matplotlib

仍然可以使用matplotlib

import cv2
from matplotlib import pyplot as plt
img = cv2.imread('img.jpg',0)
plt.imshow(img)
plt.show()

Problem:

If you already have an existing OpenCV version in your system/environment; installing easyOCR can alter that. Going through the requirements.txt file of easyOCR, opencv-python-headless gets installed.

The following excerpt is taken from opencv-python-headless documentation:

Packages for server (headless) environments (such as Docker, cloud environments etc.), no GUI library dependencies

These packages are smaller than the two other packages above because they do not contain any GUI functionality (not compiled with Qt / other GUI components). This means that the packages avoid a heavy dependency chain to X11 libraries and you will have for example smaller Docker images as a result. You should always use these packages if you do not use cv2.imshow et al. or you are using some other package (such as PyQt) than OpenCV to create your GUI.

TLDR;

In short, easyocr disables existing GUI capabilities. It has been designed exclusively for containerized applications and/or server deployments.

Solution:

To use easyOCR with OpenCV, you can try either one of the following:

1. Change installation sequence:

All the following can be done using pip:

  • First install easyocr.
  • Uninstall opencv-python-headless.
  • Install opencv-python

2. Use matplotlib

One can still display images using matplotlib:

import cv2
from matplotlib import pyplot as plt
img = cv2.imread('img.jpg',0)
plt.imshow(img)
plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文