rcai commited on
Commit
e5ca1da
·
1 Parent(s): d7d9e17

Upload PDF_TO_EXCEL_By_Neuralearn_.ipynb

Browse files
Files changed (1) hide show
  1. PDF_TO_EXCEL_By_Neuralearn_.ipynb +1618 -0
PDF_TO_EXCEL_By_Neuralearn_.ipynb ADDED
@@ -0,0 +1,1618 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "source": [
6
+ "from PIL import Image\n",
7
+ "import cv2\n",
8
+ "import numpy as np\n",
9
+ "import pandas as pd\n",
10
+ "import tensorflow as tf"
11
+ ],
12
+ "metadata": {
13
+ "id": "mhEjVUbiUytV"
14
+ },
15
+ "execution_count": null,
16
+ "outputs": []
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "source": [
21
+ "#!pip install paddlepaddle-gpu==2.3.2 cudatoolkit==10.2"
22
+ ],
23
+ "metadata": {
24
+ "id": "JejuCeNXHckg"
25
+ },
26
+ "execution_count": null,
27
+ "outputs": []
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "source": [
32
+ "!pip install paddlepaddle-gpu==2.3.0.post110 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html"
33
+ ],
34
+ "metadata": {
35
+ "colab": {
36
+ "base_uri": "https://localhost:8080/"
37
+ },
38
+ "id": "xWhdOt9Jay6z",
39
+ "outputId": "cda3179f-f1d6-41e3-bdd2-6d8fdeab5867"
40
+ },
41
+ "execution_count": null,
42
+ "outputs": [
43
+ {
44
+ "output_type": "stream",
45
+ "name": "stdout",
46
+ "text": [
47
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
48
+ "Looking in links: https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html\n",
49
+ "Collecting paddlepaddle-gpu==2.3.0.post110\n",
50
+ " Downloading https://paddle-wheel.bj.bcebos.com/2.3.0/linux/linux-gpu-cuda11.0-cudnn8-mkl-gcc8.2-avx/paddlepaddle_gpu-2.3.0.post110-cp37-cp37m-linux_x86_64.whl (532.9 MB)\n",
51
+ "\u001b[K |████████████████████████████████| 532.9 MB 27 kB/s \n",
52
+ "\u001b[?25hRequirement already satisfied: decorator in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (4.4.2)\n",
53
+ "Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (7.1.2)\n",
54
+ "Requirement already satisfied: requests>=2.20.0 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (2.23.0)\n",
55
+ "Collecting paddle-bfloat==0.1.2\n",
56
+ " Downloading paddle_bfloat-0.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (373 kB)\n",
57
+ "\u001b[K |████████████████████████████████| 373 kB 5.7 MB/s \n",
58
+ "\u001b[?25hRequirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (1.15.0)\n",
59
+ "Requirement already satisfied: protobuf>=3.1.0 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (3.19.6)\n",
60
+ "Requirement already satisfied: astor in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (0.8.1)\n",
61
+ "Requirement already satisfied: numpy>=1.13 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (1.21.6)\n",
62
+ "Requirement already satisfied: opt-einsum==3.3.0 in /usr/local/lib/python3.7/dist-packages (from paddlepaddle-gpu==2.3.0.post110) (3.3.0)\n",
63
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle-gpu==2.3.0.post110) (2022.9.24)\n",
64
+ "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle-gpu==2.3.0.post110) (2.10)\n",
65
+ "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-gpu==2.3.0.post110) (1.24.3)\n",
66
+ "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20.0->paddlepaddle-gpu==2.3.0.post110) (3.0.4)\n",
67
+ "Installing collected packages: paddle-bfloat, paddlepaddle-gpu\n",
68
+ "Successfully installed paddle-bfloat-0.1.2 paddlepaddle-gpu-2.3.0.post110\n"
69
+ ]
70
+ }
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "markdown",
75
+ "metadata": {
76
+ "id": "dvKiMyj2feUe"
77
+ },
78
+ "source": [
79
+ "# pdf2image"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "markdown",
84
+ "source": [
85
+ "## Installation"
86
+ ],
87
+ "metadata": {
88
+ "id": "aIz56VvlWkf-"
89
+ }
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "source": [
94
+ "!pip install pdf2image\n",
95
+ "!apt-get update\n",
96
+ "!apt-get install poppler-utils"
97
+ ],
98
+ "metadata": {
99
+ "colab": {
100
+ "base_uri": "https://localhost:8080/"
101
+ },
102
+ "id": "biSgyAkWnUD3",
103
+ "outputId": "06487f1d-40ee-4de6-f072-6372561d16cd"
104
+ },
105
+ "execution_count": null,
106
+ "outputs": [
107
+ {
108
+ "output_type": "stream",
109
+ "name": "stdout",
110
+ "text": [
111
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
112
+ "Collecting pdf2image\n",
113
+ " Downloading pdf2image-1.16.0-py3-none-any.whl (10 kB)\n",
114
+ "Requirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (from pdf2image) (7.1.2)\n",
115
+ "Installing collected packages: pdf2image\n",
116
+ "Successfully installed pdf2image-1.16.0\n",
117
+ "Get:1 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/ InRelease [3,626 B]\n",
118
+ "Ign:2 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 InRelease\n",
119
+ "Hit:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease\n",
120
+ "Hit:4 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 Release\n",
121
+ "Hit:5 http://archive.ubuntu.com/ubuntu bionic InRelease\n",
122
+ "Get:6 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic InRelease [15.9 kB]\n",
123
+ "Get:7 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]\n",
124
+ "Get:8 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]\n",
125
+ "Hit:10 http://ppa.launchpad.net/cran/libgit2/ubuntu bionic InRelease\n",
126
+ "Get:11 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [83.3 kB]\n",
127
+ "Hit:12 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease\n",
128
+ "Hit:13 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic InRelease\n",
129
+ "Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [3,494 kB]\n",
130
+ "Get:15 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main Sources [2,225 kB]\n",
131
+ "Get:16 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [3,068 kB]\n",
132
+ "Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [29.8 kB]\n",
133
+ "Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [1,303 kB]\n",
134
+ "Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2,336 kB]\n",
135
+ "Get:20 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,561 kB]\n",
136
+ "Get:21 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main amd64 Packages [1,138 kB]\n",
137
+ "Fetched 15.4 MB in 4s (3,448 kB/s)\n",
138
+ "Reading package lists... Done\n",
139
+ "Reading package lists... Done\n",
140
+ "Building dependency tree \n",
141
+ "Reading state information... Done\n",
142
+ "The following package was automatically installed and is no longer required:\n",
143
+ " libnvidia-common-460\n",
144
+ "Use 'apt autoremove' to remove it.\n",
145
+ "The following NEW packages will be installed:\n",
146
+ " poppler-utils\n",
147
+ "0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.\n",
148
+ "Need to get 154 kB of archives.\n",
149
+ "After this operation, 613 kB of additional disk space will be used.\n",
150
+ "Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 poppler-utils amd64 0.62.0-2ubuntu2.14 [154 kB]\n",
151
+ "Fetched 154 kB in 1s (198 kB/s)\n",
152
+ "Selecting previously unselected package poppler-utils.\n",
153
+ "(Reading database ... 123991 files and directories currently installed.)\n",
154
+ "Preparing to unpack .../poppler-utils_0.62.0-2ubuntu2.14_amd64.deb ...\n",
155
+ "Unpacking poppler-utils (0.62.0-2ubuntu2.14) ...\n",
156
+ "Setting up poppler-utils (0.62.0-2ubuntu2.14) ...\n",
157
+ "Processing triggers for man-db (2.8.3-2ubuntu0.1) ...\n"
158
+ ]
159
+ }
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "markdown",
164
+ "source": [
165
+ "## Conversion"
166
+ ],
167
+ "metadata": {
168
+ "id": "pLaguCz1WmF9"
169
+ }
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "source": [
174
+ "from pdf2image import convert_from_path"
175
+ ],
176
+ "metadata": {
177
+ "id": "HI1dzCGmkeWI"
178
+ },
179
+ "execution_count": null,
180
+ "outputs": []
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "source": [
185
+ "images = convert_from_path('/content/bahdanau attention.pdf')"
186
+ ],
187
+ "metadata": {
188
+ "id": "xyhjFgqjkgG7"
189
+ },
190
+ "execution_count": null,
191
+ "outputs": []
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "source": [
196
+ "!mkdir pages"
197
+ ],
198
+ "metadata": {
199
+ "id": "M5hBWxpskgJW"
200
+ },
201
+ "execution_count": null,
202
+ "outputs": []
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "source": [
207
+ "for i in range(len(images)):\n",
208
+ " images[i].save('pages/page'+str(i)+'.jpg', 'JPEG')"
209
+ ],
210
+ "metadata": {
211
+ "id": "7mlH9ltkkgMB"
212
+ },
213
+ "execution_count": null,
214
+ "outputs": []
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "source": [
219
+ "# Layout"
220
+ ],
221
+ "metadata": {
222
+ "id": "Urwb7Q_OZC8t"
223
+ }
224
+ },
225
+ {
226
+ "cell_type": "markdown",
227
+ "source": [
228
+ "## Installation"
229
+ ],
230
+ "metadata": {
231
+ "id": "vTkwQbF4FZPN"
232
+ }
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "source": [
237
+ "#!python3 -m pip install paddlepaddle-gpu\n",
238
+ "!pip install \"paddleocr>=2.0.1\"\n",
239
+ "!pip install protobuf==3.20.0\n",
240
+ "!git clone https://github.com/PaddlePaddle/PaddleOCR.git"
241
+ ],
242
+ "metadata": {
243
+ "colab": {
244
+ "base_uri": "https://localhost:8080/",
245
+ "height": 1000
246
+ },
247
+ "id": "R0lRpQLkIpbZ",
248
+ "outputId": "24283e8e-5de0-4b41-bb43-8d0638f927c1"
249
+ },
250
+ "execution_count": null,
251
+ "outputs": [
252
+ {
253
+ "output_type": "stream",
254
+ "name": "stdout",
255
+ "text": [
256
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
257
+ "Collecting paddleocr>=2.0.1\n",
258
+ " Downloading paddleocr-2.6.1.0-py3-none-any.whl (409 kB)\n",
259
+ "\u001b[K |████████████████████████████████| 409 kB 6.1 MB/s \n",
260
+ "\u001b[?25hRequirement already satisfied: lmdb in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (0.99)\n",
261
+ "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (4.64.1)\n",
262
+ "Collecting python-docx\n",
263
+ " Downloading python-docx-0.8.11.tar.gz (5.6 MB)\n",
264
+ "\u001b[K |████████████████████████████████| 5.6 MB 56.9 MB/s \n",
265
+ "\u001b[?25hCollecting premailer\n",
266
+ " Downloading premailer-3.10.0-py2.py3-none-any.whl (19 kB)\n",
267
+ "Collecting PyMuPDF==1.19.0\n",
268
+ " Downloading PyMuPDF-1.19.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (8.7 MB)\n",
269
+ "\u001b[K |████████████████████████████████| 8.7 MB 19.5 MB/s \n",
270
+ "\u001b[?25hCollecting lanms-neo==1.0.2\n",
271
+ " Downloading lanms_neo-1.0.2.tar.gz (39 kB)\n",
272
+ " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
273
+ " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
274
+ " Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n",
275
+ "Requirement already satisfied: lxml in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (4.9.1)\n",
276
+ "Collecting pyclipper\n",
277
+ " Downloading pyclipper-1.3.0.post4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (604 kB)\n",
278
+ "\u001b[K |████████████████████████████████| 604 kB 62.9 MB/s \n",
279
+ "\u001b[?25hRequirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (0.18.3)\n",
280
+ "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (1.21.6)\n",
281
+ "Requirement already satisfied: cython in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (0.29.32)\n",
282
+ "Collecting fire>=0.3.0\n",
283
+ " Downloading fire-0.4.0.tar.gz (87 kB)\n",
284
+ "\u001b[K |████████████████████████████████| 87 kB 7.9 MB/s \n",
285
+ "\u001b[?25hRequirement already satisfied: opencv-contrib-python in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (4.6.0.66)\n",
286
+ "Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (4.6.0.66)\n",
287
+ "Requirement already satisfied: openpyxl in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (3.0.10)\n",
288
+ "Collecting rapidfuzz\n",
289
+ " Downloading rapidfuzz-2.13.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB)\n",
290
+ "\u001b[K |████████████████████████████████| 2.2 MB 52.5 MB/s \n",
291
+ "\u001b[?25hCollecting pdf2docx\n",
292
+ " Downloading pdf2docx-0.5.6-py3-none-any.whl (148 kB)\n",
293
+ "\u001b[K |████████████████████████████████| 148 kB 68.2 MB/s \n",
294
+ "\u001b[?25hRequirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (4.6.3)\n",
295
+ "Collecting attrdict\n",
296
+ " Downloading attrdict-2.0.1-py2.py3-none-any.whl (9.9 kB)\n",
297
+ "Collecting visualdl\n",
298
+ " Downloading visualdl-2.4.1-py3-none-any.whl (4.9 MB)\n",
299
+ "\u001b[K |████████████████████████████████| 4.9 MB 46.1 MB/s \n",
300
+ "\u001b[?25hCollecting fonttools>=4.24.0\n",
301
+ " Downloading fonttools-4.38.0-py3-none-any.whl (965 kB)\n",
302
+ "\u001b[K |████████████████████████████████| 965 kB 57.7 MB/s \n",
303
+ "\u001b[?25hCollecting Polygon3\n",
304
+ " Downloading Polygon3-3.0.9.1.tar.gz (39 kB)\n",
305
+ "Requirement already satisfied: shapely in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (1.8.5.post1)\n",
306
+ "Requirement already satisfied: imgaug in /usr/local/lib/python3.7/dist-packages (from paddleocr>=2.0.1) (0.4.0)\n",
307
+ "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from fire>=0.3.0->paddleocr>=2.0.1) (1.15.0)\n",
308
+ "Requirement already satisfied: termcolor in /usr/local/lib/python3.7/dist-packages (from fire>=0.3.0->paddleocr>=2.0.1) (2.1.0)\n",
309
+ "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from imgaug->paddleocr>=2.0.1) (1.7.3)\n",
310
+ "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from imgaug->paddleocr>=2.0.1) (3.2.2)\n",
311
+ "Requirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from imgaug->paddleocr>=2.0.1) (2.9.0)\n",
312
+ "Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from imgaug->paddleocr>=2.0.1) (7.1.2)\n",
313
+ "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleocr>=2.0.1) (2021.11.2)\n",
314
+ "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleocr>=2.0.1) (1.3.0)\n",
315
+ "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->paddleocr>=2.0.1) (2.6.3)\n",
316
+ "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug->paddleocr>=2.0.1) (2.8.2)\n",
317
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug->paddleocr>=2.0.1) (0.11.0)\n",
318
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->imgaug->paddleocr>=2.0.1) (1.4.4)\n",
319
+ "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->paddleocr>=2.0.1) (3.0.9)\n",
320
+ "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib->imgaug->paddleocr>=2.0.1) (4.1.1)\n",
321
+ "Requirement already satisfied: et-xmlfile in /usr/local/lib/python3.7/dist-packages (from openpyxl->paddleocr>=2.0.1) (1.1.0)\n",
322
+ "Collecting cssutils\n",
323
+ " Downloading cssutils-2.6.0-py3-none-any.whl (399 kB)\n",
324
+ "\u001b[K |████████████████████████████████| 399 kB 56.6 MB/s \n",
325
+ "\u001b[?25hRequirement already satisfied: cachetools in /usr/local/lib/python3.7/dist-packages (from premailer->paddleocr>=2.0.1) (5.2.0)\n",
326
+ "Collecting cssselect\n",
327
+ " Downloading cssselect-1.2.0-py2.py3-none-any.whl (18 kB)\n",
328
+ "Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from premailer->paddleocr>=2.0.1) (2.23.0)\n",
329
+ "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from cssutils->premailer->paddleocr>=2.0.1) (4.13.0)\n",
330
+ "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->cssutils->premailer->paddleocr>=2.0.1) (3.10.0)\n",
331
+ "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>=2.0.1) (1.24.3)\n",
332
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleocr>=2.0.1) (2022.9.24)\n",
333
+ "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleocr>=2.0.1) (2.10)\n",
334
+ "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->premailer->paddleocr>=2.0.1) (3.0.4)\n",
335
+ "Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleocr>=2.0.1) (21.3)\n",
336
+ "Collecting Flask-Babel>=1.0.0\n",
337
+ " Downloading Flask_Babel-2.0.0-py3-none-any.whl (9.3 kB)\n",
338
+ "Collecting multiprocess\n",
339
+ " Downloading multiprocess-0.70.14-py37-none-any.whl (115 kB)\n",
340
+ "\u001b[K |████████████████████████████████| 115 kB 70.8 MB/s \n",
341
+ "\u001b[?25hRequirement already satisfied: protobuf>=3.11.0 in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleocr>=2.0.1) (3.19.6)\n",
342
+ "Collecting bce-python-sdk\n",
343
+ " Downloading bce_python_sdk-0.8.74-py3-none-any.whl (204 kB)\n",
344
+ "\u001b[K |████████████████████████████████| 204 kB 74.4 MB/s \n",
345
+ "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleocr>=2.0.1) (1.3.5)\n",
346
+ "Requirement already satisfied: flask>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from visualdl->paddleocr>=2.0.1) (1.1.4)\n",
347
+ "Requirement already satisfied: Jinja2<3.0,>=2.10.1 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleocr>=2.0.1) (2.11.3)\n",
348
+ "Requirement already satisfied: itsdangerous<2.0,>=0.24 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleocr>=2.0.1) (1.1.0)\n",
349
+ "Requirement already satisfied: click<8.0,>=5.1 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleocr>=2.0.1) (7.1.2)\n",
350
+ "Requirement already satisfied: Werkzeug<2.0,>=0.15 in /usr/local/lib/python3.7/dist-packages (from flask>=1.1.1->visualdl->paddleocr>=2.0.1) (1.0.1)\n",
351
+ "Requirement already satisfied: Babel>=2.3 in /usr/local/lib/python3.7/dist-packages (from Flask-Babel>=1.0.0->visualdl->paddleocr>=2.0.1) (2.11.0)\n",
352
+ "Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from Flask-Babel>=1.0.0->visualdl->paddleocr>=2.0.1) (2022.6)\n",
353
+ "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) (2.0.1)\n",
354
+ "Requirement already satisfied: future>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from bce-python-sdk->visualdl->paddleocr>=2.0.1) (0.16.0)\n",
355
+ "Collecting pycryptodome>=3.8.0\n",
356
+ " Downloading pycryptodome-3.15.0-cp35-abi3-manylinux2010_x86_64.whl (2.3 MB)\n",
357
+ "\u001b[K |████████████████████████████████| 2.3 MB 52.8 MB/s \n",
358
+ "\u001b[?25hRequirement already satisfied: dill>=0.3.6 in /usr/local/lib/python3.7/dist-packages (from multiprocess->visualdl->paddleocr>=2.0.1) (0.3.6)\n",
359
+ "Building wheels for collected packages: lanms-neo, fire, python-docx, Polygon3\n",
360
+ " Building wheel for lanms-neo (PEP 517) ... \u001b[?25l\u001b[?25hdone\n",
361
+ " Created wheel for lanms-neo: filename=lanms_neo-1.0.2-cp37-cp37m-linux_x86_64.whl size=110709 sha256=db3be5b526b39f2cdb111fae9919810e45d809fbf6483beb4aef28c3577351e1\n",
362
+ " Stored in directory: /root/.cache/pip/wheels/09/7b/5e/1e4d24a8f94c1116afa284ce2968ef2f72b986a5457164b340\n",
363
+ " Building wheel for fire (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
364
+ " Created wheel for fire: filename=fire-0.4.0-py2.py3-none-any.whl size=115940 sha256=6a35e11384be4e128e9cc6c57ba0a7d5a6dd93ab81674fe4d179f29373f6016e\n",
365
+ " Stored in directory: /root/.cache/pip/wheels/8a/67/fb/2e8a12fa16661b9d5af1f654bd199366799740a85c64981226\n",
366
+ " Building wheel for python-docx (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
367
+ " Created wheel for python-docx: filename=python_docx-0.8.11-py3-none-any.whl size=184508 sha256=39fd6da47445e3f73ed3453c6f584faecf60afde06c3276603ebda99353988d8\n",
368
+ " Stored in directory: /root/.cache/pip/wheels/f6/6f/b9/d798122a8b55b74ad30b5f52b01482169b445fbb84a11797a6\n",
369
+ " Building wheel for Polygon3 (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
370
+ " Created wheel for Polygon3: filename=Polygon3-3.0.9.1-cp37-cp37m-linux_x86_64.whl size=102659 sha256=41f609300d5ade5b91d4f4b3bd34ac510e7b2ccfbf1ebd338f17d917ab63cd02\n",
371
+ " Stored in directory: /root/.cache/pip/wheels/0d/f3/a1/d9909fbad83c438786f3fbde79b0636c9e843107bad74baba7\n",
372
+ "Successfully built lanms-neo fire python-docx Polygon3\n",
373
+ "Installing collected packages: pycryptodome, python-docx, PyMuPDF, multiprocess, fonttools, Flask-Babel, fire, cssutils, cssselect, bce-python-sdk, visualdl, rapidfuzz, pyclipper, premailer, Polygon3, pdf2docx, lanms-neo, attrdict, paddleocr\n",
374
+ "Successfully installed Flask-Babel-2.0.0 Polygon3-3.0.9.1 PyMuPDF-1.19.0 attrdict-2.0.1 bce-python-sdk-0.8.74 cssselect-1.2.0 cssutils-2.6.0 fire-0.4.0 fonttools-4.38.0 lanms-neo-1.0.2 multiprocess-0.70.14 paddleocr-2.6.1.0 pdf2docx-0.5.6 premailer-3.10.0 pyclipper-1.3.0.post4 pycryptodome-3.15.0 python-docx-0.8.11 rapidfuzz-2.13.2 visualdl-2.4.1\n",
375
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
376
+ "Collecting protobuf==3.20.0\n",
377
+ " Downloading protobuf-3.20.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB)\n",
378
+ "\u001b[K |████████████████████████████████| 1.0 MB 8.3 MB/s \n",
379
+ "\u001b[?25hInstalling collected packages: protobuf\n",
380
+ " Attempting uninstall: protobuf\n",
381
+ " Found existing installation: protobuf 3.19.6\n",
382
+ " Uninstalling protobuf-3.19.6:\n",
383
+ " Successfully uninstalled protobuf-3.19.6\n",
384
+ "\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",
385
+ "tensorflow 2.9.2 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.0 which is incompatible.\n",
386
+ "tensorboard 2.9.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.0 which is incompatible.\n",
387
+ "google-cloud-translate 3.8.4 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\n",
388
+ "google-cloud-language 2.6.1 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\n",
389
+ "google-cloud-firestore 2.7.2 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\n",
390
+ "google-cloud-datastore 2.9.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\n",
391
+ "google-cloud-bigquery 3.3.6 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\n",
392
+ "google-cloud-bigquery-storage 2.16.2 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.0 which is incompatible.\u001b[0m\n",
393
+ "Successfully installed protobuf-3.20.0\n"
394
+ ]
395
+ },
396
+ {
397
+ "output_type": "display_data",
398
+ "data": {
399
+ "application/vnd.colab-display-data+json": {
400
+ "pip_warning": {
401
+ "packages": [
402
+ "google"
403
+ ]
404
+ }
405
+ }
406
+ },
407
+ "metadata": {}
408
+ },
409
+ {
410
+ "output_type": "stream",
411
+ "name": "stdout",
412
+ "text": [
413
+ "Cloning into 'PaddleOCR'...\n",
414
+ "remote: Enumerating objects: 44967, done.\u001b[K\n",
415
+ "remote: Counting objects: 100% (98/98), done.\u001b[K\n",
416
+ "remote: Compressing objects: 100% (75/75), done.\u001b[K\n",
417
+ "remote: Total 44967 (delta 43), reused 45 (delta 23), pack-reused 44869\u001b[K\n",
418
+ "Receiving objects: 100% (44967/44967), 338.24 MiB | 33.36 MiB/s, done.\n",
419
+ "Resolving deltas: 100% (31741/31741), done.\n"
420
+ ]
421
+ }
422
+ ]
423
+ },
424
+ {
425
+ "cell_type": "code",
426
+ "source": [
427
+ "a=5"
428
+ ],
429
+ "metadata": {
430
+ "id": "IXEKTAa2_10K"
431
+ },
432
+ "execution_count": null,
433
+ "outputs": []
434
+ },
435
+ {
436
+ "cell_type": "code",
437
+ "source": [
438
+ "!wget https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-any.whl\n",
439
+ "!pip install -U layoutparser-0.0.0-py3-none-any.whl"
440
+ ],
441
+ "metadata": {
442
+ "colab": {
443
+ "base_uri": "https://localhost:8080/"
444
+ },
445
+ "id": "8gWFgGl5CXu6",
446
+ "outputId": "5d435097-2f57-4806-f454-eeeeb1a02efc"
447
+ },
448
+ "execution_count": null,
449
+ "outputs": [
450
+ {
451
+ "output_type": "stream",
452
+ "name": "stdout",
453
+ "text": [
454
+ "--2022-11-18 12:58:08-- https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-any.whl\n",
455
+ "Resolving paddleocr.bj.bcebos.com (paddleocr.bj.bcebos.com)... 103.235.46.61, 2409:8c04:1001:1002:0:ff:b001:368a\n",
456
+ "Connecting to paddleocr.bj.bcebos.com (paddleocr.bj.bcebos.com)|103.235.46.61|:443... connected.\n",
457
+ "HTTP request sent, awaiting response... 200 OK\n",
458
+ "Length: 19145360 (18M) [application/octet-stream]\n",
459
+ "Saving to: ‘layoutparser-0.0.0-py3-none-any.whl’\n",
460
+ "\n",
461
+ "layoutparser-0.0.0- 100%[===================>] 18.26M 3.69MB/s in 12s \n",
462
+ "\n",
463
+ "2022-11-18 12:58:23 (1.48 MB/s) - ‘layoutparser-0.0.0-py3-none-any.whl’ saved [19145360/19145360]\n",
464
+ "\n",
465
+ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
466
+ "Processing ./layoutparser-0.0.0-py3-none-any.whl\n",
467
+ "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (1.21.6)\n",
468
+ "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (1.3.5)\n",
469
+ "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (4.64.1)\n",
470
+ "Collecting iopath\n",
471
+ " Downloading iopath-0.1.10.tar.gz (42 kB)\n",
472
+ "\u001b[K |████████████████████████████████| 42 kB 38 kB/s \n",
473
+ "\u001b[?25hRequirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (7.1.2)\n",
474
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (6.0)\n",
475
+ "Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from layoutparser==0.0.0) (4.6.0.66)\n",
476
+ "Requirement already satisfied: typing_extensions in /usr/local/lib/python3.7/dist-packages (from iopath->layoutparser==0.0.0) (4.1.1)\n",
477
+ "Collecting portalocker\n",
478
+ " Downloading portalocker-2.6.0-py2.py3-none-any.whl (15 kB)\n",
479
+ "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->layoutparser==0.0.0) (2022.6)\n",
480
+ "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->layoutparser==0.0.0) (2.8.2)\n",
481
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->layoutparser==0.0.0) (1.15.0)\n",
482
+ "Building wheels for collected packages: iopath\n",
483
+ " Building wheel for iopath (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
484
+ " Created wheel for iopath: filename=iopath-0.1.10-py3-none-any.whl size=31548 sha256=8f3da2a0ce4dd2c6b432ef4d5851d960b4c889e015e7066a5a77b45bfa05cb60\n",
485
+ " Stored in directory: /root/.cache/pip/wheels/aa/cc/ed/ca4e88beef656b01c84b9185196513ef2faf74a5a379b043a7\n",
486
+ "Successfully built iopath\n",
487
+ "Installing collected packages: portalocker, iopath, layoutparser\n",
488
+ "Successfully installed iopath-0.1.10 layoutparser-0.0.0 portalocker-2.6.0\n"
489
+ ]
490
+ }
491
+ ]
492
+ },
493
+ {
494
+ "cell_type": "markdown",
495
+ "source": [
496
+ "## Table Extraction"
497
+ ],
498
+ "metadata": {
499
+ "id": "w5MA08E0F8aU"
500
+ }
501
+ },
502
+ {
503
+ "cell_type": "code",
504
+ "source": [
505
+ "import cv2\n",
506
+ "import layoutparser as lp\n",
507
+ "image = cv2.imread(\"/content/pages/page13.jpg\")\n",
508
+ "\n",
509
+ "image = image[..., ::-1]\n",
510
+ "\n",
511
+ "# load model\n",
512
+ "model = lp.PaddleDetectionLayoutModel(config_path=\"lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config\",\n",
513
+ " threshold=0.5,\n",
514
+ " label_map={0: \"Text\", 1: \"Title\", 2: \"List\", 3:\"Table\", 4:\"Figure\"},\n",
515
+ " enforce_cpu=False,\n",
516
+ " enable_mkldnn=True)#math kernel library\n",
517
+ "# detect\n",
518
+ "layout = model.detect(image)"
519
+ ],
520
+ "metadata": {
521
+ "id": "bw9SFYnMCX0E",
522
+ "colab": {
523
+ "base_uri": "https://localhost:8080/"
524
+ },
525
+ "outputId": "89218fbd-3b01-453e-a191-0d15c8883d03"
526
+ },
527
+ "execution_count": null,
528
+ "outputs": [
529
+ {
530
+ "output_type": "stream",
531
+ "name": "stdout",
532
+ "text": [
533
+ "download https://paddle-model-ecology.bj.bcebos.com/model/layout-parser/ppyolov2_r50vd_dcn_365e_publaynet.tar to /root/.paddledet/inference_model/ppyolov2_r50vd_dcn_365e_publaynet/ppyolov2_r50vd_dcn_365e_publaynet_infer/ppyolov2_r50vd_dcn_365e_publaynet.tar\n"
534
+ ]
535
+ },
536
+ {
537
+ "output_type": "stream",
538
+ "name": "stderr",
539
+ "text": [
540
+ "100%|██████████| 221M/221M [00:37<00:00, 5.92MiB/s]\n"
541
+ ]
542
+ }
543
+ ]
544
+ },
545
+ {
546
+ "cell_type": "code",
547
+ "source": [
548
+ "layout"
549
+ ],
550
+ "metadata": {
551
+ "id": "G76oO2WXCX6v",
552
+ "colab": {
553
+ "base_uri": "https://localhost:8080/"
554
+ },
555
+ "outputId": "2b0f9ed6-ff8c-4b46-b69c-5e3961d017d4"
556
+ },
557
+ "execution_count": null,
558
+ "outputs": [
559
+ {
560
+ "output_type": "execute_result",
561
+ "data": {
562
+ "text/plain": [
563
+ "Layout(_blocks=[TextBlock(block=Rectangle(x_1=300.35406494140625, y_1=1716.4278564453125, x_2=1401.105712890625, y_2=1876.4561767578125), text=None, id=None, type=Text, parent=None, next=None, score=0.947794497013092), TextBlock(block=Rectangle(x_1=296.242431640625, y_1=1969.3675537109375, x_2=1405.8653564453125, y_2=2034.4422607421875), text=None, id=None, type=Text, parent=None, next=None, score=0.934190034866333), TextBlock(block=Rectangle(x_1=296.2332763671875, y_1=1460.10986328125, x_2=1401.1175537109375, y_2=1553.036865234375), text=None, id=None, type=Text, parent=None, next=None, score=0.924132227897644), TextBlock(block=Rectangle(x_1=294.98626708984375, y_1=444.1419677734375, x_2=1408.130126953125, y_2=567.1005249023438), text=None, id=None, type=Text, parent=None, next=None, score=0.9196642637252808), TextBlock(block=Rectangle(x_1=300.4600830078125, y_1=1669.076171875, x_2=711.9566040039062, y_2=1697.28076171875), text=None, id=None, type=Title, parent=None, next=None, score=0.8556817770004272), TextBlock(block=Rectangle(x_1=297.86297607421875, y_1=220.03121948242188, x_2=1409.0029296875, y_2=418.0099182128906), text=None, id=None, type=Table, parent=None, next=None, score=0.7598645091056824), TextBlock(block=Rectangle(x_1=298.9613342285156, y_1=1601.4661865234375, x_2=687.694580078125, y_2=1633.7120361328125), text=None, id=None, type=Title, parent=None, next=None, score=0.7429183125495911), TextBlock(block=Rectangle(x_1=295.4989318847656, y_1=1405.8271484375, x_2=551.2619018554688, y_2=1438.658203125), text=None, id=None, type=Title, parent=None, next=None, score=0.6753251552581787), TextBlock(block=Rectangle(x_1=282.51495361328125, y_1=647.5087890625, x_2=1415.5732421875, y_2=1368.4254150390625), text=None, id=None, type=List, parent=None, next=None, score=0.6743354201316833), TextBlock(block=Rectangle(x_1=298.611328125, y_1=1063.1019287109375, x_2=366.89483642578125, y_2=1092.1378173828125), text=None, id=None, type=Text, parent=None, next=None, score=0.6345258951187134), TextBlock(block=Rectangle(x_1=298.71820068359375, y_1=1171.6640625, x_2=998.8455200195312, y_2=1205.39306640625), text=None, id=None, type=Text, parent=None, next=None, score=0.6338083148002625), TextBlock(block=Rectangle(x_1=294.16180419921875, y_1=931.6088256835938, x_2=1402.220458984375, y_2=996.5545043945312), text=None, id=None, type=Text, parent=None, next=None, score=0.5081444382667542)], page_data={})"
564
+ ]
565
+ },
566
+ "metadata": {},
567
+ "execution_count": 13
568
+ }
569
+ ]
570
+ },
571
+ {
572
+ "cell_type": "code",
573
+ "source": [
574
+ "x_1=0\n",
575
+ "y_1=0\n",
576
+ "x_2=0\n",
577
+ "y_2=0\n",
578
+ "\n",
579
+ "for l in layout:\n",
580
+ " #print(l)\n",
581
+ " if l.type == 'Table':\n",
582
+ " x_1 = int(l.block.x_1)\n",
583
+ " print(l.block.x_1)\n",
584
+ " y_1 = int(l.block.y_1)\n",
585
+ " x_2 = int(l.block.x_2)\n",
586
+ " y_2 = int(l.block.y_2)\n",
587
+ "\n",
588
+ " break"
589
+ ],
590
+ "metadata": {
591
+ "id": "y3h0kCz-CX_U",
592
+ "colab": {
593
+ "base_uri": "https://localhost:8080/"
594
+ },
595
+ "outputId": "5b44d211-694b-409f-df7c-69189d4b448f"
596
+ },
597
+ "execution_count": null,
598
+ "outputs": [
599
+ {
600
+ "output_type": "stream",
601
+ "name": "stdout",
602
+ "text": [
603
+ "297.86298\n"
604
+ ]
605
+ }
606
+ ]
607
+ },
608
+ {
609
+ "cell_type": "code",
610
+ "source": [
611
+ "print(x_1,y_1,x_2,y_2)"
612
+ ],
613
+ "metadata": {
614
+ "id": "cdiYPeCJCYIg",
615
+ "colab": {
616
+ "base_uri": "https://localhost:8080/"
617
+ },
618
+ "outputId": "4160ed2b-e1d1-4174-dd2e-55bee31167f3"
619
+ },
620
+ "execution_count": null,
621
+ "outputs": [
622
+ {
623
+ "output_type": "stream",
624
+ "name": "stdout",
625
+ "text": [
626
+ "297 220 1409 418\n"
627
+ ]
628
+ }
629
+ ]
630
+ },
631
+ {
632
+ "cell_type": "code",
633
+ "source": [
634
+ "im = cv2.imread('/content/pages/page13.jpg')"
635
+ ],
636
+ "metadata": {
637
+ "id": "F39kJV3hCYLV"
638
+ },
639
+ "execution_count": null,
640
+ "outputs": []
641
+ },
642
+ {
643
+ "cell_type": "code",
644
+ "source": [
645
+ "cv2.imwrite('ext_im.jpg', im[y_1:y_2,x_1:x_2])"
646
+ ],
647
+ "metadata": {
648
+ "id": "EQDXSNijCYPs",
649
+ "colab": {
650
+ "base_uri": "https://localhost:8080/"
651
+ },
652
+ "outputId": "9c0e6954-da96-491b-efcb-318dc5410561"
653
+ },
654
+ "execution_count": null,
655
+ "outputs": [
656
+ {
657
+ "output_type": "execute_result",
658
+ "data": {
659
+ "text/plain": [
660
+ "True"
661
+ ]
662
+ },
663
+ "metadata": {},
664
+ "execution_count": 17
665
+ }
666
+ ]
667
+ },
668
+ {
669
+ "cell_type": "code",
670
+ "source": [],
671
+ "metadata": {
672
+ "id": "7O2P4aIMor_e"
673
+ },
674
+ "execution_count": null,
675
+ "outputs": []
676
+ },
677
+ {
678
+ "cell_type": "markdown",
679
+ "metadata": {
680
+ "id": "EGwGhHnd8i_h"
681
+ },
682
+ "source": [
683
+ "# Text Detection and Recognition"
684
+ ]
685
+ },
686
+ {
687
+ "cell_type": "code",
688
+ "source": [
689
+ "from paddleocr import PaddleOCR, draw_ocr"
690
+ ],
691
+ "metadata": {
692
+ "id": "N6WQZXhLLDWk"
693
+ },
694
+ "execution_count": null,
695
+ "outputs": []
696
+ },
697
+ {
698
+ "cell_type": "code",
699
+ "source": [
700
+ "ocr = PaddleOCR(lang='en')\n",
701
+ "image_path = '/content/ext_im.jpg'\n",
702
+ "image_cv = cv2.imread(image_path)\n",
703
+ "image_height = image_cv.shape[0]\n",
704
+ "image_width = image_cv.shape[1]\n",
705
+ "output = ocr.ocr(image_path)[0]"
706
+ ],
707
+ "metadata": {
708
+ "colab": {
709
+ "base_uri": "https://localhost:8080/"
710
+ },
711
+ "id": "A8bCZ9AULDZF",
712
+ "outputId": "78de4243-7a38-4378-8dfd-063004300535"
713
+ },
714
+ "execution_count": null,
715
+ "outputs": [
716
+ {
717
+ "output_type": "stream",
718
+ "name": "stdout",
719
+ "text": [
720
+ "download https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar to /root/.paddleocr/whl/det/en/en_PP-OCRv3_det_infer/en_PP-OCRv3_det_infer.tar\n"
721
+ ]
722
+ },
723
+ {
724
+ "output_type": "stream",
725
+ "name": "stderr",
726
+ "text": [
727
+ "100%|██████████| 4.00M/4.00M [00:07<00:00, 505kiB/s] \n"
728
+ ]
729
+ },
730
+ {
731
+ "output_type": "stream",
732
+ "name": "stdout",
733
+ "text": [
734
+ "download https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar to /root/.paddleocr/whl/rec/en/en_PP-OCRv3_rec_infer/en_PP-OCRv3_rec_infer.tar\n"
735
+ ]
736
+ },
737
+ {
738
+ "output_type": "stream",
739
+ "name": "stderr",
740
+ "text": [
741
+ "100%|██████████| 9.96M/9.96M [00:14<00:00, 693kiB/s] \n"
742
+ ]
743
+ },
744
+ {
745
+ "output_type": "stream",
746
+ "name": "stdout",
747
+ "text": [
748
+ "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"
749
+ ]
750
+ },
751
+ {
752
+ "output_type": "stream",
753
+ "name": "stderr",
754
+ "text": [
755
+ "100%|██████████| 2.19M/2.19M [00:11<00:00, 190kiB/s]"
756
+ ]
757
+ },
758
+ {
759
+ "output_type": "stream",
760
+ "name": "stdout",
761
+ "text": [
762
+ "[2022/11/18 13:00:00] 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_box_type='quad', 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_limit_side_len=960, det_limit_type='max', det_model_dir='/root/.paddleocr/whl/det/en/en_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, 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, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='en', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='/usr/local/lib/python3.7/dist-packages/paddleocr/ppocr/utils/en_dict.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='/root/.paddleocr/whl/rec/en/en_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=False, use_dilation=False, use_gpu=True, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)\n"
763
+ ]
764
+ },
765
+ {
766
+ "output_type": "stream",
767
+ "name": "stderr",
768
+ "text": [
769
+ "\n"
770
+ ]
771
+ },
772
+ {
773
+ "output_type": "stream",
774
+ "name": "stdout",
775
+ "text": [
776
+ "[2022/11/18 13:00:00] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process\n",
777
+ "[2022/11/18 13:00:01] ppocr DEBUG: dt_boxes num : 42, elapse : 0.12288975715637207\n",
778
+ "[2022/11/18 13:00:01] ppocr DEBUG: rec_res num : 42, elapse : 0.12553930282592773\n"
779
+ ]
780
+ }
781
+ ]
782
+ },
783
+ {
784
+ "cell_type": "code",
785
+ "source": [
786
+ "print(output)"
787
+ ],
788
+ "metadata": {
789
+ "colab": {
790
+ "base_uri": "https://localhost:8080/"
791
+ },
792
+ "id": "VBIDZA0XLDeA",
793
+ "outputId": "b86018c1-5b24-4897-9174-a34299909bf7"
794
+ },
795
+ "execution_count": null,
796
+ "outputs": [
797
+ {
798
+ "output_type": "stream",
799
+ "name": "stdout",
800
+ "text": [
801
+ "[[[[693.0, 4.0], [755.0, 4.0], [755.0, 36.0], [693.0, 36.0]], ('GPU', 0.9990124106407166)], [[[70.0, 5.0], [148.0, 5.0], [148.0, 36.0], [70.0, 36.0]], ('Model', 0.9997721910476685)], [[[230.0, 5.0], [394.0, 8.0], [394.0, 37.0], [229.0, 35.0]], ('Updates (105)', 0.9652137756347656)], [[[425.0, 5.0], [511.0, 5.0], [511.0, 36.0], [425.0, 36.0]], ('Epochs', 0.9998965263366699)], [[[537.0, 5.0], [612.0, 5.0], [612.0, 36.0], [537.0, 36.0]], ('Hours', 0.9620624780654907)], [[[833.0, 4.0], [958.0, 4.0], [958.0, 33.0], [833.0, 33.0]], ('Train NLL', 0.9994094371795654)], [[[988.0, 6.0], [1104.0, 6.0], [1104.0, 32.0], [988.0, 32.0]], ('Dev.NLL', 0.9872051477432251)], [[[42.0, 47.0], [177.0, 47.0], [177.0, 72.0], [42.0, 72.0]], ('RNNenc-30', 0.9995856881141663)], [[[285.0, 46.0], [341.0, 46.0], [341.0, 74.0], [285.0, 74.0]], ('8.46', 0.9999933242797852)], [[[446.0, 46.0], [489.0, 46.0], [489.0, 74.0], [446.0, 74.0]], ('6.4', 0.9964627623558044)], [[[553.0, 45.0], [599.0, 45.0], [599.0, 74.0], [553.0, 74.0]], ('109', 0.9999635815620422)], [[[641.0, 47.0], [805.0, 47.0], [805.0, 72.0], [641.0, 72.0]], ('TITAN BLACK', 0.9913126230239868)], [[[869.0, 43.0], [923.0, 43.0], [923.0, 75.0], [869.0, 75.0]], ('28.1', 0.999950110912323)], [[[1019.0, 46.0], [1075.0, 46.0], [1075.0, 74.0], [1019.0, 74.0]], ('53.0', 0.999934196472168)], [[[41.0, 75.0], [177.0, 75.0], [177.0, 101.0], [41.0, 101.0]], ('RNNenc-50', 0.9980602264404297)], [[[285.0, 75.0], [341.0, 75.0], [341.0, 104.0], [285.0, 104.0]], ('6.00', 0.9998406171798706)], [[[446.0, 74.0], [489.0, 74.0], [489.0, 104.0], [446.0, 104.0]], ('4.5', 0.9982914924621582)], [[[553.0, 74.0], [599.0, 74.0], [599.0, 104.0], [553.0, 104.0]], ('108', 0.9998137950897217)], [[[644.0, 78.0], [804.0, 78.0], [804.0, 103.0], [644.0, 103.0]], ('Quadro K-6000', 0.9990899562835693)], [[[868.0, 73.0], [927.0, 73.0], [927.0, 105.0], [868.0, 105.0]], ('44.0', 0.999671459197998)], [[[1017.0, 73.0], [1076.0, 73.0], [1076.0, 105.0], [1017.0, 105.0]], ('43.6', 0.9998911619186401)], [[[27.0, 109.0], [193.0, 109.0], [193.0, 134.0], [27.0, 134.0]], ('RNNsearch-30', 0.9990729689598083)], [[[284.0, 108.0], [338.0, 108.0], [338.0, 136.0], [284.0, 136.0]], ('4.71', 0.9994158744812012)], [[[445.0, 108.0], [489.0, 108.0], [489.0, 136.0], [445.0, 136.0]], ('3.6', 0.9944102168083191)], [[[553.0, 108.0], [599.0, 108.0], [599.0, 136.0], [553.0, 136.0]], ('113', 0.9994351267814636)], [[[643.0, 111.0], [804.0, 111.0], [804.0, 132.0], [643.0, 132.0]], ('TITAN BLACK', 0.9635356664657593)], [[[870.0, 108.0], [923.0, 108.0], [923.0, 136.0], [870.0, 136.0]], ('26.7', 0.9992948770523071)], [[[1018.0, 108.0], [1074.0, 108.0], [1074.0, 136.0], [1018.0, 136.0]], ('47.2', 0.9993252158164978)], [[[25.0, 139.0], [193.0, 139.0], [193.0, 163.0], [25.0, 163.0]], ('RNNsearch-50', 0.9973625540733337)], [[[285.0, 137.0], [339.0, 137.0], [339.0, 166.0], [285.0, 166.0]], ('2.88', 0.9999485015869141)], [[[445.0, 134.0], [489.0, 134.0], [489.0, 168.0], [445.0, 168.0]], ('2.2', 0.9979038238525391)], [[[551.0, 137.0], [598.0, 137.0], [598.0, 166.0], [551.0, 166.0]], ('111', 0.9987512230873108)], [[[643.0, 140.0], [804.0, 140.0], [804.0, 165.0], [643.0, 165.0]], ('Quadro K-6000', 0.9971157908439636)], [[[870.0, 137.0], [924.0, 137.0], [924.0, 166.0], [870.0, 166.0]], ('40.7', 0.9991925954818726)], [[[1018.0, 135.0], [1075.0, 135.0], [1075.0, 167.0], [1018.0, 167.0]], ('38.1', 0.9999594688415527)], [[[21.0, 172.0], [196.0, 172.0], [196.0, 193.0], [21.0, 193.0]], ('RNNsearch-50*', 0.9954861402511597)], [[[285.0, 170.0], [338.0, 170.0], [338.0, 197.0], [285.0, 197.0]], ('6.67', 0.9998753666877747)], [[[446.0, 170.0], [489.0, 170.0], [489.0, 197.0], [446.0, 197.0]], ('5.0', 0.9963653683662415)], [[[551.0, 170.0], [600.0, 170.0], [600.0, 197.0], [551.0, 197.0]], ('252', 0.9991322159767151)], [[[644.0, 172.0], [804.0, 172.0], [804.0, 197.0], [644.0, 197.0]], ('Quadro K-6000', 0.9994592666625977)], [[[870.0, 170.0], [923.0, 170.0], [923.0, 197.0], [870.0, 197.0]], ('36.7', 0.9990472793579102)], [[[1019.0, 170.0], [1074.0, 170.0], [1074.0, 197.0], [1019.0, 197.0]], ('35.2', 0.9986913204193115)]]\n"
802
+ ]
803
+ }
804
+ ]
805
+ },
806
+ {
807
+ "cell_type": "code",
808
+ "source": [
809
+ "boxes = [line[0] for line in output]\n",
810
+ "texts = [line[1][0] for line in output]\n",
811
+ "probabilities = [line[1][1] for line in output]"
812
+ ],
813
+ "metadata": {
814
+ "id": "nNMBAQ78LDgG"
815
+ },
816
+ "execution_count": null,
817
+ "outputs": []
818
+ },
819
+ {
820
+ "cell_type": "code",
821
+ "source": [
822
+ "image_boxes = image_cv.copy()\n"
823
+ ],
824
+ "metadata": {
825
+ "id": "uukcg4SWV_dg"
826
+ },
827
+ "execution_count": null,
828
+ "outputs": []
829
+ },
830
+ {
831
+ "cell_type": "code",
832
+ "source": [
833
+ "for box,text in zip(boxes,texts):\n",
834
+ " cv2.rectangle(image_boxes, (int(box[0][0]),int(box[0][1])), (int(box[2][0]),int(box[2][1])),(0,0,255),1)\n",
835
+ " cv2.putText(image_boxes, text,(int(box[0][0]),int(box[0][1])),cv2.FONT_HERSHEY_SIMPLEX,1,(222,0,0),1)"
836
+ ],
837
+ "metadata": {
838
+ "id": "l_HzbiA7V_fw"
839
+ },
840
+ "execution_count": null,
841
+ "outputs": []
842
+ },
843
+ {
844
+ "cell_type": "code",
845
+ "source": [
846
+ "cv2.imwrite('detections.jpg', image_boxes)"
847
+ ],
848
+ "metadata": {
849
+ "colab": {
850
+ "base_uri": "https://localhost:8080/"
851
+ },
852
+ "id": "PfUG9mcgV_iJ",
853
+ "outputId": "b97aaa44-61b9-4a62-dd01-c8c26b66e9c7"
854
+ },
855
+ "execution_count": null,
856
+ "outputs": [
857
+ {
858
+ "output_type": "execute_result",
859
+ "data": {
860
+ "text/plain": [
861
+ "True"
862
+ ]
863
+ },
864
+ "metadata": {},
865
+ "execution_count": 24
866
+ }
867
+ ]
868
+ },
869
+ {
870
+ "cell_type": "markdown",
871
+ "metadata": {
872
+ "id": "kYWt0lzDHZNp"
873
+ },
874
+ "source": [
875
+ "# Reconstruction"
876
+ ]
877
+ },
878
+ {
879
+ "cell_type": "markdown",
880
+ "source": [
881
+ "## Get Horizontal and Vertical Lines"
882
+ ],
883
+ "metadata": {
884
+ "id": "ruzifYJz4H6y"
885
+ }
886
+ },
887
+ {
888
+ "cell_type": "code",
889
+ "source": [
890
+ "im = image_cv.copy()"
891
+ ],
892
+ "metadata": {
893
+ "id": "YLIoKedcqby_"
894
+ },
895
+ "execution_count": null,
896
+ "outputs": []
897
+ },
898
+ {
899
+ "cell_type": "code",
900
+ "source": [
901
+ "horiz_boxes = []\n",
902
+ "vert_boxes = []\n",
903
+ "\n",
904
+ "for box in boxes:\n",
905
+ " x_h, x_v = 0,int(box[0][0])\n",
906
+ " y_h, y_v = int(box[0][1]),0\n",
907
+ " width_h,width_v = image_width, int(box[2][0]-box[0][0])\n",
908
+ " height_h,height_v = int(box[2][1]-box[0][1]),image_height\n",
909
+ "\n",
910
+ " horiz_boxes.append([x_h,y_h,x_h+width_h,y_h+height_h])\n",
911
+ " vert_boxes.append([x_v,y_v,x_v+width_v,y_v+height_v])\n",
912
+ "\n",
913
+ " cv2.rectangle(im,(x_h,y_h), (x_h+width_h,y_h+height_h),(0,0,255),1)\n",
914
+ " cv2.rectangle(im,(x_v,y_v), (x_v+width_v,y_v+height_v),(0,255,0),1)\n",
915
+ ""
916
+ ],
917
+ "metadata": {
918
+ "id": "GwcAAe-wccnF"
919
+ },
920
+ "execution_count": null,
921
+ "outputs": []
922
+ },
923
+ {
924
+ "cell_type": "code",
925
+ "source": [
926
+ "cv2.imwrite('horiz_vert.jpg',im)"
927
+ ],
928
+ "metadata": {
929
+ "colab": {
930
+ "base_uri": "https://localhost:8080/"
931
+ },
932
+ "id": "7UxFGhMkccph",
933
+ "outputId": "344b62aa-8bbf-46e0-ccea-bd1c5eb60e3a"
934
+ },
935
+ "execution_count": null,
936
+ "outputs": [
937
+ {
938
+ "output_type": "execute_result",
939
+ "data": {
940
+ "text/plain": [
941
+ "True"
942
+ ]
943
+ },
944
+ "metadata": {},
945
+ "execution_count": 27
946
+ }
947
+ ]
948
+ },
949
+ {
950
+ "cell_type": "markdown",
951
+ "source": [
952
+ "## Non-Max Suppression"
953
+ ],
954
+ "metadata": {
955
+ "id": "ekVFvJrM4ROL"
956
+ }
957
+ },
958
+ {
959
+ "cell_type": "code",
960
+ "source": [
961
+ "horiz_out = tf.image.non_max_suppression(\n",
962
+ " horiz_boxes,\n",
963
+ " probabilities,\n",
964
+ " max_output_size = 1000,\n",
965
+ " iou_threshold=0.1,\n",
966
+ " score_threshold=float('-inf'),\n",
967
+ " name=None\n",
968
+ ")"
969
+ ],
970
+ "metadata": {
971
+ "id": "4LVSSB2fcoe7"
972
+ },
973
+ "execution_count": null,
974
+ "outputs": []
975
+ },
976
+ {
977
+ "cell_type": "code",
978
+ "source": [
979
+ "horiz_lines = np.sort(np.array(horiz_out))\n",
980
+ "print(horiz_lines)"
981
+ ],
982
+ "metadata": {
983
+ "colab": {
984
+ "base_uri": "https://localhost:8080/"
985
+ },
986
+ "id": "pOboYpGnccr2",
987
+ "outputId": "02933914-32bb-4b3d-88bb-72745b6dda8b"
988
+ },
989
+ "execution_count": null,
990
+ "outputs": [
991
+ {
992
+ "output_type": "stream",
993
+ "name": "stdout",
994
+ "text": [
995
+ "[ 3 8 20 24 34 36]\n"
996
+ ]
997
+ }
998
+ ]
999
+ },
1000
+ {
1001
+ "cell_type": "code",
1002
+ "source": [
1003
+ "im_nms = image_cv.copy()"
1004
+ ],
1005
+ "metadata": {
1006
+ "id": "pfxHrn3iccyK"
1007
+ },
1008
+ "execution_count": null,
1009
+ "outputs": []
1010
+ },
1011
+ {
1012
+ "cell_type": "code",
1013
+ "source": [
1014
+ "for val in horiz_lines:\n",
1015
+ " cv2.rectangle(im_nms, (int(horiz_boxes[val][0]),int(horiz_boxes[val][1])), (int(horiz_boxes[val][2]),int(horiz_boxes[val][3])),(0,0,255),1)\n",
1016
+ ""
1017
+ ],
1018
+ "metadata": {
1019
+ "id": "68PCHfmZcc0L"
1020
+ },
1021
+ "execution_count": null,
1022
+ "outputs": []
1023
+ },
1024
+ {
1025
+ "cell_type": "code",
1026
+ "source": [
1027
+ "cv2.imwrite('im_nms.jpg',im_nms)"
1028
+ ],
1029
+ "metadata": {
1030
+ "colab": {
1031
+ "base_uri": "https://localhost:8080/"
1032
+ },
1033
+ "id": "Z8r9qpiAcc2X",
1034
+ "outputId": "9510d3cf-3870-4c77-b9ff-dd903f9a7902"
1035
+ },
1036
+ "execution_count": null,
1037
+ "outputs": [
1038
+ {
1039
+ "output_type": "execute_result",
1040
+ "data": {
1041
+ "text/plain": [
1042
+ "True"
1043
+ ]
1044
+ },
1045
+ "metadata": {},
1046
+ "execution_count": 32
1047
+ }
1048
+ ]
1049
+ },
1050
+ {
1051
+ "cell_type": "code",
1052
+ "source": [
1053
+ "vert_out = tf.image.non_max_suppression(\n",
1054
+ " vert_boxes,\n",
1055
+ " probabilities,\n",
1056
+ " max_output_size = 1000,\n",
1057
+ " iou_threshold=0.1,\n",
1058
+ " score_threshold=float('-inf'),\n",
1059
+ " name=None\n",
1060
+ ")"
1061
+ ],
1062
+ "metadata": {
1063
+ "id": "mKgPuh7rcc4s"
1064
+ },
1065
+ "execution_count": null,
1066
+ "outputs": []
1067
+ },
1068
+ {
1069
+ "cell_type": "code",
1070
+ "source": [
1071
+ "print(vert_out)"
1072
+ ],
1073
+ "metadata": {
1074
+ "colab": {
1075
+ "base_uri": "https://localhost:8080/"
1076
+ },
1077
+ "id": "GBpKsImVcc6p",
1078
+ "outputId": "f7bfbf04-9318-4230-f9df-98101fc7cadd"
1079
+ },
1080
+ "execution_count": null,
1081
+ "outputs": [
1082
+ {
1083
+ "output_type": "stream",
1084
+ "name": "stdout",
1085
+ "text": [
1086
+ "tf.Tensor([ 8 10 34 12 3 1 39], shape=(7,), dtype=int32)\n"
1087
+ ]
1088
+ }
1089
+ ]
1090
+ },
1091
+ {
1092
+ "cell_type": "code",
1093
+ "source": [
1094
+ "vert_lines = np.sort(np.array(vert_out))\n",
1095
+ "print(vert_lines)"
1096
+ ],
1097
+ "metadata": {
1098
+ "colab": {
1099
+ "base_uri": "https://localhost:8080/"
1100
+ },
1101
+ "id": "K0lBh-yz5YLp",
1102
+ "outputId": "31a4ea8a-27ce-4b53-9bdb-9857c65ebdaa"
1103
+ },
1104
+ "execution_count": null,
1105
+ "outputs": [
1106
+ {
1107
+ "output_type": "stream",
1108
+ "name": "stdout",
1109
+ "text": [
1110
+ "[ 1 3 8 10 12 34 39]\n"
1111
+ ]
1112
+ }
1113
+ ]
1114
+ },
1115
+ {
1116
+ "cell_type": "code",
1117
+ "source": [
1118
+ "for val in vert_lines:\n",
1119
+ " cv2.rectangle(im_nms, (int(vert_boxes[val][0]),int(vert_boxes[val][1])), (int(vert_boxes[val][2]),int(vert_boxes[val][3])),(255,0,0),1)\n",
1120
+ ""
1121
+ ],
1122
+ "metadata": {
1123
+ "id": "WqsLm0L_cc84"
1124
+ },
1125
+ "execution_count": null,
1126
+ "outputs": []
1127
+ },
1128
+ {
1129
+ "cell_type": "code",
1130
+ "source": [
1131
+ "cv2.imwrite('im_nms.jpg',im_nms)"
1132
+ ],
1133
+ "metadata": {
1134
+ "colab": {
1135
+ "base_uri": "https://localhost:8080/"
1136
+ },
1137
+ "id": "xZOEa7lpcdGM",
1138
+ "outputId": "a92cbce5-7529-4b3b-f4b5-2c016904ab21"
1139
+ },
1140
+ "execution_count": null,
1141
+ "outputs": [
1142
+ {
1143
+ "output_type": "execute_result",
1144
+ "data": {
1145
+ "text/plain": [
1146
+ "True"
1147
+ ]
1148
+ },
1149
+ "metadata": {},
1150
+ "execution_count": 37
1151
+ }
1152
+ ]
1153
+ },
1154
+ {
1155
+ "cell_type": "markdown",
1156
+ "source": [
1157
+ "## Convert to CSV"
1158
+ ],
1159
+ "metadata": {
1160
+ "id": "116eBUrO93-i"
1161
+ }
1162
+ },
1163
+ {
1164
+ "cell_type": "code",
1165
+ "source": [
1166
+ "\n",
1167
+ "\n",
1168
+ "out_array = [[\"\" for i in range(len(vert_lines))] for j in range(len(horiz_lines))]\n",
1169
+ "print(np.array(out_array).shape)\n",
1170
+ "print(out_array)"
1171
+ ],
1172
+ "metadata": {
1173
+ "colab": {
1174
+ "base_uri": "https://localhost:8080/"
1175
+ },
1176
+ "id": "HRQzwVUTcdIq",
1177
+ "outputId": "93b6914b-c713-48e0-ecaf-87a764a48d13"
1178
+ },
1179
+ "execution_count": null,
1180
+ "outputs": [
1181
+ {
1182
+ "output_type": "stream",
1183
+ "name": "stdout",
1184
+ "text": [
1185
+ "(6, 7)\n",
1186
+ "[['', '', '', '', '', '', ''], ['', '', '', '', '', '', ''], ['', '', '', '', '', '', ''], ['', '', '', '', '', '', ''], ['', '', '', '', '', '', ''], ['', '', '', '', '', '', '']]\n"
1187
+ ]
1188
+ }
1189
+ ]
1190
+ },
1191
+ {
1192
+ "cell_type": "code",
1193
+ "source": [
1194
+ "\n",
1195
+ "unordered_boxes = []\n",
1196
+ "\n",
1197
+ "for i in vert_lines:\n",
1198
+ " print(vert_boxes[i])\n",
1199
+ " unordered_boxes.append(vert_boxes[i][0])"
1200
+ ],
1201
+ "metadata": {
1202
+ "colab": {
1203
+ "base_uri": "https://localhost:8080/"
1204
+ },
1205
+ "id": "sSrupaRZIAk_",
1206
+ "outputId": "61055c32-2de2-4a31-c36f-e3857a6cc939"
1207
+ },
1208
+ "execution_count": null,
1209
+ "outputs": [
1210
+ {
1211
+ "output_type": "stream",
1212
+ "name": "stdout",
1213
+ "text": [
1214
+ "[70, 0, 148, 198]\n",
1215
+ "[425, 0, 511, 198]\n",
1216
+ "[285, 0, 341, 198]\n",
1217
+ "[553, 0, 599, 198]\n",
1218
+ "[869, 0, 923, 198]\n",
1219
+ "[1018, 0, 1075, 198]\n",
1220
+ "[644, 0, 804, 198]\n"
1221
+ ]
1222
+ }
1223
+ ]
1224
+ },
1225
+ {
1226
+ "cell_type": "code",
1227
+ "source": [
1228
+ "ordered_boxes = np.argsort(unordered_boxes)\n",
1229
+ "print(ordered_boxes)"
1230
+ ],
1231
+ "metadata": {
1232
+ "colab": {
1233
+ "base_uri": "https://localhost:8080/"
1234
+ },
1235
+ "id": "lRMlVNh_HuJV",
1236
+ "outputId": "de3751a5-525d-4659-acbc-00d61fcbeba1"
1237
+ },
1238
+ "execution_count": null,
1239
+ "outputs": [
1240
+ {
1241
+ "output_type": "stream",
1242
+ "name": "stdout",
1243
+ "text": [
1244
+ "[0 2 1 3 6 4 5]\n"
1245
+ ]
1246
+ }
1247
+ ]
1248
+ },
1249
+ {
1250
+ "cell_type": "code",
1251
+ "source": [
1252
+ "def intersection(box_1, box_2):\n",
1253
+ " return [box_2[0], box_1[1],box_2[2], box_1[3]]"
1254
+ ],
1255
+ "metadata": {
1256
+ "id": "AHHaxKUuC6jQ"
1257
+ },
1258
+ "execution_count": null,
1259
+ "outputs": []
1260
+ },
1261
+ {
1262
+ "cell_type": "code",
1263
+ "source": [
1264
+ "def iou(box_1, box_2):\n",
1265
+ "\n",
1266
+ " x_1 = max(box_1[0], box_2[0])\n",
1267
+ " y_1 = max(box_1[1], box_2[1])\n",
1268
+ " x_2 = min(box_1[2], box_2[2])\n",
1269
+ " y_2 = min(box_1[3], box_2[3])\n",
1270
+ "\n",
1271
+ " inter = abs(max((x_2 - x_1, 0)) * max((y_2 - y_1), 0))\n",
1272
+ " if inter == 0:\n",
1273
+ " return 0\n",
1274
+ "\n",
1275
+ " box_1_area = abs((box_1[2] - box_1[0]) * (box_1[3] - box_1[1]))\n",
1276
+ " box_2_area = abs((box_2[2] - box_2[0]) * (box_2[3] - box_2[1]))\n",
1277
+ "\n",
1278
+ " return inter / float(box_1_area + box_2_area - inter)"
1279
+ ],
1280
+ "metadata": {
1281
+ "id": "fDVb0DkxJSIf"
1282
+ },
1283
+ "execution_count": null,
1284
+ "outputs": []
1285
+ },
1286
+ {
1287
+ "cell_type": "code",
1288
+ "source": [
1289
+ "for i in range(len(horiz_lines)):\n",
1290
+ " for j in range(len(vert_lines)):\n",
1291
+ " resultant = intersection(horiz_boxes[horiz_lines[i]], vert_boxes[vert_lines[ordered_boxes[j]]] )\n",
1292
+ "\n",
1293
+ " for b in range(len(boxes)):\n",
1294
+ " the_box = [boxes[b][0][0],boxes[b][0][1],boxes[b][2][0],boxes[b][2][1]]\n",
1295
+ " if(iou(resultant,the_box)>0.1):\n",
1296
+ " out_array[i][j] = texts[b]"
1297
+ ],
1298
+ "metadata": {
1299
+ "id": "LWGhCwg6BIoL"
1300
+ },
1301
+ "execution_count": null,
1302
+ "outputs": []
1303
+ },
1304
+ {
1305
+ "cell_type": "code",
1306
+ "source": [
1307
+ "out_array=np.array(out_array)"
1308
+ ],
1309
+ "metadata": {
1310
+ "id": "c4tEY9LGNIM9"
1311
+ },
1312
+ "execution_count": null,
1313
+ "outputs": []
1314
+ },
1315
+ {
1316
+ "cell_type": "code",
1317
+ "source": [
1318
+ "out_array"
1319
+ ],
1320
+ "metadata": {
1321
+ "id": "_ekto4-Ymxv2",
1322
+ "outputId": "f7a8e379-2879-4ed0-e8c0-4e127aacc50a",
1323
+ "colab": {
1324
+ "base_uri": "https://localhost:8080/"
1325
+ }
1326
+ },
1327
+ "execution_count": null,
1328
+ "outputs": [
1329
+ {
1330
+ "output_type": "execute_result",
1331
+ "data": {
1332
+ "text/plain": [
1333
+ "array([['Model', 'Updates (105)', 'Epochs', 'Hours', 'GPU', 'Train NLL',\n",
1334
+ " 'Dev.NLL'],\n",
1335
+ " ['RNNenc-30', '8.46', '6.4', '109', 'TITAN BLACK', '28.1', '53.0'],\n",
1336
+ " ['RNNenc-50', '6.00', '4.5', '108', 'Quadro K-6000', '44.0',\n",
1337
+ " '43.6'],\n",
1338
+ " ['RNNsearch-30', '4.71', '3.6', '113', 'TITAN BLACK', '26.7',\n",
1339
+ " '47.2'],\n",
1340
+ " ['RNNsearch-50', '2.88', '2.2', '111', 'Quadro K-6000', '40.7',\n",
1341
+ " '38.1'],\n",
1342
+ " ['RNNsearch-50*', '6.67', '5.0', '252', 'Quadro K-6000', '36.7',\n",
1343
+ " '35.2']], dtype='<U13')"
1344
+ ]
1345
+ },
1346
+ "metadata": {},
1347
+ "execution_count": 45
1348
+ }
1349
+ ]
1350
+ },
1351
+ {
1352
+ "cell_type": "code",
1353
+ "source": [
1354
+ "pd.DataFrame(out_array).to_csv('sample.csv')"
1355
+ ],
1356
+ "metadata": {
1357
+ "id": "D8UdX80wBI9V"
1358
+ },
1359
+ "execution_count": null,
1360
+ "outputs": []
1361
+ },
1362
+ {
1363
+ "cell_type": "markdown",
1364
+ "source": [
1365
+ "## Merging Cells"
1366
+ ],
1367
+ "metadata": {
1368
+ "id": "E693Ela3qhLx"
1369
+ }
1370
+ },
1371
+ {
1372
+ "cell_type": "code",
1373
+ "source": [
1374
+ "current_bank=['']*len(out_array[0,:])\n",
1375
+ "print(current_bank)"
1376
+ ],
1377
+ "metadata": {
1378
+ "colab": {
1379
+ "base_uri": "https://localhost:8080/"
1380
+ },
1381
+ "id": "XNcX7fEWPDfw",
1382
+ "outputId": "06cb1313-e8b8-4252-d305-f03fc03d14ed"
1383
+ },
1384
+ "execution_count": null,
1385
+ "outputs": [
1386
+ {
1387
+ "output_type": "stream",
1388
+ "name": "stdout",
1389
+ "text": [
1390
+ "['', '', '', '', '', '', '']\n"
1391
+ ]
1392
+ }
1393
+ ]
1394
+ },
1395
+ {
1396
+ "cell_type": "code",
1397
+ "source": [
1398
+ "def empty(arr):\n",
1399
+ " for i in arr:\n",
1400
+ " if i=='':\n",
1401
+ " return True\n",
1402
+ " return False"
1403
+ ],
1404
+ "metadata": {
1405
+ "id": "TTF5ojcCQJKR"
1406
+ },
1407
+ "execution_count": null,
1408
+ "outputs": []
1409
+ },
1410
+ {
1411
+ "cell_type": "code",
1412
+ "source": [
1413
+ "cleaned_array=[]"
1414
+ ],
1415
+ "metadata": {
1416
+ "id": "3w1amnEXSVSB"
1417
+ },
1418
+ "execution_count": null,
1419
+ "outputs": []
1420
+ },
1421
+ {
1422
+ "cell_type": "code",
1423
+ "source": [
1424
+ "for i in range(len(out_array)):\n",
1425
+ " if not empty(out_array[i]):\n",
1426
+ " current_bank=[out_array[i][j] for j in range(len(out_array[i]))]\n",
1427
+ " cleaned_array.append(current_bank)\n",
1428
+ " not_empty=True\n",
1429
+ " else:\n",
1430
+ " for j in range(len(out_array[i])):\n",
1431
+ " current_bank[j]+=' '+out_array[i][j]\n",
1432
+ " print('-->',current_bank)\n",
1433
+ "cleaned_array=np.array(cleaned_array)\n",
1434
+ "print(cleaned_array)"
1435
+ ],
1436
+ "metadata": {
1437
+ "id": "W_q9e2EkPepQ",
1438
+ "colab": {
1439
+ "base_uri": "https://localhost:8080/"
1440
+ },
1441
+ "outputId": "fba25f38-1e56-45c3-88fe-2211d38d4dca"
1442
+ },
1443
+ "execution_count": null,
1444
+ "outputs": [
1445
+ {
1446
+ "output_type": "stream",
1447
+ "name": "stdout",
1448
+ "text": [
1449
+ "[['Model' 'Updates (105)' 'Epochs' 'Hours' 'GPU' 'Train NLL' 'Dev.NLL']\n",
1450
+ " ['RNNenc-30' '8.46' '6.4' '109' 'TITAN BLACK' '28.1' '53.0']\n",
1451
+ " ['RNNenc-50' '6.00' '4.5' '108' 'Quadro K-6000' '44.0' '43.6']\n",
1452
+ " ['RNNsearch-30' '4.71' '3.6' '113' 'TITAN BLACK' '26.7' '47.2']\n",
1453
+ " ['RNNsearch-50' '2.88' '2.2' '111' 'Quadro K-6000' '40.7' '38.1']\n",
1454
+ " ['RNNsearch-50*' '6.67' '5.0' '252' 'Quadro K-6000' '36.7' '35.2']]\n"
1455
+ ]
1456
+ }
1457
+ ]
1458
+ },
1459
+ {
1460
+ "cell_type": "code",
1461
+ "source": [
1462
+ "pd.DataFrame(cleaned_array).to_csv('cleaned.csv')"
1463
+ ],
1464
+ "metadata": {
1465
+ "id": "RZltyMmD_E68"
1466
+ },
1467
+ "execution_count": null,
1468
+ "outputs": []
1469
+ },
1470
+ {
1471
+ "cell_type": "markdown",
1472
+ "source": [
1473
+ "# Convert to OWL Format"
1474
+ ],
1475
+ "metadata": {
1476
+ "id": "M9rH5mX9Mx7g"
1477
+ }
1478
+ },
1479
+ {
1480
+ "cell_type": "markdown",
1481
+ "source": [
1482
+ "# **CSV to Text**"
1483
+ ],
1484
+ "metadata": {
1485
+ "id": "SqFdbM634H5w"
1486
+ }
1487
+ },
1488
+ {
1489
+ "cell_type": "code",
1490
+ "source": [
1491
+ "import jpype\n",
1492
+ "import asposecells\n",
1493
+ "\n",
1494
+ "\n",
1495
+ "jpype.startJVM()\n",
1496
+ "from asposecells.api import Workbook\n",
1497
+ "\n",
1498
+ "workbook = Workbook(\"/content/sample.csv\")\n",
1499
+ "workbook.save(\"Output.docx\")\n",
1500
+ "jpype.shutdownJVM()"
1501
+ ],
1502
+ "metadata": {
1503
+ "id": "949GB9T1_Go7",
1504
+ "colab": {
1505
+ "base_uri": "https://localhost:8080/",
1506
+ "height": 373
1507
+ },
1508
+ "outputId": "d3bf9a55-8248-459c-8eb6-c2c67e5a84b3"
1509
+ },
1510
+ "execution_count": null,
1511
+ "outputs": [
1512
+ {
1513
+ "output_type": "error",
1514
+ "ename": "ModuleNotFoundError",
1515
+ "evalue": "ignored",
1516
+ "traceback": [
1517
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1518
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
1519
+ "\u001b[0;32m<ipython-input-52-0cc478de6e7d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mjpype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0masposecells\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mjpype\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartJVM\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1520
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'jpype'",
1521
+ "",
1522
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n"
1523
+ ],
1524
+ "errorDetails": {
1525
+ "actions": [
1526
+ {
1527
+ "action": "open_url",
1528
+ "actionText": "Open Examples",
1529
+ "url": "/notebooks/snippets/importing_libraries.ipynb"
1530
+ }
1531
+ ]
1532
+ }
1533
+ }
1534
+ ]
1535
+ },
1536
+ {
1537
+ "cell_type": "code",
1538
+ "source": [],
1539
+ "metadata": {
1540
+ "id": "eIGJDS7u4DLS"
1541
+ },
1542
+ "execution_count": null,
1543
+ "outputs": []
1544
+ },
1545
+ {
1546
+ "cell_type": "code",
1547
+ "source": [],
1548
+ "metadata": {
1549
+ "id": "ziHBaaCn4DN2"
1550
+ },
1551
+ "execution_count": null,
1552
+ "outputs": []
1553
+ },
1554
+ {
1555
+ "cell_type": "markdown",
1556
+ "source": [
1557
+ "# Brighten Image (For Anyone dealing with PDFs created from scanned images)"
1558
+ ],
1559
+ "metadata": {
1560
+ "id": "FIzj02CHqce7"
1561
+ }
1562
+ },
1563
+ {
1564
+ "cell_type": "code",
1565
+ "source": [
1566
+ "from PIL import Image, ImageEnhance\n",
1567
+ "\n",
1568
+ "#read the image\n",
1569
+ "im = Image.open(\"ext_im.jpg\")\n",
1570
+ "\n",
1571
+ "#image brightness enhancer\n",
1572
+ "enhancer = ImageEnhance.Brightness(im)\n",
1573
+ "\n",
1574
+ "factor = 1 #gives original image\n",
1575
+ "im_output = enhancer.enhance(factor)\n",
1576
+ "im_output.save('ext_im-1.jpg')\n",
1577
+ "\n",
1578
+ "factor = 1.5## brightens the image\n",
1579
+ "im_output = enhancer.enhance(factor)\n",
1580
+ "im_output.save('ext_im-2.jpg')\n"
1581
+ ],
1582
+ "metadata": {
1583
+ "id": "vnzqj5q34DQk"
1584
+ },
1585
+ "execution_count": null,
1586
+ "outputs": []
1587
+ },
1588
+ {
1589
+ "cell_type": "code",
1590
+ "source": [],
1591
+ "metadata": {
1592
+ "id": "arQSfE2br7YT"
1593
+ },
1594
+ "execution_count": null,
1595
+ "outputs": []
1596
+ }
1597
+ ],
1598
+ "metadata": {
1599
+ "accelerator": "GPU",
1600
+ "colab": {
1601
+ "collapsed_sections": [
1602
+ "E693Ela3qhLx",
1603
+ "SqFdbM634H5w",
1604
+ "FIzj02CHqce7"
1605
+ ],
1606
+ "provenance": []
1607
+ },
1608
+ "kernelspec": {
1609
+ "display_name": "Python 3",
1610
+ "name": "python3"
1611
+ },
1612
+ "language_info": {
1613
+ "name": "python"
1614
+ }
1615
+ },
1616
+ "nbformat": 4,
1617
+ "nbformat_minor": 0
1618
+ }