JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
24.51k stars 3.16k forks source link

error when reading an png #640

Closed MicalKarl closed 2 years ago

MicalKarl commented 2 years ago
Traceback (most recent call last):
  File "testocr.py", line 5, in <module>
    result = reader.readtext('1.png')
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\easyocr.py", line 385, in readtext
    horizontal_list, free_list = self.detect(img, min_size, text_threshold,\
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\easyocr.py", line 275, in detect
    text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio,
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\detection.py", line 95, in get_textbox
    bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector,
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\detection.py", line 55, in test_net
    boxes, polys, mapper = getDetBoxes(
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\craft_utils.py", line 236, in getDetBoxes
    boxes, labels, mapper = getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars)
  File "C:\Users\karl\Desktop\test\venv\lib\site-packages\easyocr\craft_utils.py", line 31, in getDetBoxes_core
    nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4)
cv2.error: Unknown C++ exception from OpenCV code
Aslyamovt commented 2 years ago

Same problem with all images

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9312/3775422832.py in <module>
      1 s = time.time()
----> 2 result = reader.readtext(path)
      3 print(time.time()-s)

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\easyocr.py in readtext(self, image, decoder, beamWidth, batch_size, workers, allowlist, blocklist, detail, rotation_info, paragraph, min_size, contrast_ths, adjust_contrast, filter_ths, text_threshold, low_text, link_threshold, canvas_size, mag_ratio, slope_ths, ycenter_ths, height_ths, width_ths, y_ths, x_ths, add_margin, output_format)
    383         img, img_cv_grey = reformat_input(image)
    384 
--> 385         horizontal_list, free_list = self.detect(img, min_size, text_threshold,\
    386                                                  low_text, link_threshold,\
    387                                                  canvas_size, mag_ratio,\

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\easyocr.py in detect(self, img, min_size, text_threshold, low_text, link_threshold, canvas_size, mag_ratio, slope_ths, ycenter_ths, height_ths, width_ths, add_margin, reformat, optimal_num_chars)
    273             img, img_cv_grey = reformat_input(img)
    274 
--> 275         text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio,
    276                                     text_threshold, link_threshold, low_text,
    277                                     False, self.device, optimal_num_chars)

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\detection.py in get_textbox(detector, image, canvas_size, mag_ratio, text_threshold, link_threshold, low_text, poly, device, optimal_num_chars)
     92     result = []
     93     estimate_num_chars = optimal_num_chars is not None
---> 94     bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector,
     95                                        image, text_threshold,
     96                                        link_threshold, low_text, poly,

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\detection.py in test_net(canvas_size, mag_ratio, net, image, text_threshold, link_threshold, low_text, poly, device, estimate_num_chars)
     52 
     53         # Post-processing
---> 54         boxes, polys, mapper = getDetBoxes(
     55             score_text, score_link, text_threshold, link_threshold, low_text, poly, estimate_num_chars)
     56 

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\craft_utils.py in getDetBoxes(textmap, linkmap, text_threshold, link_threshold, low_text, poly, estimate_num_chars)
    234     if poly and estimate_num_chars:
    235         raise Exception("Estimating the number of characters not currently supported with poly.")
--> 236     boxes, labels, mapper = getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars)
    237 
    238     if poly:

D:\Anaconda\envs\ocr\lib\site-packages\easyocr\craft_utils.py in getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars)
     29 
     30     text_score_comb = np.clip(text_score + link_score, 0, 1)
---> 31     nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4)
     32 
     33     det = []

error: Unknown C++ exception from OpenCV code

Conda environment:

# packages in environment at D:\Anaconda\envs\ocr:
#
# Name                    Version                   Build  Channel
argon2-cffi               21.3.0                   pypi_0    pypi
argon2-cffi-bindings      21.2.0                   pypi_0    pypi
attrs                     21.4.0                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
blas                      2.106                       mkl    conda-forge
bleach                    4.1.0                    pypi_0    pypi
ca-certificates           2021.10.8            h5b45459_0    conda-forge
cffi                      1.15.0                   pypi_0    pypi
colorama                  0.4.4                    pypi_0    pypi
cudatoolkit               10.2.89              hb195166_9    conda-forge
debugpy                   1.5.1                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
easyocr                   1.4                      pypi_0    pypi
entrypoints               0.3                      pypi_0    pypi
freetype                  2.10.4               h546665d_1    conda-forge
imageio                   2.9.0                    pypi_0    pypi
importlib-resources       5.4.0                    pypi_0    pypi
intel-openmp              2022.0.0          h57928b3_3663    conda-forge
ipykernel                 6.6.1                    pypi_0    pypi
ipython                   7.31.0                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
ipywidgets                7.6.5                    pypi_0    pypi
jbig                      2.1               h8d14728_2003    conda-forge
jedi                      0.18.1                   pypi_0    pypi
jinja2                    3.0.3                    pypi_0    pypi
jpeg                      9d                   h8ffe710_0    conda-forge
jsonschema                4.3.3                    pypi_0    pypi
jupyter                   1.0.0                    pypi_0    pypi
jupyter-client            7.1.0                    pypi_0    pypi
jupyter-console           6.4.0                    pypi_0    pypi
jupyter-core              4.9.1                    pypi_0    pypi
jupyterlab-pygments       0.1.2                    pypi_0    pypi
jupyterlab-widgets        1.0.2                    pypi_0    pypi
lcms2                     2.12                 h2a16943_0    conda-forge
lerc                      3.0                  h0e60522_0    conda-forge
libblas                   3.9.0                     6_mkl    conda-forge
libcblas                  3.9.0                     6_mkl    conda-forge
libdeflate                1.8                  h8ffe710_0    conda-forge
liblapack                 3.9.0                     6_mkl    conda-forge
liblapacke                3.9.0                     6_mkl    conda-forge
libpng                    1.6.37               h1d00b33_2    conda-forge
libtiff                   4.3.0                hd413186_2    conda-forge
libuv                     1.42.0               h8ffe710_0    conda-forge
libzlib                   1.2.11            h8ffe710_1013    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
markupsafe                2.0.1                    pypi_0    pypi
matplotlib-inline         0.1.3                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
mkl                       2020.4             hb70f87d_311    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
nbclient                  0.5.9                    pypi_0    pypi
nbconvert                 6.4.0                    pypi_0    pypi
nbformat                  5.1.3                    pypi_0    pypi
nest-asyncio              1.5.4                    pypi_0    pypi
networkx                  2.6.3                    pypi_0    pypi
notebook                  6.4.6                    pypi_0    pypi
numpy                     1.22.0           py38hcf66579_0    conda-forge
olefile                   0.46               pyh9f0ad1d_1    conda-forge
opencv-python             4.5.5.62                 pypi_0    pypi
opencv-python-headless    4.5.5.62                 pypi_0    pypi
openjpeg                  2.4.0                hb211442_1    conda-forge
openssl                   3.0.0                h8ffe710_2    conda-forge
packaging                 21.3                     pypi_0    pypi
pandocfilters             1.5.0                    pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    8.2.0                    pypi_0    pypi
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
prometheus-client         0.12.0                   pypi_0    pypi
prompt-toolkit            3.0.24                   pypi_0    pypi
pycparser                 2.21                     pypi_0    pypi
pygments                  2.11.2                   pypi_0    pypi
pyparsing                 3.0.6                    pypi_0    pypi
pyrsistent                0.18.0                   pypi_0    pypi
python                    3.8.12          h900ac77_2_cpython    conda-forge
python-bidi               0.4.2                    pypi_0    pypi
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.8                      2_cp38    conda-forge
pytorch                   1.10.1          py3.8_cuda10.2_cudnn7_0    pytorch
pytorch-mutex             1.0                        cuda    pytorch
pywavelets                1.2.0                    pypi_0    pypi
pywin32                   303                      pypi_0    pypi
pywinpty                  1.1.6                    pypi_0    pypi
pyyaml                    6.0                      pypi_0    pypi
pyzmq                     22.3.0                   pypi_0    pypi
qtconsole                 5.2.2                    pypi_0    pypi
qtpy                      2.0.0                    pypi_0    pypi
scikit-image              0.19.1                   pypi_0    pypi
scipy                     1.7.3                    pypi_0    pypi
send2trash                1.8.0                    pypi_0    pypi
setuptools                60.5.0           py38haa244fe_0    conda-forge
six                       1.16.0                   pypi_0    pypi
sqlite                    3.37.0               h8ffe710_0    conda-forge
terminado                 0.12.1                   pypi_0    pypi
testpath                  0.5.0                    pypi_0    pypi
tifffile                  2021.11.2                pypi_0    pypi
tk                        8.6.11               h8ffe710_1    conda-forge
torchvision               0.11.2               py38_cu102    pytorch
tornado                   6.1                      pypi_0    pypi
traitlets                 5.1.1                    pypi_0    pypi
typing_extensions         4.0.1              pyha770c72_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
vc                        14.2                 hb210afc_6    conda-forge
vs2015_runtime            14.29.30037          h902a5da_6    conda-forge
wcwidth                   0.2.5                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
widgetsnbextension        3.5.2                    pypi_0    pypi
xz                        5.2.5                h62dcd97_1    conda-forge
zipp                      3.7.0                    pypi_0    pypi
zlib                      1.2.11            h8ffe710_1013    conda-forge
zstd                      1.5.1                h6255e5f_0    conda-forge
Aslyamovt commented 2 years ago

@MicalKarl solved this problem by opencv-python-headless и opencv-python of version 4.5.1.48

MicalKarl commented 2 years ago

@MicalKarl solved this problem by opencv-python-headless и opencv-python of version 4.5.1.48

It works! @Aslyamovt

ghLcd9dG commented 2 years ago

It workss!!!!

egeres commented 2 years ago

I was getting the same issue (which hadn't happened before, I have no idea how this broke out of nowhere)

Fixed it with the pip install opencv-python-headless==4.5.1.48 @Aslyamovt mentioned and was changed in https://github.com/xuyichenmo/EasyOCR/commit/3333f241349ddaf45477cc1bcda768da56d338dd

Furippu24 commented 2 years ago

Hi all, I am getting the same issue, but issue does not fix by changing opencv-python-headless and opencv-python versions to either 4.5.1.48 nor 4.5.4.60.

Traceback (most recent call last): File "C:\Users\fish\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 9, in <module> File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\easyocr.py", line 385, in readtext horizontal_list, free_list = self.detect(img, min_size, text_threshold,\ File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\easyocr.py", line 275, in detect text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio, File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\detection.py", line 95, in get_textbox bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector, File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\detection.py", line 55, in test_net boxes, polys, mapper = getDetBoxes( File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\craft_utils.py", line 236, in getDetBoxes boxes, labels, mapper = getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars) File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\craft_utils.py", line 31, in getDetBoxes_core nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4) cv2.error: Unknown C++ exception from OpenCV code

click 8.0.4 colorama 0.4.4 cycler 0.11.0 easyocr 1.4.1 fonttools 4.29.1 imageio 2.9.0 joblib 1.1.0 kiwisolver 1.3.2 lmdb 1.3.0 matplotlib 3.5.1 natsort 8.1.0 networkx 2.6.3 NEURON 8.0 nltk 3.7 numpy 1.22.2 opencv-python 4.5.1.48 opencv-python-headless 4.5.1.48 packaging 21.3 pandas 1.4.1 pdf2image 1.16.0 Pillow 8.2.0 pip 22.0.3 plotly 5.6.0 pyparsing 3.0.7 python-bidi 0.4.2 python-dateutil 2.8.2 pytz 2021.3 PyWavelets 1.2.0 PyYAML 6.0 regex 2022.1.18 scikit-image 0.19.2 scipy 1.8.0 setuptools 57.0.0 six 1.16.0 tenacity 8.0.1 tifffile 2022.2.9 torch 1.10.2 torchaudio 0.10.2 torchvision 0.11.3 tqdm 4.62.3 typing_extensions 4.1.1 wheel 0.36.2

Furippu24 commented 2 years ago

Hi all, I am getting the same issue, but issue does not fix by changing opencv-python-headless and opencv-python versions to either 4.5.1.48 nor 4.5.4.60.

Traceback (most recent call last): File "C:\Users\fish\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 9, in <module> File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\easyocr.py", line 385, in readtext horizontal_list, free_list = self.detect(img, min_size, text_threshold,\ File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\easyocr.py", line 275, in detect text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio, File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\detection.py", line 95, in get_textbox bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector, File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\detection.py", line 55, in test_net boxes, polys, mapper = getDetBoxes( File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\craft_utils.py", line 236, in getDetBoxes boxes, labels, mapper = getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars) File "C:\Users\fish\PycharmProjects\PDFOCR\venv\lib\site-packages\easyocr\craft_utils.py", line 31, in getDetBoxes_core nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4) cv2.error: Unknown C++ exception from OpenCV code

click 8.0.4 colorama 0.4.4 cycler 0.11.0 easyocr 1.4.1 fonttools 4.29.1 imageio 2.9.0 joblib 1.1.0 kiwisolver 1.3.2 lmdb 1.3.0 matplotlib 3.5.1 natsort 8.1.0 networkx 2.6.3 NEURON 8.0 nltk 3.7 numpy 1.22.2 opencv-python 4.5.1.48 opencv-python-headless 4.5.1.48 packaging 21.3 pandas 1.4.1 pdf2image 1.16.0 Pillow 8.2.0 pip 22.0.3 plotly 5.6.0 pyparsing 3.0.7 python-bidi 0.4.2 python-dateutil 2.8.2 pytz 2021.3 PyWavelets 1.2.0 PyYAML 6.0 regex 2022.1.18 scikit-image 0.19.2 scipy 1.8.0 setuptools 57.0.0 six 1.16.0 tenacity 8.0.1 tifffile 2022.2.9 torch 1.10.2 torchaudio 0.10.2 torchvision 0.11.3 tqdm 4.62.3 typing_extensions 4.1.1 wheel 0.36.2

Sorry, I just had "WARNING: Ignoring invalid distribution" for opencv packages ~ working now

nqx12348 commented 2 years ago

@MicalKarl solved this problem by opencv-python-headless и opencv-python of version 4.5.1.48

I meet the same problem, and it works to use opencv-python==4.5.1.48. Thanks!