ocr-stream 2.2.8__tar.gz → 2.3__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.2.8 → ocr_stream-2.3}/PKG-INFO +4 -3
- ocr_stream-2.3/ocr_stream/__init__.py +51 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream/bin_tess/__init__.py +2 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream/modules/__init__.py +2 -2
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream/ocr/__init__.py +1 -1
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream/recognize.py +7 -3
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream.egg-info/PKG-INFO +4 -3
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream.egg-info/requires.txt +3 -2
- {ocr_stream-2.2.8 → ocr_stream-2.3}/pyproject.toml +4 -3
- ocr_stream-2.2.8/ocr_stream/__init__.py +0 -5
- {ocr_stream-2.2.8 → ocr_stream-2.3}/README.md +0 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream.egg-info/SOURCES.txt +0 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream.egg-info/dependency_links.txt +0 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/ocr_stream.egg-info/top_level.txt +0 -0
- {ocr_stream-2.2.8 → ocr_stream-2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ocr_stream
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3
|
|
4
4
|
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
5
|
Author: Bruno Chaves
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -11,8 +11,9 @@ Requires-Dist: openpyxl
|
|
|
11
11
|
Requires-Dist: pandas
|
|
12
12
|
Requires-Dist: requests>=2.32.4
|
|
13
13
|
Requires-Dist: opencv-python
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
14
|
+
Requires-Dist: pytesseract
|
|
15
|
+
Requires-Dist: convert_stream>=2.3
|
|
16
|
+
Requires-Dist: soup_files>=1.4
|
|
16
17
|
|
|
17
18
|
# ocrlib
|
|
18
19
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from ocr_stream.modules import *
|
|
4
|
+
from ocr_stream.bin_tess import BinTesseract, get_path_tesseract_sys
|
|
5
|
+
from ocr_stream.ocr import TesseractOcr, TextRecognized, DEFAULT_LIB_OCR
|
|
6
|
+
from ocr_stream.recognize import RecognizeImage, RecognizePdf
|
|
7
|
+
from soup_files import File, Directory, InputFiles, LibraryDocs, CreatePbar, ProgressBarAdapter
|
|
8
|
+
from convert_stream import ImageObject, PdfStream, DocumentPdf, ConvertPdfToImages
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def read_images(
|
|
12
|
+
images: list[ImageObject], *,
|
|
13
|
+
pbar: ProgressBarAdapter = CreatePbar().get()
|
|
14
|
+
) -> DocumentPdf:
|
|
15
|
+
pbar.start()
|
|
16
|
+
print()
|
|
17
|
+
max_num = len(images)
|
|
18
|
+
pages = []
|
|
19
|
+
rec = RecognizeImage()
|
|
20
|
+
for idx, image in enumerate(images):
|
|
21
|
+
pbar.update(
|
|
22
|
+
((idx + 1) / max_num) * 100,
|
|
23
|
+
f'[OCR] {idx + 1} / {max_num}',
|
|
24
|
+
)
|
|
25
|
+
out = rec.image_recognize(image).to_page_pdf()
|
|
26
|
+
pages.append(out)
|
|
27
|
+
tmp_doc = DocumentPdf.create_from_pages(pages)
|
|
28
|
+
print()
|
|
29
|
+
pbar.stop()
|
|
30
|
+
return tmp_doc
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read_document(
|
|
34
|
+
document: DocumentPdf, *,
|
|
35
|
+
dpi: int = 300,
|
|
36
|
+
pbar: ProgressBarAdapter = CreatePbar().get()
|
|
37
|
+
) -> DocumentPdf:
|
|
38
|
+
pbar.start()
|
|
39
|
+
print()
|
|
40
|
+
convert = ConvertPdfToImages.create(document)
|
|
41
|
+
convert.set_pbar(pbar)
|
|
42
|
+
images = convert.to_images(dpi=dpi)
|
|
43
|
+
print()
|
|
44
|
+
return read_images(images, pbar=pbar)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
@@ -15,6 +15,8 @@ def __get_path_tesseract_unix() -> File | None:
|
|
|
15
15
|
def __get_path_tesseract_windows() -> File | None:
|
|
16
16
|
out = which('tesseract.exe')
|
|
17
17
|
if out is None:
|
|
18
|
+
if os.path.isfile("C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"):
|
|
19
|
+
return File("C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe")
|
|
18
20
|
return None
|
|
19
21
|
return File(out)
|
|
20
22
|
|
|
@@ -49,7 +49,7 @@ class TextRecognized(object):
|
|
|
49
49
|
return doc.to_pages()[0]
|
|
50
50
|
|
|
51
51
|
def to_document(self) -> DocumentPdf:
|
|
52
|
-
return DocumentPdf
|
|
52
|
+
return DocumentPdf(BytesIO(self.bytes_recognized))
|
|
53
53
|
|
|
54
54
|
def to_map(self, separator: str = '\n') -> MapText:
|
|
55
55
|
text = self.to_string()
|
|
@@ -59,7 +59,11 @@ class RecognizeImage(object):
|
|
|
59
59
|
"""
|
|
60
60
|
return self.image_recognize(img).to_dataframe()
|
|
61
61
|
|
|
62
|
-
def image_recognize(self, img: ImageObject | File) -> TextRecognized:
|
|
62
|
+
def image_recognize(self, img: ImageObject | File, *, land_scape: bool = False) -> TextRecognized:
|
|
63
|
+
if isinstance(img, File):
|
|
64
|
+
img = ImageObject(img)
|
|
65
|
+
if land_scape:
|
|
66
|
+
img.set_landscape()
|
|
63
67
|
rec: TextRecognized = self.module_ocr.to_reconize(img)
|
|
64
68
|
return rec
|
|
65
69
|
|
|
@@ -80,7 +84,7 @@ class RecognizePdf(object):
|
|
|
80
84
|
def set_pbar(self, p: ProgressBarAdapter):
|
|
81
85
|
self.pbar = p
|
|
82
86
|
|
|
83
|
-
def recognize_page_pdf(self, page: PageDocumentPdf, *, dpi: int =
|
|
87
|
+
def recognize_page_pdf(self, page: PageDocumentPdf, *, dpi: int = 300) -> DocumentPdf:
|
|
84
88
|
"""
|
|
85
89
|
Converte a página em Imagem, reconhece o texto com OCR e
|
|
86
90
|
retorna uma nova página com o texto reconhecido.
|
|
@@ -94,7 +98,7 @@ class RecognizePdf(object):
|
|
|
94
98
|
del img
|
|
95
99
|
return text_recognized.to_document()
|
|
96
100
|
|
|
97
|
-
def recognize_document(self, doc: DocumentPdf, *, dpi: int =
|
|
101
|
+
def recognize_document(self, doc: DocumentPdf, *, dpi: int = 300) -> DocumentPdf:
|
|
98
102
|
_pages: list[PageDocumentPdf] = []
|
|
99
103
|
_pages.clear()
|
|
100
104
|
_conv = ConvertPdfToImages.create(doc)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ocr_stream
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3
|
|
4
4
|
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
5
|
Author: Bruno Chaves
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -11,8 +11,9 @@ Requires-Dist: openpyxl
|
|
|
11
11
|
Requires-Dist: pandas
|
|
12
12
|
Requires-Dist: requests>=2.32.4
|
|
13
13
|
Requires-Dist: opencv-python
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
14
|
+
Requires-Dist: pytesseract
|
|
15
|
+
Requires-Dist: convert_stream>=2.3
|
|
16
|
+
Requires-Dist: soup_files>=1.4
|
|
16
17
|
|
|
17
18
|
# ocrlib
|
|
18
19
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ocr_stream"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Bruno Chaves"},
|
|
10
10
|
]
|
|
@@ -20,8 +20,9 @@ dependencies = [
|
|
|
20
20
|
"pandas",
|
|
21
21
|
"requests>=2.32.4",
|
|
22
22
|
"opencv-python",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"pytesseract",
|
|
24
|
+
"convert_stream>=2.3",
|
|
25
|
+
"soup_files>=1.4",
|
|
25
26
|
]
|
|
26
27
|
|
|
27
28
|
[tool.setuptools]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|