cv2.imshow() 在安装了 easyocr 后不起作用
cv2.imshow() doesnt work when easyocr installed
我使用 pip
安装 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\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'
问题:
如果您的 system/environment 中已有 OpenCV
版本;安装 easyOCR
可以改变它。通过 easyOCR
的 requirements.txt file
,安装 opencv-python-headless
。
以下摘录自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;
简而言之,easyocr
禁用现有的 GUI 功能。它专为容器化应用程序 and/or 服务器部署而设计。
解决方案:
要将 easyOCR
与 OpenCV
一起使用,您可以尝试以下任一方法:
1.更改安装顺序:
可以使用 pip
完成以下所有操作:
- 首先安装
easyocr
.
- 卸载
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()
我使用 pip
安装 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\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'
问题:
如果您的 system/environment 中已有 OpenCV
版本;安装 easyOCR
可以改变它。通过 easyOCR
的 requirements.txt file
,安装 opencv-python-headless
。
以下摘录自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;
简而言之,easyocr
禁用现有的 GUI 功能。它专为容器化应用程序 and/or 服务器部署而设计。
解决方案:
要将 easyOCR
与 OpenCV
一起使用,您可以尝试以下任一方法:
1.更改安装顺序:
可以使用 pip
完成以下所有操作:
- 首先安装
easyocr
. - 卸载
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()