{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# \ud83e\udde0 mnemo_ocr \u2014 Google Colab Notebook (Python 3.10.19)\n", "\u042d\u0442\u043e\u0442 \u043d\u043e\u0443\u0442\u0431\u0443\u043a \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442 Google Colab \u043d\u0430 **Python 3.10.19** \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435."]}, {"cell_type": "markdown", "metadata": {}, "source": ["## \ud83d\udd27 \u0428\u0430\u0433 1 \u2014 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Python 3.10.19 (\u0432\u043c\u0435\u0441\u0442\u043e 3.12)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!sudo apt-get update -y\n", "!sudo apt-get install python3.10 python3.10-distutils python3.10-dev -y\n", "\n", "!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1\n", "!sudo update-alternatives --set python3 /usr/bin/python3.10\n", "\n", "!curl -sS https://bootstrap.pypa.io/get-pip.py | python3\n", "\n", "import sys\n", "print('Python version now:', sys.version)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## \ud83d\udce6 \u0428\u0430\u0433 2 \u2014 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 PaddleOCR \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install paddlepaddle==2.6.1\n", "!pip install paddleocr\n", "!pip install opencv-python-headless pandas numpy python-docx pytesseract pyyaml tqdm"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## \ud83d\udcc1 \u0428\u0430\u0433 3 \u2014 \u041a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 mnemo_ocr"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!git clone https://github.com/bianconeri91/mnemo_ocr.git\n", "%cd mnemo_ocr"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## \ud83d\udd0c \u0428\u0430\u0433 4 \u2014 \u0418\u043c\u043f\u043e\u0440\u0442\u044b \u0438 \u0437\u0430\u043f\u0443\u0441\u043a OCR"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from google.colab import files\n", "import cv2\n", "import numpy as np\n", "\n", "from src.pipeline import extract_text\n", "from src.ocr_utils import ocr_sensors\n", "\n", "print('\u0418\u043c\u043f\u043e\u0440\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \ud83d\ude80')"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## \ud83d\udce4 \u0428\u0430\u0433 5 \u2014 \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["uploaded = files.upload()\n", "\n", "for fname, data in uploaded.items():\n", " print(f\"\\n\ud83d\udcc4 \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u0430\u0439\u043b\u0430: {fname}\")\n", "\n", " arr = np.frombuffer(data, np.uint8)\n", " img = cv2.imdecode(arr, cv2.IMREAD_COLOR)\n", "\n", " if img is None:\n", " print('\u274c \u0424\u0430\u0439\u043b \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d \u043a\u0430\u043a \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.')\n", " continue\n", "\n", " color_ranges = {}\n", " title, sensors = extract_text(img, color_ranges)\n", "\n", " print('\\n\ud83c\udff7 TITLE:', title)\n", " print('\ud83e\udde9 SENSORS:')\n", " for s in sensors:\n", " print(s)"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"name": "python"}}, "nbformat": 4, "nbformat_minor": 2}