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.39k stars 3.16k forks source link

Unable to install #1304

Open elnath78 opened 1 month ago

elnath78 commented 1 month ago

I'm not much into python, I get some weird error, looks like I have more than one version so not sure how to run the correct one, here is what I run and the result:

python -m pip install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already up-to-date: pip in c:\python27\lib\site-packages (20.3.4)

So pip is fine however when I run I get this error:

pip install easyocr
Collecting easyocr
  Using cached https://files.pythonhosted.org/packages/cb/0e/09bafec31db720e796d3f5b0814c37c5fdb59dcd35a2c6c6b1c774b09646/easyocr-1.7.1-py3-none-any.whl
Collecting scipy (from easyocr)
  Using cached https://files.pythonhosted.org/packages/f3/9f/80522344838ae24cac9e945240436269cbb92349f7f1f4c9dfc10cb6bad5/scipy-1.5.4-cp36-cp36m-win_amd64.whl
Collecting opencv-python-headless (from easyocr)
  Using cached https://files.pythonhosted.org/packages/2f/7e/d20f68a5f1487adf19d74378d349932a386b1ece3be9be9915e5986db468/opencv-python-headless-4.10.0.84.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting Shapely (from easyocr)
  Using cached https://files.pythonhosted.org/packages/b6/8f/f1beeb3585a7db42062bb67ce1766b55a7b3e25af1a916a0879bc249b5c9/Shapely-1.8.5.post1-cp36-cp36m-win_amd64.whl
Collecting python-bidi (from easyocr)
  Using cached https://files.pythonhosted.org/packages/42/72/798318217bf0ee8e68af67e6e23c5e1017b9ab83b96019bf240da7b7a72f/python_bidi-0.6.0.tar.gz
  Installing build dependencies ... error
  ERROR: Complete output from command 'c:\python36\python.exe' 'c:\python36\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\pc\AppData\Local\Temp\pip-build-env-rtrw680t\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'maturin>=1,<2':
  ERROR: Collecting maturin<2,>=1
    ERROR: Could not find a version that satisfies the requirement maturin<2,>=1 (from versions: 0.7.0, 0.7.1, 0.7.2, 0.7.4, 0.7.5, 0.7.6, 0.7.7, 0.7.8, 0.7.9, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.9.0, 0.9.1, 0.9.3, 0.9.4, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.4, 0.10.5, 0.10.6, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.11.4, 0.11.5, 0.12.0, 0.12.1, 0.12.2, 0.12.3, 0.12.4, 0.12.5, 0.12.6, 0.12.7, 0.12.8, 0.12.9, 0.12.10, 0.12.11, 0.12.12, 0.12.13, 0.12.14, 0.12.15, 0.12.16, 0.12.17, 0.12.18b1, 0.12.18b2, 0.12.18, 0.12.19, 0.12.20)
  ERROR: No matching distribution found for maturin<2,>=1
  WARNING: You are using pip version 19.1.1, however version 21.3.1 is available.
  You should consider upgrading via the 'python -m pip install --upgrade pip' command.
  ----------------------------------------
ERROR: Command "'c:\python36\python.exe' 'c:\python36\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\pc\AppData\Local\Temp\pip-build-env-rtrw680t\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'maturin>=1,<2'" failed with error code 1 in None
WARNING: You are using pip version 19.1.1, however version 21.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

It is kind of trolling me, I just run the command to ugrade pip and everything was fine.

elnath78 commented 1 month ago

Ok managed to update pip for the correct python version and get EasyOCR, but now I'm getting this warning and no result:

Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
c:\python312\Lib\site-packages\easyocr\detection.py:78: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device)))
c:\python312\Lib\site-packages\easyocr\recognition.py:169: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state_dict = torch.load(model_path, map_location=device)
elnath78 commented 1 month ago

This is what I'm running:

import easyocr
import os

# Path to the directory containing frames
frames_dir = 'C:/honor/png'

# Path to save the extracted text files
output_dir = 'C:/honor/ocr'

# Create output directory if it doesn't exist
if not os.path.exists(output_dir):
    os.makedirs(output_dir)

# Create an EasyOCR Reader instance
reader = easyocr.Reader(['en'])

# Loop through each frame in the directory
for filename in os.listdir(frames_dir):
    if filename.endswith('.png') or filename.endswith('.jpg'):  # Adjust based on your frame format
        frame_path = os.path.join(frames_dir, filename)

        # Perform OCR
        results = reader.readtext(frame_path)

        # Prepare the output text file path
        output_file_path = os.path.join(output_dir, f'{os.path.splitext(filename)[0]}.txt')

        # Open the file and write the extracted text
        with open(output_file_path, 'w', encoding='utf-8') as text_file:
            for result in results:
                text_file.write(result[1] + '\n')  # Write the text to file with newlines between results

        print(f'Extracted text from {filename} saved to {output_file_path}')