|
5 | 5 | "execution_count": 1,
|
6 | 6 | "metadata": {
|
7 | 7 | "ExecuteTime": {
|
8 |
| - "end_time": "2019-03-23T12:57:28.040474Z", |
9 |
| - "start_time": "2019-03-23T12:57:28.006379Z" |
| 8 | + "end_time": "2019-03-24T19:19:47.035418Z", |
| 9 | + "start_time": "2019-03-24T19:19:46.989260Z" |
10 | 10 | }
|
11 | 11 | },
|
12 | 12 | "outputs": [],
|
13 | 13 | "source": [
|
| 14 | + "import ctypes\n", |
| 15 | + "import locale\n", |
14 | 16 | "import os\n",
|
15 | 17 | "import platform\n",
|
| 18 | + "from ctypes.util import find_library\n", |
16 | 19 | "\n",
|
17 | 20 | "import cffi\n",
|
18 | 21 | "from PIL import Image, ImageDraw, ImageFont"
|
|
23 | 26 | "execution_count": 2,
|
24 | 27 | "metadata": {
|
25 | 28 | "ExecuteTime": {
|
26 |
| - "end_time": "2019-03-23T12:57:29.331915Z", |
27 |
| - "start_time": "2019-03-23T12:57:28.951892Z" |
| 29 | + "end_time": "2019-03-24T19:19:48.504555Z", |
| 30 | + "start_time": "2019-03-24T19:19:48.097205Z" |
28 | 31 | }
|
29 | 32 | },
|
30 | 33 | "outputs": [],
|
|
41 | 44 | "execution_count": 3,
|
42 | 45 | "metadata": {
|
43 | 46 | "ExecuteTime": {
|
44 |
| - "end_time": "2019-03-23T12:57:30.073874Z", |
45 |
| - "start_time": "2019-03-23T12:57:29.961576Z" |
| 47 | + "end_time": "2019-03-24T19:19:49.435764Z", |
| 48 | + "start_time": "2019-03-24T19:19:49.428745Z" |
| 49 | + } |
| 50 | + }, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "def get_abs_path_of_library(library):\n", |
| 54 | + " \"\"\"Get absolute path of library.\"\"\"\n", |
| 55 | + " abs_path = None\n", |
| 56 | + " lib_name = find_library(library)\n", |
| 57 | + " if os.path.exists(lib_name):\n", |
| 58 | + " abs_path = os.path.abspath(lib_name)\n", |
| 59 | + " return abs_path\n", |
| 60 | + " libdl = ctypes.CDLL(lib_name)\n", |
| 61 | + " if not libdl:\n", |
| 62 | + " return abs_path # None\n", |
| 63 | + " try:\n", |
| 64 | + " dlinfo = libdl.dlinfos\n", |
| 65 | + " except AttributeError as err:\n", |
| 66 | + " # Workaroung for linux\n", |
| 67 | + " abs_path = str(err).split(\":\")[0]\n", |
| 68 | + " return abs_path" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": 4, |
| 74 | + "metadata": { |
| 75 | + "ExecuteTime": { |
| 76 | + "end_time": "2019-03-24T19:19:51.359887Z", |
| 77 | + "start_time": "2019-03-24T19:19:51.212488Z" |
46 | 78 | }
|
47 | 79 | },
|
48 | 80 | "outputs": [],
|
|
173 | 205 | },
|
174 | 206 | {
|
175 | 207 | "cell_type": "code",
|
176 |
| - "execution_count": 4, |
| 208 | + "execution_count": 5, |
177 | 209 | "metadata": {
|
178 | 210 | "ExecuteTime": {
|
179 |
| - "end_time": "2019-03-23T12:57:30.832997Z", |
180 |
| - "start_time": "2019-03-23T12:57:30.821967Z" |
| 211 | + "end_time": "2019-03-24T19:19:52.516956Z", |
| 212 | + "start_time": "2019-03-24T19:19:52.507932Z" |
181 | 213 | }
|
182 | 214 | },
|
183 | 215 | "outputs": [],
|
|
211 | 243 | },
|
212 | 244 | {
|
213 | 245 | "cell_type": "code",
|
214 |
| - "execution_count": 5, |
| 246 | + "execution_count": 7, |
215 | 247 | "metadata": {
|
216 | 248 | "ExecuteTime": {
|
217 |
| - "end_time": "2019-03-23T12:57:31.655190Z", |
218 |
| - "start_time": "2019-03-23T12:57:31.646162Z" |
| 249 | + "end_time": "2019-03-24T19:20:28.472550Z", |
| 250 | + "start_time": "2019-03-24T19:20:28.461520Z" |
219 | 251 | }
|
220 | 252 | },
|
221 | 253 | "outputs": [],
|
|
225 | 257 | "dll_dir = \"\"\n",
|
226 | 258 | "if platform.architecture()[1].lower().startswith('windows'):\n",
|
227 | 259 | " dll_dir = \"win\"\n",
|
| 260 | + " if platform.architecture()[0] == '64bit':\n", |
| 261 | + " dll_dir += \"64\"\n", |
| 262 | + " elif platform.architecture()[0] == '32bit':\n", |
| 263 | + " dll_dir += \"32\"\n", |
| 264 | + " abs_path = os.path.join(os.getcwd(), dll_dir)\n", |
228 | 265 | "\n",
|
229 |
| - "if platform.architecture()[0] == '64bit':\n", |
230 |
| - " dll_dir += \"64\"\n", |
231 |
| - "# dll_dir += \"64\"\n", |
232 |
| - "elif platform.architecture()[0] == '32bit':\n", |
233 |
| - " dll_dir += \"32\"\n", |
234 |
| - "\n", |
235 |
| - "abs_path = os.path.join(os.getcwd(), dll_dir)\n", |
236 |
| - "\n", |
237 |
| - "env_path = os.environ['PATH']\n", |
238 |
| - "if abs_path not in env_path:\n", |
239 |
| - " os.environ['PATH'] = abs_path + \";\" + env_path\n", |
240 |
| - "tess_libname = os.path.join(abs_path, \"tesseract41.dll\")\n", |
241 |
| - "lept_libname = os.path.join(abs_path, \"leptonica-1.78.0.dll\")\n", |
| 266 | + " env_path = os.environ['PATH']\n", |
| 267 | + " if abs_path not in env_path:\n", |
| 268 | + " os.environ['PATH'] = abs_path + \";\" + env_path\n", |
| 269 | + " tess_libname = os.path.join(abs_path, \"tesseract41.dll\")\n", |
| 270 | + " lept_libname = os.path.join(abs_path, \"leptonica-1.78.0.dll\")\n", |
| 271 | + "else:\n", |
| 272 | + " tess_libname = get_abs_path_of_library('tesseract')\n", |
| 273 | + " lept_libname = get_abs_path_of_library('lept')\n", |
242 | 274 | "\n",
|
243 | 275 | "# Use project tessdata\n",
|
244 | 276 | "tessdata = os.path.join(os.getcwd(), \"tessdata\")\n",
|
|
247 | 279 | },
|
248 | 280 | {
|
249 | 281 | "cell_type": "code",
|
250 |
| - "execution_count": 6, |
| 282 | + "execution_count": 8, |
251 | 283 | "metadata": {
|
252 | 284 | "ExecuteTime": {
|
253 |
| - "end_time": "2019-03-23T12:57:32.405182Z", |
254 |
| - "start_time": "2019-03-23T12:57:32.382116Z" |
| 285 | + "end_time": "2019-03-24T19:20:34.971855Z", |
| 286 | + "start_time": "2019-03-24T19:20:31.138664Z" |
255 | 287 | }
|
256 | 288 | },
|
257 | 289 | "outputs": [
|
|
284 | 316 | },
|
285 | 317 | {
|
286 | 318 | "cell_type": "code",
|
287 |
| - "execution_count": 7, |
288 |
| - "metadata": { |
289 |
| - "ExecuteTime": { |
290 |
| - "end_time": "2019-03-23T12:57:33.259451Z", |
291 |
| - "start_time": "2019-03-23T12:57:33.254435Z" |
292 |
| - } |
293 |
| - }, |
294 |
| - "outputs": [], |
295 |
| - "source": [ |
296 |
| - "# Create tesseract API\n", |
297 |
| - "if api:\n", |
298 |
| - " tesseract.TessBaseAPIEnd(api)\n", |
299 |
| - " tesseract.TessBaseAPIDelete(api)\n", |
300 |
| - "api = tesseract.TessBaseAPICreate()" |
301 |
| - ] |
302 |
| - }, |
303 |
| - { |
304 |
| - "cell_type": "code", |
305 |
| - "execution_count": 8, |
| 319 | + "execution_count": 9, |
306 | 320 | "metadata": {
|
307 | 321 | "ExecuteTime": {
|
308 |
| - "end_time": "2019-03-23T12:57:33.956304Z", |
309 |
| - "start_time": "2019-03-23T12:57:33.902158Z" |
| 322 | + "end_time": "2019-03-24T19:20:51.661233Z", |
| 323 | + "start_time": "2019-03-24T19:20:51.292247Z" |
310 | 324 | }
|
311 | 325 | },
|
312 | 326 | "outputs": [
|
|
331 | 345 | "print(f\"Image {filename} has {x_dpi[0]}x{y_dpi[0]} DPI.\")"
|
332 | 346 | ]
|
333 | 347 | },
|
| 348 | + { |
| 349 | + "cell_type": "code", |
| 350 | + "execution_count": 7, |
| 351 | + "metadata": { |
| 352 | + "ExecuteTime": { |
| 353 | + "end_time": "2019-03-23T12:57:33.259451Z", |
| 354 | + "start_time": "2019-03-23T12:57:33.254435Z" |
| 355 | + } |
| 356 | + }, |
| 357 | + "outputs": [], |
| 358 | + "source": [ |
| 359 | + "# Create tesseract API\n", |
| 360 | + "if api:\n", |
| 361 | + " tesseract.TessBaseAPIEnd(api)\n", |
| 362 | + " tesseract.TessBaseAPIDelete(api)\n", |
| 363 | + "api = tesseract.TessBaseAPICreate()" |
| 364 | + ] |
| 365 | + }, |
334 | 366 | {
|
335 | 367 | "cell_type": "code",
|
336 | 368 | "execution_count": 9,
|
|
0 commit comments