Commit 4b041d81 authored by AYOUB ABOUNAMER's avatar AYOUB ABOUNAMER

Upload New File

parent e1f23002
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "paddleOCR.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "DWtMMessJXUk",
"outputId": "bb44974d-6e21-4ac0-9cad-75648d4e1c34"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Looking in indexes: https://mirror.baidu.com/pypi/simple\n",
"Collecting paddlepaddle\n",
" Downloading https://mirror.baidu.com/pypi/packages/e4/42/3a91bff89038a9773b2df69610293e759ed6e1de6fe115503d1132805103/paddlepaddle-2.2.2-cp37-cp37m-manylinux1_x86_64.whl (108.4 MB)\n",
"\u001b[K |████████████████████████████████| 108.4 MB 25 kB/s \n",
"\u001b[?25hRequirement already satisfied: decorator in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (4.4.2)\n",
"Requirement already satisfied: astor in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (0.8.1)\n",
"Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (7.1.2)\n",
"Requirement already satisfied: protobuf>=3.1.0 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (3.17.3)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (1.15.0)\n",
"Requirement already satisfied: requests>=2.20.0 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (2.23.0)\n",
"Requirement already satisfied: numpy>=1.13 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle) (1.21.5)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle) (2.10)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle) (1.24.3)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle) (2021.10.8)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle) (3.0.4)\n",
"Installing collected packages: paddlepaddle\n",
"Successfully installed paddlepaddle-2.2.2\n"
]
}
],
"source": [
"pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple\n"
]
},
{
"cell_type": "code",
"source": [
"pip install paddleOCR"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ELQZ8V9uKPyi",
"outputId": "f902e505-4020-4d9b-c018-d516bf62113c"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting paddleOCR\n",
" Downloading paddleocr-2.4.0.4-py3-none-any.whl (339 kB)\n",
"\u001b[K |████████████████████████████████| 339 kB 8.3 MB/s \n",
"\u001b[?25hRequirement already satisfied: openpyxl in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (3.0.9)\n",
"Requirement already satisfied: cython in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (0.29.28)\n",
"Collecting python-Levenshtein\n",
" Downloading python-Levenshtein-0.12.2.tar.gz (50 kB)\n",
"\u001b[K |████████████████████████████████| 50 kB 6.2 MB/s \n",
"\u001b[?25hCollecting premailer\n",
" Downloading premailer-3.10.0-py2.py3-none-any.whl (19 kB)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (1.21.5)\n",
"Collecting opencv-contrib-python==4.4.0.46\n",
" Downloading opencv_contrib_python-4.4.0.46-cp37-cp37m-manylinux2014_x86_64.whl (55.7 MB)\n",
"\u001b[K |████████████████████████████████| 55.7 MB 65.1 MB/s \n",
"\u001b[?25hCollecting pyclipper\n",
" Downloading pyclipper-1.3.0.post2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (603 kB)\n",
"\u001b[K |████████████████████████████████| 603 kB 47.6 MB/s \n",
"\u001b[?25hRequirement already satisfied: lxml in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (4.2.6)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (4.64.0)\n",
"Collecting imgaug==0.4.0\n",
" Downloading imgaug-0.4.0-py2.py3-none-any.whl (948 kB)\n",
"\u001b[K |████████████████████████████████| 948 kB 46.1 MB/s \n",
"\u001b[?25hRequirement already satisfied: lmdb in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (0.99)\n",
"Collecting visualdl\n",
" Downloading visualdl-2.2.3-py3-none-any.whl (2.7 MB)\n",
"\u001b[K |████████████████████████████████| 2.7 MB 21.5 MB/s \n",
"\u001b[?25hRequirement already satisfied: shapely in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (1.8.1.post1)\n",
"Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from paddleOCR) (0.18.3)\n",
"Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (7.1.2)\n",
"Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (4.1.2.30)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (1.15.0)\n",
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (3.2.2)\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (1.4.1)\n",
"Requirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from imgaug==0.4.0->paddleOCR) (2.4.1)\n",
"Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleOCR) (1.3.0)\n",
"Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleOCR) (2.6.3)\n",
"Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleOCR) (2021.11.2)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug==0.4.0->paddleOCR) (2.8.2)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug==0.4.0->paddleOCR) (1.4.2)\n",
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug==0.4.0->paddleOCR) (3.0.8)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug==0.4.0->paddleOCR) (0.11.0)\n",
"Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib->imgaug==0.4.0->paddleOCR) (4.1.1)\n",
"Requirement already satisfied: et-xmlfile in /usr/local/lib/python3.7/dist-packages (from openpyxl->paddleOCR) (1.1.0)\n",
"Collecting cssutils\n",
" Downloading cssutils-2.4.0-py3-none-any.whl (404 kB)\n",
"\u001b[K |████████████████████████████████| 404 kB 51.6 MB/s \n",
"\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from premailer->paddleOCR) (2.23.0)\n",
"Requirement already satisfied: cachetools in /usr/local/lib/python3.7/dist-packages (from premailer->paddleOCR) (4.2.4)\n",
"Collecting cssselect\n",
" Downloading cssselect-1.1.0-py2.py3-none-any.whl (16 kB)\n",
"Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from cssutils->premailer->paddleOCR) (4.11.3)\n",
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->cssutils->premailer->paddleOCR) (3.8.0)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from python-Levenshtein->paddleOCR) (57.4.0)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleOCR) (2.10)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleOCR) (2021.10.8)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleOCR) (1.24.3)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleOCR) (3.0.4)\n",
"Requirement already satisfied: protobuf>=3.11.0 in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleOCR) (3.17.3)\n",
"Requirement already satisfied: flask>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleOCR) (1.1.4)\n",
"Collecting pre-commit\n",
" Downloading pre_commit-2.18.1-py2.py3-none-any.whl (197 kB)\n",
"\u001b[K |████████████████████████████████| 197 kB 52.6 MB/s \n",
"\u001b[?25hCollecting shellcheck-py\n",
" Downloading shellcheck_py-0.8.0.4-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)\n",
"\u001b[K |████████████████████████████████| 2.1 MB 31.0 MB/s \n",
"\u001b[?25hCollecting flake8>=3.7.9\n",
" Downloading flake8-4.0.1-py2.py3-none-any.whl (64 kB)\n",
"\u001b[K |████████████████████████████████| 64 kB 2.3 MB/s \n",
"\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleOCR) (1.3.5)\n",
"Collecting Flask-Babel>=1.0.0\n",
" Downloading Flask_Babel-2.0.0-py3-none-any.whl (9.3 kB)\n",
"Collecting bce-python-sdk\n",
" Downloading bce-python-sdk-0.8.64.tar.gz (127 kB)\n",
"\u001b[K |████████████████████████████████| 127 kB 47.7 MB/s \n",
"\u001b[?25hCollecting mccabe<0.7.0,>=0.6.0\n",
" Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)\n",
"Collecting pyflakes<2.5.0,>=2.4.0\n",
" Downloading pyflakes-2.4.0-py2.py3-none-any.whl (69 kB)\n",
"\u001b[K |████████████████████████████████| 69 kB 7.2 MB/s \n",
"\u001b[?25hCollecting importlib-metadata\n",
" Downloading importlib_metadata-4.2.0-py3-none-any.whl (16 kB)\n",
"Collecting pycodestyle<2.9.0,>=2.8.0\n",
" Downloading pycodestyle-2.8.0-py2.py3-none-any.whl (42 kB)\n",
"\u001b[K |████████████████████████████████| 42 kB 764 kB/s \n",
"\u001b[?25hRequirement already satisfied: Jinja2<3.0,>=2.10.1 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleOCR) (2.11.3)\n",
"Requirement already satisfied: itsdangerous<2.0,>=0.24 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleOCR) (1.1.0)\n",
"Requirement already satisfied: Werkzeug<2.0,>=0.15 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleOCR) (1.0.1)\n",
"Requirement already satisfied: click<8.0,>=5.1 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleOCR) (7.1.2)\n",
"Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from Flask-Babel>=1.0.0->visualdl->paddleOCR) (2018.9)\n",
"Requirement already satisfied: Babel>=2.3 in /usr/local/lib/python3.7/dist-packages (from Flask-Babel>=1.0.0->visualdl->paddleOCR) (2.9.1)\n",
"Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from Jinja2<3.0,>=2.10.1->flask>=1.1.1->visualdl->paddleOCR) (2.0.1)\n",
"Collecting pycryptodome>=3.8.0\n",
" Downloading pycryptodome-3.14.1-cp35-abi3-manylinux2010_x86_64.whl (2.0 MB)\n",
"\u001b[K |████████████████████████████████| 2.0 MB 38.2 MB/s \n",
"\u001b[?25hRequirement already satisfied: future>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from bce-python-sdk->visualdl->paddleOCR) (0.16.0)\n",
"Collecting identify>=1.0.0\n",
" Downloading identify-2.4.12-py2.py3-none-any.whl (98 kB)\n",
"\u001b[K |████████████████████████████████| 98 kB 7.7 MB/s \n",
"\u001b[?25hCollecting cfgv>=2.0.0\n",
" Downloading cfgv-3.3.1-py2.py3-none-any.whl (7.3 kB)\n",
"Collecting nodeenv>=0.11.1\n",
" Downloading nodeenv-1.6.0-py2.py3-none-any.whl (21 kB)\n",
"Collecting pyyaml>=5.1\n",
" Downloading PyYAML-6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596 kB)\n",
"\u001b[K |████████████████████████████████| 596 kB 67.5 MB/s \n",
"\u001b[?25hCollecting toml\n",
" Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)\n",
"Collecting virtualenv>=20.0.8\n",
" Downloading virtualenv-20.14.1-py2.py3-none-any.whl (8.8 MB)\n",
"\u001b[K |████████████████████████████████| 8.8 MB 51.7 MB/s \n",
"\u001b[?25hCollecting platformdirs<3,>=2\n",
" Downloading platformdirs-2.5.1-py3-none-any.whl (14 kB)\n",
"Collecting distlib<1,>=0.3.1\n",
" Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)\n",
"\u001b[K |████████████████████████████████| 461 kB 54.5 MB/s \n",
"\u001b[?25hRequirement already satisfied: filelock<4,>=3.2 in /usr/local/lib/python3.7/dist-packages (from virtualenv>=20.0.8->pre-commit->visualdl->paddleOCR) (3.6.0)\n",
"Building wheels for collected packages: python-Levenshtein, bce-python-sdk\n",
" Building wheel for python-Levenshtein (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for python-Levenshtein: filename=python_Levenshtein-0.12.2-cp37-cp37m-linux_x86_64.whl size=149861 sha256=2524ec0932d40733393b42be425af5aec1530348a10d7f5e6cf8c8729b8d6c51\n",
" Stored in directory: /root/.cache/pip/wheels/05/5f/ca/7c4367734892581bb5ff896f15027a932c551080b2abd3e00d\n",
" Building wheel for bce-python-sdk (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for bce-python-sdk: filename=bce_python_sdk-0.8.64-py3-none-any.whl size=202973 sha256=16f467d22159725ff9366490cbc80ec053cc9c8dfba69013623bd4347b256649\n",
" Stored in directory: /root/.cache/pip/wheels/fd/ee/a5/4ad3bdc0e60b48e892e8bd6f661a3201d7e76dccfa9e968b34\n",
"Successfully built python-Levenshtein bce-python-sdk\n",
"Installing collected packages: platformdirs, importlib-metadata, distlib, virtualenv, toml, pyyaml, pyflakes, pycryptodome, pycodestyle, nodeenv, mccabe, identify, cfgv, shellcheck-py, pre-commit, Flask-Babel, flake8, cssutils, cssselect, bce-python-sdk, visualdl, python-Levenshtein, pyclipper, premailer, opencv-contrib-python, imgaug, paddleOCR\n",
" Attempting uninstall: importlib-metadata\n",
" Found existing installation: importlib-metadata 4.11.3\n",
" Uninstalling importlib-metadata-4.11.3:\n",
" Successfully uninstalled importlib-metadata-4.11.3\n",
" Attempting uninstall: pyyaml\n",
" Found existing installation: PyYAML 3.13\n",
" Uninstalling PyYAML-3.13:\n",
" Successfully uninstalled PyYAML-3.13\n",
" Attempting uninstall: opencv-contrib-python\n",
" Found existing installation: opencv-contrib-python 4.1.2.30\n",
" Uninstalling opencv-contrib-python-4.1.2.30:\n",
" Successfully uninstalled opencv-contrib-python-4.1.2.30\n",
" Attempting uninstall: imgaug\n",
" Found existing installation: imgaug 0.2.9\n",
" Uninstalling imgaug-0.2.9:\n",
" Successfully uninstalled imgaug-0.2.9\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"markdown 3.3.6 requires importlib-metadata>=4.4; python_version < \"3.10\", but you have importlib-metadata 4.2.0 which is incompatible.\n",
"albumentations 0.1.12 requires imgaug<0.2.7,>=0.2.5, but you have imgaug 0.4.0 which is incompatible.\u001b[0m\n",
"Successfully installed Flask-Babel-2.0.0 bce-python-sdk-0.8.64 cfgv-3.3.1 cssselect-1.1.0 cssutils-2.4.0 distlib-0.3.4 flake8-4.0.1 identify-2.4.12 imgaug-0.4.0 importlib-metadata-4.2.0 mccabe-0.6.1 nodeenv-1.6.0 opencv-contrib-python-4.4.0.46 paddleOCR-2.4.0.4 platformdirs-2.5.1 pre-commit-2.18.1 premailer-3.10.0 pyclipper-1.3.0.post2 pycodestyle-2.8.0 pycryptodome-3.14.1 pyflakes-2.4.0 python-Levenshtein-0.12.2 pyyaml-6.0 shellcheck-py-0.8.0.4 toml-0.10.2 virtualenv-20.14.1 visualdl-2.2.3\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from paddleocr import PaddleOCR, draw_ocr # main OCR dependencies\n",
"from matplotlib import pyplot as plt # plot images\n",
"import cv2 #opencv\n",
"import os\n",
"\n",
"ocr = PaddleOCR(use_angle_cls=True, lang=\"arabic\") # need to run only once to download and load model into memory\n",
"\n",
"# Select the image path you want to recognize "
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Ar5037fFKdxP",
"outputId": "6c79330c-bab9-40e6-c161-d002f4ea7f81"
},
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"download https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/en_ppocr_mobile_v2.0_det_infer.tar to /root/.paddleocr/whl/det/en/en_ppocr_mobile_v2.0_det_infer/en_ppocr_mobile_v2.0_det_infer.tar\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 3.16M/3.16M [00:09<00:00, 338kiB/s] \n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"download https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/arabic_ppocr_mobile_v2.0_rec_infer.tar to /root/.paddleocr/whl/rec/arabic/arabic_ppocr_mobile_v2.0_rec_infer/arabic_ppocr_mobile_v2.0_rec_infer.tar\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 2.72M/2.72M [00:09<00:00, 302kiB/s]\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"download https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar to /root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer/ch_ppocr_mobile_v2.0_cls_infer.tar\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 1.45M/1.45M [00:09<00:00, 149kiB/s]"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"[2022/04/18 01:25:03] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_fce_box_type='poly', det_limit_side_len=960, det_limit_type='max', det_model_dir='/root/.paddleocr/whl/det/en/en_ppocr_mobile_v2.0_det_infer', det_pse_box_thresh=0.85, det_pse_box_type='quad', det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_polygon=False, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir=None, ir_optim=True, label_list=['0', '180'], lang='arabic', layout_label_map=None, layout_path_model='lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config', max_batch_size=10, max_text_length=25, min_subgraph_size=15, mode='structure', ocr_version='PP-OCRv2', output='./output', precision='fp32', process_id=0, rec=True, rec_algorithm='CRNN', rec_batch_num=6, rec_char_dict_path='/usr/local/lib/python3.7/dist-packages/paddleocr/ppocr/utils/dict/arabic_dict.txt', rec_image_shape='3, 32, 320', rec_model_dir='/root/.paddleocr/whl/rec/arabic/arabic_ppocr_mobile_v2.0_rec_infer', save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], show_log=True, structure_version='STRUCTURE', table_char_dict_path=None, table_char_type='en', table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"img_path = 'kashida-justification.png'\n",
"\n",
"result = ocr.ocr(img_path)\n",
"for line in result:\n",
"\n",
" print(line)\n",
"\n",
"# Show results \n",
"\n",
"from PIL import Image\n",
"\n",
"image = Image.open(img_path).convert('RGB')\n",
"\n",
"boxes = [line[0] for line in result]\n",
"\n",
"txts = [line[1][0] for line in result]\n",
"\n",
"scores = [line[1][1] for line in result]\n",
"txts"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UqzORhnXLBum",
"outputId": "f54acbd0-4cf4-4358-8533-366e5813b619"
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[2022/04/18 01:27:22] ppocr DEBUG: dt_boxes num : 21, elapse : 0.8194270133972168\n",
"[2022/04/18 01:27:22] ppocr DEBUG: cls num : 21, elapse : 0.7467317581176758\n",
"[2022/04/18 01:27:24] ppocr DEBUG: rec_res num : 21, elapse : 1.0784804821014404\n",
"[[[537.0, 101.0], [788.0, 93.0], [791.0, 157.0], [539.0, 165.0]], ('الشوق', 0.76377183)]\n",
"[[[20.0, 272.0], [457.0, 276.0], [456.0, 340.0], [19.0, 336.0]], ('کندواسن', 0.531458)]\n",
"[[[551.0, 371.0], [790.0, 382.0], [787.0, 436.0], [549.0, 425.0]], ('صري', 0.54460627)]\n",
"[[[668.0, 455.0], [796.0, 448.0], [799.0, 506.0], [671.0, 512.0]], ('بطا', 0.84923536)]\n",
"[[[553.0, 803.0], [808.0, 792.0], [811.0, 862.0], [556.0, 873.0]], ('الع', 0.674664)]\n",
"[[[336.0, 893.0], [567.0, 893.0], [567.0, 955.0], [336.0, 955.0]], ('الر', 0.7086611)]\n",
"[[[599.0, 895.0], [803.0, 889.0], [805.0, 940.0], [601.0, 946.0]], ('المتحدة', 0.91257584)]\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['الشوق', 'کندواسن', 'صري', 'بطا', 'الع', 'الر', 'المتحدة']"
]
},
"metadata": {},
"execution_count": 11
}
]
}
]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment