{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "arabicocrrr_NEW.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "xlVculzkSI4V",
        "outputId": "07bf0ae7-575d-48c3-a182-424a310b7182"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: ArabicOcr in /usr/local/lib/python3.7/dist-packages (1.1.6)\n",
            "Requirement already satisfied: easyocr in /usr/local/lib/python3.7/dist-packages (from ArabicOcr) (1.4.2)\n",
            "Requirement already satisfied: torchvision>=0.5 in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (0.11.1+cu111)\n",
            "Requirement already satisfied: python-bidi in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (0.4.2)\n",
            "Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (0.18.3)\n",
            "Requirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (1.10.0+cu111)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (1.4.1)\n",
            "Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (3.13)\n",
            "Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (7.1.2)\n",
            "Requirement already satisfied: opencv-python-headless<=4.5.4.60 in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (4.5.4.60)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from easyocr->ArabicOcr) (1.21.5)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch->easyocr->ArabicOcr) (4.1.1)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from python-bidi->easyocr->ArabicOcr) (1.15.0)\n",
            "Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->easyocr->ArabicOcr) (2.4.1)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->easyocr->ArabicOcr) (2021.11.2)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->easyocr->ArabicOcr) (1.3.0)\n",
            "Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->easyocr->ArabicOcr) (3.2.2)\n",
            "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->easyocr->ArabicOcr) (2.6.3)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->easyocr->ArabicOcr) (0.11.0)\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!=3.0.0,>=2.0.0->scikit-image->easyocr->ArabicOcr) (3.0.8)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->easyocr->ArabicOcr) (1.4.2)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->easyocr->ArabicOcr) (2.8.2)\n"
          ]
        }
      ],
      "source": [
        "!pip install ArabicOcr\n",
        "from ArabicOcr import arabicocr\n"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pdf=\"r.jpg\""
      ],
      "metadata": {
        "id": "YTMD8Q7tSlg3"
      },
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "out_image='font_preview-ae8a8c44055469537eec30890fd91d074584.png'\n",
        "results=arabicocr.arabic_ocr(pdf,out_image)\n",
        "print(results)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "cfkfKD1YSliv",
        "outputId": "18dcd07b-c706-44ba-ec69-1d432a0f3f11"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "Using CPU. Note: This module is much faster with a GPU.\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[INFO] OCR'ing input image...\n",
            "[INFO] 0.7118: عظيم أوجده الله لهدف وغاية\n",
            "[INFO] 0.9510: كن على ثقة أنك\n",
            "[INFO] 0.5869: ووضع فيك ما يميزك عن غيرك . قد تتعثرفي طريقك\n",
            "[INFO] 0.9686: توازنك وتحزن وتنطفئ روحك\n",
            "[INFO] 0.7192: لكنك لست بعاجز أو أقل من غيرك\n",
            "[INFO] 0.4888: لاتلتفت لكل ما يحبطك . أنت\n",
            "[INFO] 0.6203: من يستطيع أن يفجر طاقاتك أنت من تصنع سعادتك\n",
            "[INFO] 0.7844: نفسك فقط\n",
            "[INFO] 0.5433: تأمل\n",
            "[INFO] 0.7832: وتغير حياتك\n",
            "[INFO] 0.9997: شخص\n",
            "[INFO] 0.8442: و قد تفقد\n",
            "[INFO] 0.9201: وحدا\n",
            "[INFO] 0.7544:  للأفضل\n",
            "[[[[33, 81], [257, 81], [257, 119], [33, 119]], 'عظيم أوجده الله لهدف وغاية', 0.7117604163439951], [[[315, 79], [449, 79], [449, 119], [315, 119]], 'كن على ثقة أنك', 0.9509828033641047], [[[43, 119], [445, 119], [445, 159], [43, 159]], 'ووضع فيك ما يميزك عن غيرك . قد تتعثرفي طريقك', 0.5868975025637876], [[[83, 155], [328, 155], [328, 188], [83, 188]], 'توازنك وتحزن وتنطفئ روحك', 0.9685795521460127], [[[103, 183], [385, 183], [385, 223], [103, 223]], 'لكنك لست بعاجز أو أقل من غيرك', 0.7192249539704715], [[[149, 217], [391, 217], [391, 255], [149, 255]], 'لاتلتفت لكل ما يحبطك . أنت', 0.48881162710266574], [[[35, 248], [452, 248], [452, 296], [35, 296]], 'من يستطيع أن يفجر طاقاتك أنت من تصنع سعادتك', 0.6202687483334991], [[[88, 290], [180, 290], [180, 316], [88, 316]], 'نفسك فقط', 0.7844466329095169], [[[177, 285], [225, 285], [225, 325], [177, 325]], 'تأمل', 0.5432728232028666], [[[296, 292], [400, 292], [400, 322], [296, 322]], 'وتغير حياتك', 0.7831651030631188], [[[251.3358994113243, 91.50384911698647], [317.6557304263147, 84.60461621668212], [319.6641005886757, 111.49615088301353], [253.34426957368532, 118.39538378331788]], 'شخص', 0.9996770776678967], [[[324.1299778141514, 149.12892678669957], [405.92856118055187, 158.34920862654403], [401.8700221858486, 187.87107321330043], [319.07143881944813, 177.65079137345597]], 'و قد تفقد', 0.8442280965655838], [[[97.10517502059216, 218.1365600658949], [154.90122361178794, 229.23652010216108], [149.89482497940784, 255.8634399341051], [92.09877638821206, 245.76347989783892]], 'وحدا', 0.9200626611709595], [[[228.34478822279527, 289.3585340901496], [299.36118659289696, 281.8314925207116], [301.6552117772047, 318.6414659098504], [230.63881340710302, 326.1685074792884]], ' للأفضل', 0.7544428760708207]]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "words=[]\n",
        "for i in range(len(results)):\t\n",
        "\t\tword=results[i][1]\n",
        "\t\twords.append(word)\n",
        "with open ('file.txt','w',encoding='utf-8')as myfile:\n",
        "\t\tmyfile.write(str(words))\n",
        "  \n",
        "print(words)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5nkhWS_pSlki",
        "outputId": "3d45e676-e75a-45d4-ecf4-b73194875dcf"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "['عظيم أوجده الله لهدف وغاية', 'كن على ثقة أنك', 'ووضع فيك ما يميزك عن غيرك . قد تتعثرفي طريقك', 'توازنك وتحزن وتنطفئ روحك', 'لكنك لست بعاجز أو أقل من غيرك', 'لاتلتفت لكل ما يحبطك . أنت', 'من يستطيع أن يفجر طاقاتك أنت من تصنع سعادتك', 'نفسك فقط', 'تأمل', 'وتغير حياتك', 'شخص', 'و قد تفقد', 'وحدا', ' للأفضل']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab.patches import cv2_imshow\n",
        "import cv2\n",
        "img = cv2.imread('font_preview-ae8a8c44055469537eec30890fd91d074584.png', cv2.IMREAD_UNCHANGED)\n",
        "cv2_imshow(img)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 396
        },
        "id": "iG7szRIt2pIE",
        "outputId": "4c3a4d73-ec14-46f2-dad9-a1006a2cabdc"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<PIL.Image.Image image mode=RGB size=474x379 at 0x7FACD1761ED0>"
            ],
            "image/png": "[encoded data, 142924 characters]\n"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import drive\n",
        "\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "id": "ZJ9cyxq9Slmi",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "5831282f-89e8-4e02-f0fe-99930ef893ac"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Mounted at /content/drive\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "RIuAt_J7SloQ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        ""
      ],
      "metadata": {
        "id": "iKvL-U5YSlrr"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}