ocr-stream 2.6.7__tar.gz → 2.6.9__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.
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/PKG-INFO +2 -2
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/ocr_stream/__init__.py +67 -17
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/pyproject.toml +2 -2
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/uv.lock +12 -12
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/.gitignore +0 -0
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/README.md +0 -0
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/local_build/linux.sh +0 -0
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/local_build/send.sh +0 -0
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/test.py +0 -0
- {ocr_stream-2.6.7 → ocr_stream-2.6.9}/update.sh +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ocr_stream
|
|
3
|
-
Version: 2.6.
|
|
3
|
+
Version: 2.6.9
|
|
4
4
|
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
|
-
Requires-Dist: convert-stream>=2.6.
|
|
6
|
+
Requires-Dist: convert-stream>=2.6.9
|
|
7
7
|
Requires-Dist: pytesseract==0.3.13
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ from shutil import which
|
|
|
13
13
|
from abc import abstractmethod, ABC
|
|
14
14
|
from io import BytesIO
|
|
15
15
|
from typing import TypeVar, NewType, Any, Callable, Iterable, Iterator, TYPE_CHECKING
|
|
16
|
-
from types import
|
|
16
|
+
from types import ModuleType
|
|
17
17
|
from dataclasses import dataclass, field
|
|
18
18
|
from enum import StrEnum
|
|
19
19
|
import threading
|
|
@@ -54,6 +54,7 @@ if not cs.MOD_IMG_OPENCV:
|
|
|
54
54
|
|
|
55
55
|
import cv2
|
|
56
56
|
|
|
57
|
+
|
|
57
58
|
class FileTesseractNotFoundError(ValueError):
|
|
58
59
|
|
|
59
60
|
def __init__(self, *args: object) -> None:
|
|
@@ -74,9 +75,10 @@ Output = None
|
|
|
74
75
|
if TYPE_CHECKING:
|
|
75
76
|
from pytesseract import pytesseract
|
|
76
77
|
|
|
78
|
+
|
|
77
79
|
def load_modules_ocr_stream() -> None:
|
|
78
80
|
global MOD_PYTESSERACT
|
|
79
|
-
global
|
|
81
|
+
global pytesseract, Output
|
|
80
82
|
|
|
81
83
|
# Atualiza os caches de descoberta de módulos.
|
|
82
84
|
importlib.invalidate_caches()
|
|
@@ -98,9 +100,11 @@ def load_modules_ocr_stream() -> None:
|
|
|
98
100
|
# convert_stream
|
|
99
101
|
cs.load_modules_convert_stream()
|
|
100
102
|
|
|
103
|
+
|
|
101
104
|
# Carregar módulos
|
|
102
105
|
load_modules_ocr_stream()
|
|
103
106
|
|
|
107
|
+
|
|
104
108
|
def _get_path_tesseract_unix() -> File | None:
|
|
105
109
|
out = which("tesseract")
|
|
106
110
|
if out is None:
|
|
@@ -377,10 +381,14 @@ class PyTesseractOcr(TesseractOcrAbstract):
|
|
|
377
381
|
_config = f"{self._get_tess_dir_config()} --oem 3 --psm 6"
|
|
378
382
|
|
|
379
383
|
if self.lang is None:
|
|
380
|
-
return self.modTess.image_to_string(
|
|
384
|
+
return self.modTess.image_to_string(
|
|
385
|
+
_im, config=_config
|
|
386
|
+
) # config=self._get_tess_dir_config())
|
|
381
387
|
else:
|
|
382
388
|
return self.modTess.image_to_string(
|
|
383
|
-
_im,
|
|
389
|
+
_im,
|
|
390
|
+
lang=self.lang,
|
|
391
|
+
config=_config, # config=self._get_tess_dir_config()
|
|
384
392
|
)
|
|
385
393
|
|
|
386
394
|
def to_reconize(self, img: cs.ImageElement) -> OcrBytesRecognized:
|
|
@@ -893,6 +901,7 @@ class ReplaceByHashMerge(MergeStrategy):
|
|
|
893
901
|
.reset_index(drop=True)
|
|
894
902
|
)
|
|
895
903
|
|
|
904
|
+
|
|
896
905
|
# ====================================================================#
|
|
897
906
|
# Processamento de imagem antes de enviar ao Tesseract.
|
|
898
907
|
# ====================================================================#
|
|
@@ -901,7 +910,15 @@ class ReplaceByHashMerge(MergeStrategy):
|
|
|
901
910
|
class OcrContrastPreprocessor(cs.ImagePreprocessor):
|
|
902
911
|
"""Realça o contraste e a nitidez dos caracteres para OCR."""
|
|
903
912
|
|
|
904
|
-
def __init__(
|
|
913
|
+
def __init__(
|
|
914
|
+
self,
|
|
915
|
+
*,
|
|
916
|
+
scale: float = 2.0,
|
|
917
|
+
clip_limit: float = 2.5,
|
|
918
|
+
sharpen_amount: float = 1.5,
|
|
919
|
+
sharpen_sigma: float = 1.2,
|
|
920
|
+
binary: bool = False,
|
|
921
|
+
) -> None:
|
|
905
922
|
super().__init__()
|
|
906
923
|
if scale <= 0 or clip_limit <= 0 or sharpen_sigma <= 0:
|
|
907
924
|
raise ValueError("Os parâmetros devem ser maiores que zero.")
|
|
@@ -915,24 +932,41 @@ class OcrContrastPreprocessor(cs.ImagePreprocessor):
|
|
|
915
932
|
cs._require_opencv()
|
|
916
933
|
|
|
917
934
|
image: np.ndarray = img.to_opencv()
|
|
918
|
-
gray: np.ndarray =
|
|
935
|
+
gray: np.ndarray = (
|
|
936
|
+
cs.cv2.cvtColor(image, cs.cv2.COLOR_BGR2GRAY)
|
|
937
|
+
if image.ndim == 3
|
|
938
|
+
else image.copy()
|
|
939
|
+
)
|
|
919
940
|
|
|
920
|
-
enlarged: np.ndarray = cs.cv2.resize(
|
|
941
|
+
enlarged: np.ndarray = cs.cv2.resize(
|
|
942
|
+
gray, None, fx=self.scale, fy=self.scale, interpolation=cs.cv2.INTER_CUBIC
|
|
943
|
+
)
|
|
921
944
|
|
|
922
945
|
clahe = cs.cv2.createCLAHE(clipLimit=self.clip_limit, tileGridSize=(8, 8))
|
|
923
946
|
enhanced: np.ndarray = clahe.apply(enlarged)
|
|
924
947
|
|
|
925
948
|
blurred: np.ndarray = cs.cv2.GaussianBlur(enhanced, (0, 0), self.sharpen_sigma)
|
|
926
|
-
sharpened: np.ndarray = cs.cv2.addWeighted(
|
|
949
|
+
sharpened: np.ndarray = cs.cv2.addWeighted(
|
|
950
|
+
enhanced, self.sharpen_amount, blurred, 1.0 - self.sharpen_amount, 0
|
|
951
|
+
)
|
|
927
952
|
|
|
928
953
|
if self.binary:
|
|
929
|
-
sharpened = cs.cv2.adaptiveThreshold(
|
|
954
|
+
sharpened = cs.cv2.adaptiveThreshold(
|
|
955
|
+
sharpened,
|
|
956
|
+
255,
|
|
957
|
+
cs.cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
|
|
958
|
+
cs.cv2.THRESH_BINARY,
|
|
959
|
+
35,
|
|
960
|
+
11,
|
|
961
|
+
)
|
|
930
962
|
|
|
931
963
|
success, buffer = cs.cv2.imencode(".png", sharpened)
|
|
932
964
|
if not success:
|
|
933
965
|
raise ValueError("Falha ao codificar a imagem processada.")
|
|
934
966
|
|
|
935
|
-
return cs.ImageElement.create_from_bytes(
|
|
967
|
+
return cs.ImageElement.create_from_bytes(
|
|
968
|
+
BytesIO(buffer.tobytes()), lib_image=cs.LibImage.OPENCV
|
|
969
|
+
)
|
|
936
970
|
|
|
937
971
|
def process_binary(self, img: cs.ImageElement) -> cs.ImageElement:
|
|
938
972
|
"""Gera uma imagem binarizada com texto escuro e fundo branco."""
|
|
@@ -940,24 +974,40 @@ class OcrContrastPreprocessor(cs.ImagePreprocessor):
|
|
|
940
974
|
cs._require_opencv()
|
|
941
975
|
|
|
942
976
|
image: np.ndarray = img.to_opencv()
|
|
943
|
-
gray: np.ndarray =
|
|
977
|
+
gray: np.ndarray = (
|
|
978
|
+
cs.cv2.cvtColor(image, cs.cv2.COLOR_BGR2GRAY)
|
|
979
|
+
if image.ndim == 3
|
|
980
|
+
else image.copy()
|
|
981
|
+
)
|
|
944
982
|
|
|
945
|
-
enlarged: np.ndarray = cs.cv2.resize(
|
|
983
|
+
enlarged: np.ndarray = cs.cv2.resize(
|
|
984
|
+
gray, None, fx=self.scale, fy=self.scale, interpolation=cs.cv2.INTER_CUBIC
|
|
985
|
+
)
|
|
946
986
|
|
|
947
987
|
clahe = cs.cv2.createCLAHE(clipLimit=self.clip_limit, tileGridSize=(8, 8))
|
|
948
988
|
enhanced: np.ndarray = clahe.apply(enlarged)
|
|
949
989
|
|
|
950
990
|
blurred: np.ndarray = cs.cv2.GaussianBlur(enhanced, (0, 0), self.sharpen_sigma)
|
|
951
|
-
sharpened: np.ndarray = cs.cv2.addWeighted(
|
|
991
|
+
sharpened: np.ndarray = cs.cv2.addWeighted(
|
|
992
|
+
enhanced, self.sharpen_amount, blurred, 1.0 - self.sharpen_amount, 0
|
|
993
|
+
)
|
|
952
994
|
|
|
953
|
-
binary: np.ndarray = cs.cv2.adaptiveThreshold(
|
|
954
|
-
|
|
995
|
+
binary: np.ndarray = cs.cv2.adaptiveThreshold(
|
|
996
|
+
sharpened,
|
|
997
|
+
255,
|
|
998
|
+
cs.cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
|
|
999
|
+
cs.cv2.THRESH_BINARY,
|
|
1000
|
+
35,
|
|
1001
|
+
11,
|
|
1002
|
+
)
|
|
955
1003
|
|
|
956
1004
|
success, buffer = cs.cv2.imencode(".png", binary)
|
|
957
1005
|
if not success:
|
|
958
1006
|
raise ValueError("Falha ao codificar a imagem binarizada.")
|
|
959
1007
|
|
|
960
|
-
return cs.ImageElement.create_from_bytes(
|
|
1008
|
+
return cs.ImageElement.create_from_bytes(
|
|
1009
|
+
BytesIO(buffer.tobytes()), lib_image=cs.LibImage.OPENCV
|
|
1010
|
+
)
|
|
961
1011
|
|
|
962
1012
|
|
|
963
1013
|
# ====================================================================#
|
|
@@ -1398,7 +1448,7 @@ class ReadOcrState(StateValue[TableData[HeaderOcr]]):
|
|
|
1398
1448
|
"""Retrato do último progresso (compatibilidade com a API antiga)."""
|
|
1399
1449
|
|
|
1400
1450
|
def __init__(self, on_finish: Callable[[StateValue], Any] = None) -> None:
|
|
1401
|
-
super().__init__(on_finish)
|
|
1451
|
+
super().__init__(on_finish=on_finish)
|
|
1402
1452
|
self.current_element: str | None = None
|
|
1403
1453
|
self.current_element_num: int = 0
|
|
1404
1454
|
self.final_element_num: int = 0
|
|
@@ -4,14 +4,14 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ocr_stream"
|
|
7
|
-
version = "2.6.
|
|
7
|
+
version = "2.6.9"
|
|
8
8
|
|
|
9
9
|
description = "Extrair textos de documentos digitalizados e imagens."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.12"
|
|
12
12
|
|
|
13
13
|
dependencies = [
|
|
14
|
-
"convert-stream>=2.6.
|
|
14
|
+
"convert-stream>=2.6.9",
|
|
15
15
|
"pytesseract==0.3.13",
|
|
16
16
|
]
|
|
17
17
|
|
|
@@ -38,7 +38,7 @@ name = "cffi"
|
|
|
38
38
|
version = "2.1.1"
|
|
39
39
|
source = { registry = "https://pypi.org/simple" }
|
|
40
40
|
dependencies = [
|
|
41
|
-
{ name = "pycparser", marker = "implementation_name != 'PyPy'
|
|
41
|
+
{ name = "pycparser", marker = "implementation_name != 'PyPy'" },
|
|
42
42
|
]
|
|
43
43
|
sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" }
|
|
44
44
|
wheels = [
|
|
@@ -218,16 +218,16 @@ wheels = [
|
|
|
218
218
|
|
|
219
219
|
[[package]]
|
|
220
220
|
name = "convert-stream"
|
|
221
|
-
version = "2.6.
|
|
221
|
+
version = "2.6.9"
|
|
222
222
|
source = { registry = "https://pypi.org/simple" }
|
|
223
223
|
dependencies = [
|
|
224
224
|
{ name = "opencv-python" },
|
|
225
225
|
{ name = "pypdfium2" },
|
|
226
226
|
{ name = "table-stream" },
|
|
227
227
|
]
|
|
228
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
228
|
+
sdist = { url = "https://files.pythonhosted.org/packages/64/ca/b72e992ea56eff7a704c7620a95ec53d9268ee3d8b64256aadee3d3ae7bb/convert_stream-2.6.9.tar.gz", hash = "sha256:20d1343498700a1436a567968060b6214e24c4ad152884a6f4b0a44b451ec3dd", size = 67456, upload-time = "2026-12-02T02:17:00.464Z" }
|
|
229
229
|
wheels = [
|
|
230
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
230
|
+
{ url = "https://files.pythonhosted.org/packages/6d/40/1f8ef622de91786063527101d6f5e3b42369ce19933d44c78c8c54f6d118/convert_stream-2.6.9-py3-none-any.whl", hash = "sha256:63b7c220c7817538c99d397bc3b4a041ed53a450282096475dbb68fa617492f1", size = 21704, upload-time = "2026-12-02T02:16:57.803Z" },
|
|
231
231
|
]
|
|
232
232
|
|
|
233
233
|
[[package]]
|
|
@@ -235,7 +235,7 @@ name = "cryptography"
|
|
|
235
235
|
version = "50.0.2"
|
|
236
236
|
source = { registry = "https://pypi.org/simple" }
|
|
237
237
|
dependencies = [
|
|
238
|
-
{ name = "cffi", marker = "platform_python_implementation != 'PyPy'
|
|
238
|
+
{ name = "cffi", marker = "platform_python_implementation != 'PyPy'" },
|
|
239
239
|
]
|
|
240
240
|
sdist = { url = "https://files.pythonhosted.org/packages/9d/af/182eb91b0df3fe75c4d9f26fe70684569566745f6ba7e5c9c73a862c5252/cryptography-50.0.2.tar.gz", hash = "sha256:7b46165bb56eb4704e2eaaf86f3c940d19154535d9b0ca7d6d590b04060e00d5", size = 880623, upload-time = "2026-09-30T15:30:04.884Z" }
|
|
241
241
|
wheels = [
|
|
@@ -539,7 +539,7 @@ wheels = [
|
|
|
539
539
|
|
|
540
540
|
[[package]]
|
|
541
541
|
name = "ocr-stream"
|
|
542
|
-
version = "2.6.
|
|
542
|
+
version = "2.6.9"
|
|
543
543
|
source = { editable = "." }
|
|
544
544
|
dependencies = [
|
|
545
545
|
{ name = "convert-stream" },
|
|
@@ -555,7 +555,7 @@ dev = [
|
|
|
555
555
|
|
|
556
556
|
[package.metadata]
|
|
557
557
|
requires-dist = [
|
|
558
|
-
{ name = "convert-stream", specifier = ">=2.6.
|
|
558
|
+
{ name = "convert-stream", specifier = ">=2.6.9" },
|
|
559
559
|
{ name = "pytesseract", specifier = "==0.3.13" },
|
|
560
560
|
]
|
|
561
561
|
|
|
@@ -905,8 +905,8 @@ name = "secretstorage"
|
|
|
905
905
|
version = "3.5.0"
|
|
906
906
|
source = { registry = "https://pypi.org/simple" }
|
|
907
907
|
dependencies = [
|
|
908
|
-
{ name = "cryptography"
|
|
909
|
-
{ name = "jeepney"
|
|
908
|
+
{ name = "cryptography" },
|
|
909
|
+
{ name = "jeepney" },
|
|
910
910
|
]
|
|
911
911
|
sdist = { url = "https://files.pythonhosted.org/packages/1c/03/e834bcd866f2f8a49a85eaff47340affa3bfa391ee9912a952a1faa68c7b/secretstorage-3.5.0.tar.gz", hash = "sha256:f04b8e4689cbce351744d5537bf6b1329c6fc68f91fa666f60a380edddcd11be", size = 19884, upload-time = "2025-11-23T19:02:53.191Z" }
|
|
912
912
|
wheels = [
|
|
@@ -915,15 +915,15 @@ wheels = [
|
|
|
915
915
|
|
|
916
916
|
[[package]]
|
|
917
917
|
name = "table-stream"
|
|
918
|
-
version = "0.2.
|
|
918
|
+
version = "0.2.10"
|
|
919
919
|
source = { registry = "https://pypi.org/simple" }
|
|
920
920
|
dependencies = [
|
|
921
921
|
{ name = "openpyxl" },
|
|
922
922
|
{ name = "pandas" },
|
|
923
923
|
]
|
|
924
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
924
|
+
sdist = { url = "https://files.pythonhosted.org/packages/98/b1/747eb569ff04e74e2c69cbbda005e466d8d1dc1a196bd0d68ac93256fc3e/table_stream-0.2.10.tar.gz", hash = "sha256:3f8d1d1cbd54d7f09e9fcef8d64e3b0cbfa215f79f3b1d24b3a41c64926cadab", size = 23460, upload-time = "2026-11-29T02:04:46.876Z" }
|
|
925
925
|
wheels = [
|
|
926
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
926
|
+
{ url = "https://files.pythonhosted.org/packages/aa/04/6c28ca338c67068c5b3d46610a89a4a42b007356f34b45ec357f5e03791b/table_stream-0.2.10-py3-none-any.whl", hash = "sha256:c7535a8b828103295d53b8af2a90bc4ee2291c9e04f7ec52bc46782c984a3356", size = 23474, upload-time = "2026-11-29T02:04:45.664Z" },
|
|
927
927
|
]
|
|
928
928
|
|
|
929
929
|
[[package]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|