<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 簡介 EasyOCR是一個功能強大的開源光學字符識別OCR(Optical Character Recognition,光學字符識別)庫,它基于深度學習模型,能夠快速準確地識別圖片中的文字,并將這些文字轉換為可編輯和可搜索的文本格式。與傳統的 OCR 工具相比,EasyOCR 不僅識別速度快,還能處理各種復雜的文本圖像,如彎曲的文本、不同字體、各種語言混合的文本等。 在本文中,我們將介紹EasyOCR在Python和PHP兩種腳本基本使用方法和最佳實踐 ## 特點和優勢 1. **多語言支持**:EasyOCR支持包括中文簡體、英文在內的80多種語言的文本識別,這使其能夠廣泛應用于不同語言和地區的場景。 2. **易于安裝和使用**:EasyOCR提供了簡單易用的API,用戶可以通過簡單的Python代碼實現復雜的文字識別任務。同時,它也支持GPU加速,能夠顯著提高識別速度和效率。 3. **靈活性強**:EasyOCR不僅支持單語言識別,還能夠處理多語言混合的情況,這對于包含多種語言文本的圖片識別非常有用。此外,它還支持對識別結果進行后處理,如去噪、二值化、旋轉校正等,以提高識別精度。 4. **廣泛的應用場景**:EasyOCR適用于多種需要從圖像中提取文本的場景,如文檔數字化、名片信息提取、車牌識別、街道標識識別、產品包裝信息提取、手寫文字識別等。這些應用場景涵蓋了學習、工作、生活等多個方面,為用戶提供了極大的便利。 5. **面向開發者的SDK集成**:EasyOCR不僅為消費者提供服務,更主要面向開發,能夠提供本地化的開發SDK集成,與C/S、B/S及Android移動端項目進行原生集成。這使得開發者可以將其集成到自己的應用中,實現更豐富的功能和更好的用戶體驗。 6. **商業支持**:隨著版本的更新和迭代,EasyOCR在商業領域也得到了廣泛的應用。它能夠為銀行、爬蟲應用、支付、大數據處理以及在線游戲圖形數據分析處理等領域提供OCR引擎支持,幫助這些行業實現更高效的數據處理和分析。 ## 環境配置 如何構建環境:[PHP快速入門開源大模型平臺魔塔ModelScope](https://mp.weixin.qq.com/s/p5x2XwJgPpodZI_Woa8qPA) 查看已有的虛擬環境 ```ts conda env list # conda environments: # base /home/www/anaconda3 tinywan-modelscope /home/www/anaconda3/envs/tinywan-modelscope ``` 激活虛擬環境 ```ts conda activate tinywan-modelscope ``` 查看Python環境 ```ts python -V Python 3.10.13 ``` ```php <?php /** * @desc phpy.php * @author Tinywan(ShaoBo Wan) */ declare(strict_types=1); // 導入 Python 模塊 $os = PyCore::import("os"); echo $os->version(). PHP_EOL; ``` 測試打印 ```ts /usr/local/php-8.2.14/bin/php phpy01.php posix.uname_result(sysname='Linux', nodename='ShaoBoWan', release='4.15.0-137-generic', version='#141-Ubuntu SMP Fri Feb 19 13:46:27 UTC 2021' machine='x86_64') ``` 輸出以上信息表示環境和擴展沒問題啦! ## 安裝easyocr ```ts pip install easyocr ``` 安裝過程 ```ts Looking in indexes: https://mirrors.cloud.aliyuncs.com/pypi/simple Collecting easyocr Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/cb/0e/09bafec31db720e796d3f5b0814c37c5fdb59dcd35a2c6c6b1c774b09646/easyocr-1.7.1-py3-none-any.whl (2.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.9/2.9 MB 10.3 MB/s eta 0:00:00 Requirement already satisfied: torch in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (2.2.1) Requirement already satisfied: torchvision>=0.5 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (0.17.1) Collecting opencv-python-headless (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/d1/09/248f86a404567303cdf120e4a301f389b68e3b18e5c0cc428de327da609c/opencv_python_headless-4.10.0.84-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.9/49.9 MB 51.2 MB/s eta 0:00:00 Requirement already satisfied: scipy in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (1.12.0) Requirement already satisfied: numpy in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (1.26.4) Requirement already satisfied: Pillow in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (10.2.0) Collecting scikit-image (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/40/2e/8b39cd2c347490dbe10adf21fd50bbddb1dada5bb0512c3a39371285eb62/scikit_image-0.24.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.9/14.9 MB 63.3 MB/s eta 0:00:00 Collecting python-bidi (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/0a/af/3a29cee9d2b8feaa796f567debf456adb506811bdd333eff77c138b95137/python_bidi-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (281 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 281.3/281.3 kB 37.9 MB/s eta 0:00:00 Requirement already satisfied: PyYAML in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from easyocr) (6.0.1) Collecting Shapely (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/2b/a6/302e0d9c210ccf4d1ffadf7ab941797d3255dcd5f93daa73aaf116a4db39/shapely-2.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 MB 83.6 MB/s eta 0:00:00 Collecting pyclipper (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/1c/81/4aa8403e587a4c60e00b479c11254a6e3200f3b985dcf4caecf0d8c21261/pyclipper-1.3.0.post5-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (908 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 908.3/908.3 kB 70.6 MB/s eta 0:00:00 Collecting ninja (from easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/6d/92/8d7aebd4430ab5ff65df2bfee6d5745f95c004284db2d8ca76dcbfd9de47/ninja-1.11.1.1-py2.py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl (307 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 307.2/307.2 kB 41.5 MB/s eta 0:00:00 Requirement already satisfied: filelock in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (3.13.1) Requirement already satisfied: typing-extensions>=4.8.0 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (4.10.0) Requirement already satisfied: sympy in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (1.12) Requirement already satisfied: networkx in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (3.2.1) Requirement already satisfied: jinja2 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (3.1.3) Requirement already satisfied: fsspec in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (2024.2.0) Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.105) Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.105) Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.105) Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (8.9.2.26) Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.3.1) Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (11.0.2.54) Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (10.3.2.106) Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (11.4.5.107) Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.0.106) Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (2.19.3) Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (12.1.105) Requirement already satisfied: triton==2.2.0 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from torch->easyocr) (2.2.0) Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch->easyocr) (12.4.99) Collecting imageio>=2.33 (from scikit-image->easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/1e/b7/02adac4e42a691008b5cfb31db98c190e1fc348d1521b9be4429f9454ed1/imageio-2.35.1-py3-none-any.whl (315 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 315.4/315.4 kB 33.4 MB/s eta 0:00:00 Collecting tifffile>=2022.8.12 (from scikit-image->easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/da/3a/22edea4fd64c40394e4c38ead42c95f5f339c52650ea9b3a870d1c091697/tifffile-2024.8.28-py3-none-any.whl (226 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 226.1/226.1 kB 5.4 MB/s eta 0:00:00 Requirement already satisfied: packaging>=21 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from scikit-image->easyocr) (24.0) Collecting lazy-loader>=0.4 (from scikit-image->easyocr) Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/83/60/d497a310bde3f01cb805196ac61b7ad6dc5dcf8dce66634dc34364b20b4f/lazy_loader-0.4-py3-none-any.whl (12 kB) Requirement already satisfied: MarkupSafe>=2.0 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from jinja2->torch->easyocr) (2.1.5) Requirement already satisfied: mpmath>=0.19 in /home/www/anaconda3/envs/tinywan-modelscope/lib/python3.10/site-packages (from sympy->torch->easyocr) (1.3.0) Installing collected packages: python-bidi, pyclipper, ninja, tifffile, Shapely, opencv-python-headless, lazy-loader, imageio, scikit-image, easyocr Attempting uninstall: lazy-loader Found existing installation: lazy_loader 0.3 Uninstalling lazy_loader-0.3: Successfully uninstalled lazy_loader-0.3 Successfully installed Shapely-2.0.6 easyocr-1.7.1 imageio-2.35.1 lazy-loader-0.4 ninja-1.11.1.1 opencv-python-headless-4.10.0.84 pyclipper-1.3.0.post5 python-bidi-0.6.0 scikit-image-0.24.0 tifffile-2024.8.28 [notice] A new release of pip is available: 24.0 -> 24.2 [notice] To update, run: pip install --upgrade pip ``` 查看已安裝的版本 ```ts (tinywan-modelscope) www@ pip list |grep easyocr easyocr 1.7.1 [notice] A new release of pip is available: 24.0 -> 24.2 [notice] To update, run: pip install --upgrade pip ``` ## 使用 本次OCR需要識別的圖片`demo.png` ![](https://img.kancloud.cn/43/77/4377b08805cfb73cce4f6e56f307c885_900x383.png) ### Python腳本 編寫OCR識別腳本`resty_easyocr.py` ```python import easyocr import sys def extract_text_from_image(image_path): """ 從給定的圖片路徑中提取文本。 參數: image_path (str): 圖片文件的路徑。 返回: str: 提取的文本,每行文本之間用換行符分隔。 """ # 初始化EasyOCR,指定需要識別的語言,這里是中國簡體(ch_sim)和英文(en) reader = easyocr.Reader(['ch_sim', 'en']) # 使用readtext方法從圖片中讀取文本 results = reader.readtext(image_path) # 初始化一個空字符串用于存儲提取的文本 text = "" # 遍歷識別結果 for result in results: # 每個result是一個元組,其中result[0]是邊界框信息,result[1]是識別到的文本 # 這里我們只需要文本部分,并將其添加到text字符串中,每個文本后添加一個換行符 text += result[1] + "\n" # 返回最終提取的文本 return text if __name__ == "__main__": # 檢查是否提供了命令行參數(圖片路徑) if len(sys.argv) != 2: print("Usage: python script.py <image_path>") sys.exit(1) # 非零退出碼表示錯誤 # 從命令行參數中獲取圖片路徑 image_path = sys.argv[1] # 調用函數提取文本 text = extract_text_from_image(image_path) # 打印提取的文本 print(text) ``` 執行命令識別結果 ``` (tinywan-modelscope) D:\AI\python>python resty_easyocr.py .\demo.png Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. D:\anaconda3\envs\tinywan-modelscope\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))) D:\anaconda3\envs\tinywan-modelscope\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) Casbin實戰教程 ABAC模型策略設計研發 ``` ![](https://img.kancloud.cn/2a/9f/2a9f0df867f7657c28e4e4db94f6130e_1116x496.png) ### PHP腳本 通過韓大佬提供轉換地址:`https://swoole.com/py2php/` 轉換后的腳本`resty_easyocr.php` ```php <?php /** * @desc phpy.php * @author Tinywan(ShaoBo Wan) */ declare(strict_types=1); $operator = PyCore::import("operator"); $builtins = PyCore::import("builtins"); $easyocr = PyCore::import('easyocr'); function extract_text_from_image($image_path) { $reader = $easyocr->Reader(new PyList(["ch_sim", "en"])); $results = $reader->readtext($image_path); $text = ""; $__iter = PyCore::iter($results); while ($current = PyCore::next($__iter)) { $result = $current; $text += $result[1] + "\n"; } return $text; } $image_path = ''./demo.png';'; $text = extract_text_from_image($image_path); PyCore::print($text); ``` 如果事先沒有安裝檢測模型和識別模型,第一次執行腳本時會自動下載2種模型文件 ```ts /usr/local/php-8.2.14/bin/php resty_easyocr.php Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. Downloading detection model, please wait. This may take several minutes depending upon your network connection. Progress: |--------------------------------------------------| 0.3% Complete 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) Casbin實戰教程 ABAC模型策略設計研發 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看