ocr-stream 2.6__tar.gz → 2.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ocr_stream
3
- Version: 2.6
3
+ Version: 2.6.1
4
4
  Summary: Extrair textos de documentos digitalizados e imagens.
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: convert-stream>=2.6
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
  """
4
- ocrlib depende de:
4
+ ocr_stream depende de:
5
5
  table_stream
6
6
  pandas
7
- convert_stream
8
7
  pytesseract
8
+ convert_stream
9
9
  """
10
10
 
11
+ # stdlib/builtin.
11
12
  from __future__ import annotations
12
13
  import os
13
14
  from shutil import which
@@ -19,8 +20,8 @@ from enum import StrEnum
19
20
  import threading
20
21
  from contextlib import contextmanager
21
22
 
23
+ # External libs.
22
24
  import pandas as pd
23
-
24
25
  from table_stream import (
25
26
  File,
26
27
  Directory,
@@ -60,15 +61,6 @@ from convert_stream import (
60
61
  MOD_CANVAS,
61
62
  )
62
63
 
63
- __version__ = "2.6"
64
-
65
-
66
- class FileTesseractNotFoundError(ValueError):
67
-
68
- def __init__(self, *args: object) -> None:
69
- super().__init__(*args)
70
-
71
-
72
64
  # ================================================================ #
73
65
  # Alias para variáveis e tipos de dados
74
66
  # ================================================================ #
@@ -99,6 +91,12 @@ if MOD_PYTESSERACT:
99
91
  from pytesseract import pytesseract, Output
100
92
 
101
93
 
94
+ class FileTesseractNotFoundError(ValueError):
95
+
96
+ def __init__(self, *args: object) -> None:
97
+ super().__init__(*args)
98
+
99
+
102
100
  def _get_path_tesseract_unix() -> File | None:
103
101
  out = which("tesseract")
104
102
  if out is None:
@@ -340,10 +338,16 @@ class PyTesseractOcr(TesseractOcrAbstract):
340
338
 
341
339
  def __init__(self, bin_tess: BinTesseract):
342
340
  super().__init__(bin_tess)
343
- self.modTess: pytesseract = pytesseract
341
+ if not MOD_PYTESSERACT:
342
+ pytesseract = "pytesseract"
343
+ self.mod_pytess: pytesseract = pytesseract
344
+
345
+ if self.bin_tess.exists() and MOD_PYTESSERACT:
346
+ self.mod_pytess.tesseract_cmd = self.bin_tess.get_tesseract().absolute()
344
347
 
345
- if self.bin_tess.exists():
346
- self.modTess.tesseract_cmd = self.bin_tess.get_tesseract().absolute()
348
+ def check_mod(self):
349
+ if not MOD_PYTESSERACT:
350
+ raise ModuleNotFoundError(f"Instale o pytesseract para prosseguir.")
347
351
 
348
352
  def _get_tess_dir_config(self) -> str:
349
353
  """
@@ -355,7 +359,7 @@ class PyTesseractOcr(TesseractOcrAbstract):
355
359
 
356
360
  It's important to add double quotes around the dir path.
357
361
  """
358
-
362
+ self.check_mod()
359
363
  # Caminho para os dados de idioma, por, eng etc...
360
364
  # os.environ["TESSDATA_PREFIX"] = self.tess_data_dir.absolute()
361
365
  if self.tess_data_dir is None:
@@ -365,34 +369,40 @@ class PyTesseractOcr(TesseractOcrAbstract):
365
369
  return r'--tessdata-dir "{}"'.format(self.tess_data_dir)
366
370
 
367
371
  def to_string(self, img: ImageElement) -> str:
372
+ self.check_mod()
373
+
368
374
  if not self.bin_tess.exists():
369
375
  raise FileTesseractNotFoundError("Instale o tesseract-ocr para prosseguir!")
370
376
 
371
377
  _im = img.to_opencv()
372
378
 
373
379
  if self.lang is None:
374
- return self.modTess.image_to_string(_im, config=self._get_tess_dir_config())
380
+ return self.mod_pytess.image_to_string(
381
+ _im, config=self._get_tess_dir_config()
382
+ )
375
383
  else:
376
- return self.modTess.image_to_string(
384
+ return self.mod_pytess.image_to_string(
377
385
  _im, lang=self.lang, config=self._get_tess_dir_config()
378
386
  )
379
387
 
380
388
  def to_reconize(self, img: ImageElement) -> OcrBytesRecognized:
389
+ self.check_mod()
381
390
  if not self.bin_tess.exists():
382
391
  raise FileTesseractNotFoundError("Instale o tesseract-ocr para prosseguir!")
383
392
 
384
393
  _im = img.to_opencv()
385
394
 
386
- bt = self.modTess.image_to_pdf_or_hocr(
395
+ bt = self.mod_pytess.image_to_pdf_or_hocr(
387
396
  _im, lang=self.lang, config=self._get_tess_dir_config()
388
397
  )
389
398
  return OcrBytesRecognized(bt)
390
399
 
391
400
  def recognize_file_image(self, f: File) -> textOcr:
401
+ self.check_mod()
392
402
  if not self.bin_tess.exists():
393
403
  raise FileTesseractNotFoundError("Instale o tesseract-ocr para prosseguir!")
394
404
 
395
- txt = self.modTess.image_to_string(
405
+ txt = self.mod_pytess.image_to_string(
396
406
  f.absolute(), lang=self.lang, config=self._get_tess_dir_config()
397
407
  )
398
408
  return textOcr(txt)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ocr_stream"
7
- version = "2.6"
7
+ version = "2.6.1"
8
8
 
9
9
  description = "Extrair textos de documentos digitalizados e imagens."
10
10
  readme = "README.md"
@@ -534,7 +534,7 @@ wheels = [
534
534
 
535
535
  [[package]]
536
536
  name = "ocr-stream"
537
- version = "2.6"
537
+ version = "2.6.1"
538
538
  source = { editable = "." }
539
539
  dependencies = [
540
540
  { name = "convert-stream" },
File without changes
File without changes
File without changes