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()