ocr-stream 1.1__tar.gz → 1.2__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.
Potentially problematic release.
This version of ocr-stream might be problematic. Click here for more details.
- ocr_stream-1.2/PKG-INFO +63 -0
- ocr_stream-1.2/README.md +33 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/__init__.py +2 -4
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/__main__.py +5 -2
- ocr_stream-1.2/ocr_stream/_version.py +5 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/extractors.py +26 -26
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/models/m_modules_ocr.py +3 -2
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/modules_ocr.py +28 -23
- ocr_stream-1.2/ocr_stream.egg-info/PKG-INFO +63 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream.egg-info/requires.txt +2 -2
- {ocr_stream-1.1 → ocr_stream-1.2}/pyproject.toml +4 -3
- {ocr_stream-1.1 → ocr_stream-1.2}/setup.py +13 -21
- ocr_stream-1.1/PKG-INFO +0 -57
- ocr_stream-1.1/README.md +0 -29
- ocr_stream-1.1/ocr_stream/_version.py +0 -5
- ocr_stream-1.1/ocr_stream.egg-info/PKG-INFO +0 -57
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/models/__init__.py +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/models/m_extractors.py +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream/utils/__init__.py +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream.egg-info/SOURCES.txt +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream.egg-info/dependency_links.txt +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream.egg-info/not-zip-safe +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/ocr_stream.egg-info/top_level.txt +0 -0
- {ocr_stream-1.1 → ocr_stream-1.2}/setup.cfg +0 -0
ocr_stream-1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ocr_stream
|
|
3
|
+
Version: 1.2
|
|
4
|
+
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
|
+
Author: Bruno Chaves
|
|
6
|
+
Requires: PyPDF2
|
|
7
|
+
Requires: PyMuPDF
|
|
8
|
+
Requires: reportlab
|
|
9
|
+
Requires: openpyxl
|
|
10
|
+
Requires: openpyxl
|
|
11
|
+
Requires: pandas
|
|
12
|
+
Requires: Pillow
|
|
13
|
+
Requires: opencv_python
|
|
14
|
+
Requires: requests
|
|
15
|
+
Requires: pytesseract
|
|
16
|
+
Requires: soup_files
|
|
17
|
+
Requires: convert_stream
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: PyPDF2==3.0.1
|
|
21
|
+
Requires-Dist: PyMuPDF==1.25.5
|
|
22
|
+
Requires-Dist: reportlab==4.3.1
|
|
23
|
+
Requires-Dist: openpyxl==3.1.5
|
|
24
|
+
Requires-Dist: pandas==2.2.3
|
|
25
|
+
Requires-Dist: Pillow==11.2.1
|
|
26
|
+
Requires-Dist: opencv-python==4.11.0.86
|
|
27
|
+
Requires-Dist: convert_stream
|
|
28
|
+
Requires-Dist: soup_files
|
|
29
|
+
Dynamic: requires
|
|
30
|
+
|
|
31
|
+
# ocrlib
|
|
32
|
+
|
|
33
|
+
# Uso simples
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
from ocr_stream import File, TextRecognized, RecognizeImage, RecognizePdf
|
|
37
|
+
|
|
38
|
+
# passo 1:
|
|
39
|
+
# instânciar o objeto para reconhecer texto, utilizando o caminho do tesseract
|
|
40
|
+
|
|
41
|
+
tess: File = File('/usr/bin/tesseract') # Substitua pelo tesseract do seu sistema
|
|
42
|
+
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
43
|
+
|
|
44
|
+
# passo 2:
|
|
45
|
+
# instânciar um arquivo de imagem para extrair o texto.
|
|
46
|
+
image: File = File('path/to/file.png')
|
|
47
|
+
|
|
48
|
+
# passo 3:
|
|
49
|
+
# extrair o texto
|
|
50
|
+
text: str = ocr.image_to_string(image)
|
|
51
|
+
print(text)
|
|
52
|
+
|
|
53
|
+
# passo 4 opcional:
|
|
54
|
+
# você pode salvar um arquivo PDF com o texto extraido
|
|
55
|
+
output_file: File = File('path/to/save.pdf')
|
|
56
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
57
|
+
recognized.to_document().to_file_pdf(output_file)
|
|
58
|
+
|
|
59
|
+
# passo 5 opcional:
|
|
60
|
+
# você pode salvar uma planilha com o texto da imagem
|
|
61
|
+
output_excel: File = File('path/to/file.xlsx')
|
|
62
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
63
|
+
recognized.to_document().to_excel(output_excel)
|
ocr_stream-1.2/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# ocrlib
|
|
2
|
+
|
|
3
|
+
# Uso simples
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from ocr_stream import File, TextRecognized, RecognizeImage, RecognizePdf
|
|
7
|
+
|
|
8
|
+
# passo 1:
|
|
9
|
+
# instânciar o objeto para reconhecer texto, utilizando o caminho do tesseract
|
|
10
|
+
|
|
11
|
+
tess: File = File('/usr/bin/tesseract') # Substitua pelo tesseract do seu sistema
|
|
12
|
+
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
13
|
+
|
|
14
|
+
# passo 2:
|
|
15
|
+
# instânciar um arquivo de imagem para extrair o texto.
|
|
16
|
+
image: File = File('path/to/file.png')
|
|
17
|
+
|
|
18
|
+
# passo 3:
|
|
19
|
+
# extrair o texto
|
|
20
|
+
text: str = ocr.image_to_string(image)
|
|
21
|
+
print(text)
|
|
22
|
+
|
|
23
|
+
# passo 4 opcional:
|
|
24
|
+
# você pode salvar um arquivo PDF com o texto extraido
|
|
25
|
+
output_file: File = File('path/to/save.pdf')
|
|
26
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
27
|
+
recognized.to_document().to_file_pdf(output_file)
|
|
28
|
+
|
|
29
|
+
# passo 5 opcional:
|
|
30
|
+
# você pode salvar uma planilha com o texto da imagem
|
|
31
|
+
output_excel: File = File('path/to/file.xlsx')
|
|
32
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
33
|
+
recognized.to_document().to_excel(output_excel)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
|
|
3
|
-
from .models.m_modules_ocr import
|
|
4
|
-
LibraryOCR,
|
|
5
|
-
)
|
|
6
|
-
|
|
3
|
+
from .models.m_modules_ocr import LibraryOCR
|
|
7
4
|
from .modules_ocr import TextRecognized
|
|
5
|
+
from .utils import File, Directory, InputFiles, UserFileSystem
|
|
8
6
|
from .extractors import RecognizeImage, RecognizePdf
|
|
9
7
|
from ._version import __version__, __modify_data__
|
|
10
8
|
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
Configuração instalação:
|
|
6
6
|
------------------------------------------------------------
|
|
7
7
|
$ pip3 install -r requirements.txt
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
10
9
|
------------------------------------------------------------
|
|
11
10
|
Referências:
|
|
12
11
|
------------------------------------------------------------
|
|
@@ -22,6 +21,7 @@ https://github.com/h/pytesseract
|
|
|
22
21
|
pyocr
|
|
23
22
|
https://gitlab.gnome.org/World/OpenPaperwork/pyocr
|
|
24
23
|
"""
|
|
24
|
+
|
|
25
25
|
import sys, os
|
|
26
26
|
this_file = os.path.abspath(os.path.relpath(__file__))
|
|
27
27
|
dir_of_project = os.path.dirname(this_file)
|
|
@@ -30,14 +30,17 @@ sys.path.insert(0, dir_of_project)
|
|
|
30
30
|
from convert_stream import print_title
|
|
31
31
|
from ocr_stream import __version__, __modify_data__
|
|
32
32
|
|
|
33
|
+
|
|
33
34
|
def test():
|
|
34
35
|
# /usr/bin/tesseract
|
|
35
36
|
# /usr/share/tesseract-ocr/5/tessdata
|
|
36
37
|
pass
|
|
37
38
|
|
|
39
|
+
|
|
38
40
|
def main():
|
|
39
41
|
print_title(f' ocrlib Versão: {__version__} | Atualização: {__modify_data__} ')
|
|
40
42
|
test()
|
|
41
43
|
|
|
44
|
+
|
|
42
45
|
if __name__ == '__main__':
|
|
43
46
|
main()
|
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
from __future__ import annotations
|
|
3
|
-
|
|
4
3
|
from ocr_stream.utils import (
|
|
5
|
-
File,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
DataFrame,
|
|
9
|
-
PageDocumentPdf,
|
|
10
|
-
DocumentPdf,
|
|
11
|
-
PdfStream,
|
|
12
|
-
LibraryPDF,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
from ocr_stream.models import (
|
|
16
|
-
ABCRecognizeImage,
|
|
17
|
-
LibraryOCR,
|
|
4
|
+
File, Directory, ImageObject,
|
|
5
|
+
DataFrame, PageDocumentPdf,
|
|
6
|
+
DocumentPdf, PdfStream, LibraryPDF,
|
|
18
7
|
)
|
|
19
|
-
|
|
8
|
+
from ocr_stream.models import ABCRecognizeImage, LibraryOCR
|
|
20
9
|
from ocr_stream.modules_ocr import ModuleOcr, TextRecognized
|
|
21
10
|
|
|
11
|
+
|
|
22
12
|
class RecognizeImage(ABCRecognizeImage):
|
|
23
13
|
def __init__(self, module_ocr):
|
|
24
14
|
super().__init__(module_ocr)
|
|
@@ -48,8 +38,16 @@ class RecognizeImage(ABCRecognizeImage):
|
|
|
48
38
|
raise ValueError(f'{__class__.__name__}\nUse: ImageObject() ou File(), não {type(img)}')
|
|
49
39
|
|
|
50
40
|
@classmethod
|
|
51
|
-
def create(
|
|
52
|
-
|
|
41
|
+
def create(
|
|
42
|
+
cls,
|
|
43
|
+
library_ocr = LibraryOCR.PYTESSERACT,
|
|
44
|
+
*,
|
|
45
|
+
path_tesseract,
|
|
46
|
+
lang=None,
|
|
47
|
+
tess_data_dir=None
|
|
48
|
+
) -> RecognizeImage:
|
|
49
|
+
#
|
|
50
|
+
module_ocr: ModuleOcr = ModuleOcr.create(
|
|
53
51
|
library_ocr,
|
|
54
52
|
path_tesseract=path_tesseract,
|
|
55
53
|
lang=lang,
|
|
@@ -59,8 +57,8 @@ class RecognizeImage(ABCRecognizeImage):
|
|
|
59
57
|
|
|
60
58
|
|
|
61
59
|
class RecognizePdf(object):
|
|
62
|
-
def __init__(self, recognize_image:RecognizeImage):
|
|
63
|
-
self.recognize_image:RecognizeImage = recognize_image
|
|
60
|
+
def __init__(self, recognize_image: RecognizeImage):
|
|
61
|
+
self.recognize_image: RecognizeImage = recognize_image
|
|
64
62
|
|
|
65
63
|
def recognize_page_pdf(self, page:PageDocumentPdf) -> PageDocumentPdf:
|
|
66
64
|
"""
|
|
@@ -69,27 +67,28 @@ class RecognizePdf(object):
|
|
|
69
67
|
"""
|
|
70
68
|
pdf_stream = PdfStream(library_pdf=LibraryPDF.FITZ)
|
|
71
69
|
pdf_stream.add_page(page)
|
|
72
|
-
img:ImageObject = pdf_stream.to_images()[0]
|
|
70
|
+
img: ImageObject = pdf_stream.to_images()[0]
|
|
73
71
|
text_recognized:TextRecognized = self.recognize_image.image_recognize(img)
|
|
74
72
|
return text_recognized.to_page_pdf()
|
|
75
73
|
|
|
76
74
|
def recognize_document(self, doc:DocumentPdf) -> DocumentPdf:
|
|
77
|
-
new:DocumentPdf = DocumentPdf()
|
|
75
|
+
new: DocumentPdf = DocumentPdf()
|
|
78
76
|
for page in doc.pages:
|
|
79
|
-
recognized_page:PageDocumentPdf = self.recognize_page_pdf(page)
|
|
77
|
+
recognized_page: PageDocumentPdf = self.recognize_page_pdf(page)
|
|
80
78
|
new.add_page(recognized_page)
|
|
81
79
|
return new
|
|
82
80
|
|
|
83
81
|
@classmethod
|
|
84
82
|
def create(
|
|
85
83
|
cls,
|
|
86
|
-
library_ocr=LibraryOCR.PYTESSERACT,
|
|
84
|
+
library_ocr = LibraryOCR.PYTESSERACT,
|
|
87
85
|
*,
|
|
88
|
-
path_tesseract:File,
|
|
86
|
+
path_tesseract: File,
|
|
89
87
|
lang:str=None,
|
|
90
|
-
tess_data_dir:Directory=None,
|
|
88
|
+
tess_data_dir: Directory=None,
|
|
91
89
|
) -> RecognizePdf:
|
|
92
|
-
|
|
90
|
+
#
|
|
91
|
+
#
|
|
93
92
|
recognize_image = RecognizeImage.create(
|
|
94
93
|
library_ocr,
|
|
95
94
|
path_tesseract=path_tesseract,
|
|
@@ -97,6 +96,7 @@ class RecognizePdf(object):
|
|
|
97
96
|
tess_data_dir=tess_data_dir
|
|
98
97
|
)
|
|
99
98
|
return cls(recognize_image)
|
|
99
|
+
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
|
|
@@ -31,13 +31,14 @@ class ABCTextRecognized(ABC):
|
|
|
31
31
|
pass
|
|
32
32
|
|
|
33
33
|
@abstractmethod
|
|
34
|
-
def to_dataframe(self,
|
|
34
|
+
def to_dataframe(self, separator:str='\n', column_text: str = 'TEXT') -> DataFrame:
|
|
35
35
|
pass
|
|
36
36
|
|
|
37
37
|
@abstractmethod
|
|
38
|
-
def to_dict(self) -> Dict[str, List[str]]:
|
|
38
|
+
def to_dict(self, separator:str='\n', column_text: str = 'TEXT') -> Dict[str, List[str]]:
|
|
39
39
|
pass
|
|
40
40
|
|
|
41
|
+
|
|
41
42
|
#======================================================================#
|
|
42
43
|
# Abstração para o módulo que extrai o texto das imagens (OCR)
|
|
43
44
|
# pode ser implementado com pytesseract ou outros.
|
|
@@ -5,19 +5,17 @@ from typing import List, Dict
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
import re
|
|
7
7
|
import os
|
|
8
|
-
|
|
8
|
+
from pandas import DataFrame
|
|
9
|
+
from pytesseract import pytesseract, Output
|
|
9
10
|
from ocr_stream.models import (
|
|
10
|
-
ABCModuleOcr,
|
|
11
|
-
ABCTextRecognized,
|
|
12
|
-
LibraryOCR,
|
|
11
|
+
ABCModuleOcr, ABCTextRecognized, LibraryOCR,
|
|
13
12
|
)
|
|
14
|
-
from pandas import DataFrame
|
|
15
13
|
from ocr_stream.utils import (
|
|
16
|
-
PageDocumentPdf, DocumentPdf, LibraryImage,
|
|
17
|
-
File, Directory
|
|
14
|
+
PageDocumentPdf, DocumentPdf, LibraryImage, LibraryPDF,
|
|
15
|
+
ImageObject, ArrayString, DataString, File, Directory
|
|
18
16
|
)
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
|
|
21
19
|
|
|
22
20
|
def get_temp_dir(prefix=Path().home()) -> str:
|
|
23
21
|
prefix = Path().home()
|
|
@@ -204,9 +202,12 @@ class TextRecognizedToi(object):
|
|
|
204
202
|
def line_roteiro(self) -> DataString:
|
|
205
203
|
return DataString(None)
|
|
206
204
|
|
|
205
|
+
|
|
207
206
|
#======================================================================#
|
|
208
207
|
# Texto reconhecido de uma imagem.
|
|
209
208
|
#======================================================================#
|
|
209
|
+
|
|
210
|
+
|
|
210
211
|
class TextRecognized(ABCTextRecognized):
|
|
211
212
|
"""
|
|
212
213
|
Recebe os bytes de uma página PDF reconhecida de imagem
|
|
@@ -215,10 +216,10 @@ class TextRecognized(ABCTextRecognized):
|
|
|
215
216
|
-> str
|
|
216
217
|
-> PageDocumentPdf()
|
|
217
218
|
"""
|
|
218
|
-
def __init__(self, bytes_recognized):
|
|
219
|
+
def __init__(self, bytes_recognized: bytes):
|
|
219
220
|
super().__init__(bytes_recognized)
|
|
220
221
|
|
|
221
|
-
self.list_bad_char:List[str] = [
|
|
222
|
+
self.list_bad_char: List[str] = [
|
|
222
223
|
':', ',', ';', '$', '=',
|
|
223
224
|
'!', '}', '{', '(', ')',
|
|
224
225
|
'|', '\\', '‘', '*'
|
|
@@ -232,33 +233,37 @@ class TextRecognized(ABCTextRecognized):
|
|
|
232
233
|
return self.to_page_pdf().to_string()
|
|
233
234
|
|
|
234
235
|
def to_page_pdf(self) -> PageDocumentPdf:
|
|
235
|
-
|
|
236
|
+
_page = PageDocumentPdf.create_from_page_bytes(
|
|
237
|
+
self.bytes_recognized,
|
|
238
|
+
library = LibraryPDF.FITZ
|
|
239
|
+
)
|
|
240
|
+
return _page
|
|
236
241
|
|
|
237
242
|
def to_document(self) -> DocumentPdf:
|
|
238
|
-
doc
|
|
239
|
-
doc.add_page(self.to_page_pdf())
|
|
243
|
+
doc = DocumentPdf(pages=self.to_page_pdf())
|
|
240
244
|
return doc
|
|
241
245
|
|
|
242
|
-
def to_dict(self, separator
|
|
246
|
+
def to_dict(self, separator = '\n', column_text = 'TEXT') -> Dict[str, List[str]]:
|
|
243
247
|
image_dict:Dict[str, List[str]] = {
|
|
244
|
-
|
|
248
|
+
column_text: [],
|
|
245
249
|
'NUM_LINHA': [],
|
|
246
250
|
}
|
|
247
251
|
image_text:str = self.to_string()
|
|
248
252
|
if (image_text is None) or (image_text == ''):
|
|
249
253
|
return {
|
|
250
|
-
|
|
254
|
+
column_text: ['nan'],
|
|
251
255
|
'NUM_LINHA': ['nan'],
|
|
252
256
|
}
|
|
253
257
|
|
|
254
|
-
image_lines:List[str] = image_text.split(separator)
|
|
258
|
+
image_lines: List[str] = image_text.split(separator)
|
|
255
259
|
for num, line in enumerate(image_lines):
|
|
256
|
-
image_dict[
|
|
260
|
+
image_dict[column_text].append(line)
|
|
257
261
|
image_dict['NUM_LINHA'].append(num+1)
|
|
258
262
|
return image_dict
|
|
259
263
|
|
|
260
|
-
def to_dataframe(self,
|
|
261
|
-
return DataFrame(self.to_dict(separator))
|
|
264
|
+
def to_dataframe(self, separator = '\n', column_text = 'TEXT') -> DataFrame:
|
|
265
|
+
return DataFrame(self.to_dict(separator, column_text))
|
|
266
|
+
|
|
262
267
|
|
|
263
268
|
#======================================================================#
|
|
264
269
|
# Modulo OCR pytesseract
|
|
@@ -381,7 +386,7 @@ class IModulePyOcr(ABCModuleOcr):
|
|
|
381
386
|
|
|
382
387
|
|
|
383
388
|
class ModuleOcr(ABCModuleOcr):
|
|
384
|
-
def __init__(self, module_ocr:ABCModuleOcr):
|
|
389
|
+
def __init__(self, module_ocr: ABCModuleOcr):
|
|
385
390
|
super().__init__(
|
|
386
391
|
cmd_executable=module_ocr.cmd_executable,
|
|
387
392
|
lang=module_ocr.lang,
|
|
@@ -389,7 +394,7 @@ class ModuleOcr(ABCModuleOcr):
|
|
|
389
394
|
)
|
|
390
395
|
self.module_ocr:ABCModuleOcr = module_ocr
|
|
391
396
|
|
|
392
|
-
def image_content_data(self, img:ImageObject) -> DataFrame:
|
|
397
|
+
def image_content_data(self, img: ImageObject) -> DataFrame:
|
|
393
398
|
return self.module_ocr.image_content_data(img)
|
|
394
399
|
|
|
395
400
|
def image_recognize(self, img:ImageObject) -> TextRecognized:
|
|
@@ -403,7 +408,7 @@ class ModuleOcr(ABCModuleOcr):
|
|
|
403
408
|
cls,
|
|
404
409
|
library_ocr = LibraryOCR.PYTESSERACT,
|
|
405
410
|
*,
|
|
406
|
-
path_tesseract,
|
|
411
|
+
path_tesseract: File,
|
|
407
412
|
lang = None,
|
|
408
413
|
tess_data_dir = None
|
|
409
414
|
) -> ModuleOcr:
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ocr_stream
|
|
3
|
+
Version: 1.2
|
|
4
|
+
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
|
+
Author: Bruno Chaves
|
|
6
|
+
Requires: PyPDF2
|
|
7
|
+
Requires: PyMuPDF
|
|
8
|
+
Requires: reportlab
|
|
9
|
+
Requires: openpyxl
|
|
10
|
+
Requires: openpyxl
|
|
11
|
+
Requires: pandas
|
|
12
|
+
Requires: Pillow
|
|
13
|
+
Requires: opencv_python
|
|
14
|
+
Requires: requests
|
|
15
|
+
Requires: pytesseract
|
|
16
|
+
Requires: soup_files
|
|
17
|
+
Requires: convert_stream
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: PyPDF2==3.0.1
|
|
21
|
+
Requires-Dist: PyMuPDF==1.25.5
|
|
22
|
+
Requires-Dist: reportlab==4.3.1
|
|
23
|
+
Requires-Dist: openpyxl==3.1.5
|
|
24
|
+
Requires-Dist: pandas==2.2.3
|
|
25
|
+
Requires-Dist: Pillow==11.2.1
|
|
26
|
+
Requires-Dist: opencv-python==4.11.0.86
|
|
27
|
+
Requires-Dist: convert_stream
|
|
28
|
+
Requires-Dist: soup_files
|
|
29
|
+
Dynamic: requires
|
|
30
|
+
|
|
31
|
+
# ocrlib
|
|
32
|
+
|
|
33
|
+
# Uso simples
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
from ocr_stream import File, TextRecognized, RecognizeImage, RecognizePdf
|
|
37
|
+
|
|
38
|
+
# passo 1:
|
|
39
|
+
# instânciar o objeto para reconhecer texto, utilizando o caminho do tesseract
|
|
40
|
+
|
|
41
|
+
tess: File = File('/usr/bin/tesseract') # Substitua pelo tesseract do seu sistema
|
|
42
|
+
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
43
|
+
|
|
44
|
+
# passo 2:
|
|
45
|
+
# instânciar um arquivo de imagem para extrair o texto.
|
|
46
|
+
image: File = File('path/to/file.png')
|
|
47
|
+
|
|
48
|
+
# passo 3:
|
|
49
|
+
# extrair o texto
|
|
50
|
+
text: str = ocr.image_to_string(image)
|
|
51
|
+
print(text)
|
|
52
|
+
|
|
53
|
+
# passo 4 opcional:
|
|
54
|
+
# você pode salvar um arquivo PDF com o texto extraido
|
|
55
|
+
output_file: File = File('path/to/save.pdf')
|
|
56
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
57
|
+
recognized.to_document().to_file_pdf(output_file)
|
|
58
|
+
|
|
59
|
+
# passo 5 opcional:
|
|
60
|
+
# você pode salvar uma planilha com o texto da imagem
|
|
61
|
+
output_excel: File = File('path/to/file.xlsx')
|
|
62
|
+
recognized: TextRecognized = ocr.image_recognize(image)
|
|
63
|
+
recognized.to_document().to_excel(output_excel)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ocr_stream"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.2"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Bruno Chaves"},
|
|
10
10
|
]
|
|
@@ -13,7 +13,6 @@ readme = "README.md"
|
|
|
13
13
|
requires-python = ">=3.11"
|
|
14
14
|
|
|
15
15
|
dependencies = [
|
|
16
|
-
"soup_files==1.0.1",
|
|
17
16
|
"PyPDF2==3.0.1",
|
|
18
17
|
"PyMuPDF==1.25.5",
|
|
19
18
|
"reportlab==4.3.1",
|
|
@@ -21,7 +20,9 @@ dependencies = [
|
|
|
21
20
|
"pandas==2.2.3",
|
|
22
21
|
"Pillow==11.2.1",
|
|
23
22
|
"opencv-python==4.11.0.86",
|
|
24
|
-
"convert_stream
|
|
23
|
+
"convert_stream",
|
|
24
|
+
"soup_files",
|
|
25
25
|
]
|
|
26
|
+
|
|
26
27
|
[tool.setuptools]
|
|
27
28
|
packages = ["ocr_stream", "ocr_stream.models", "ocr_stream.utils"]
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
|
|
3
|
-
#!/usr/bin/env python3
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
REQUERIMENTOS EXTERNOS:
|
|
8
|
-
|
|
9
|
-
pip3 install 'https://gitlab.com/bschavesbr/file-utils/-/archive/main/file-utils-main.zip'
|
|
10
|
-
pip3 install https://gitlab.com/bschaves/pdflib/-/archive/V1.0/pdflib-V1.0.zip
|
|
11
|
-
"""
|
|
12
3
|
import os
|
|
13
4
|
import sys
|
|
14
5
|
|
|
@@ -20,7 +11,6 @@ except Exception as e:
|
|
|
20
11
|
|
|
21
12
|
file_setup = os.path.abspath(os.path.realpath(__file__))
|
|
22
13
|
dir_of_project = os.path.dirname(file_setup)
|
|
23
|
-
|
|
24
14
|
sys.path.insert(0, dir_of_project)
|
|
25
15
|
|
|
26
16
|
|
|
@@ -29,21 +19,23 @@ LONG_DESCRIPTION = ''
|
|
|
29
19
|
|
|
30
20
|
setup(
|
|
31
21
|
name='ocrlib',
|
|
32
|
-
version='1.
|
|
22
|
+
version='1.2',
|
|
33
23
|
description=DESCRIPTION,
|
|
34
24
|
long_description=LONG_DESCRIPTION,
|
|
35
25
|
license='MIT',
|
|
36
26
|
requires=[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
'PyPDF2',
|
|
28
|
+
'PyMuPDF',
|
|
29
|
+
'reportlab',
|
|
30
|
+
'openpyxl',
|
|
31
|
+
'openpyxl',
|
|
32
|
+
'pandas',
|
|
33
|
+
'Pillow',
|
|
34
|
+
'opencv_python',
|
|
35
|
+
'requests',
|
|
36
|
+
'pytesseract',
|
|
37
|
+
'soup_files',
|
|
38
|
+
'convert_stream',
|
|
47
39
|
],
|
|
48
40
|
packages=['ocrlib', 'ocrlib.models', 'ocrlib.utils'],
|
|
49
41
|
zip_safe=False,
|
ocr_stream-1.1/PKG-INFO
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ocr_stream
|
|
3
|
-
Version: 1.1
|
|
4
|
-
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
|
-
Author: Bruno Chaves
|
|
6
|
-
Requires: PyPDF2
|
|
7
|
-
Requires: PyMuPDF
|
|
8
|
-
Requires: reportlab
|
|
9
|
-
Requires: openpyxl
|
|
10
|
-
Requires: openpyxl
|
|
11
|
-
Requires: pandas
|
|
12
|
-
Requires: Pillow
|
|
13
|
-
Requires: opencv_python
|
|
14
|
-
Requires: requests
|
|
15
|
-
Requires: pytesseract
|
|
16
|
-
Requires-Python: >=3.11
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
Requires-Dist: soup_files==1.0.1
|
|
19
|
-
Requires-Dist: PyPDF2==3.0.1
|
|
20
|
-
Requires-Dist: PyMuPDF==1.25.5
|
|
21
|
-
Requires-Dist: reportlab==4.3.1
|
|
22
|
-
Requires-Dist: openpyxl==3.1.5
|
|
23
|
-
Requires-Dist: pandas==2.2.3
|
|
24
|
-
Requires-Dist: Pillow==11.2.1
|
|
25
|
-
Requires-Dist: opencv-python==4.11.0.86
|
|
26
|
-
Requires-Dist: convert_stream==1.1.1
|
|
27
|
-
Dynamic: requires
|
|
28
|
-
|
|
29
|
-
# ocrlib
|
|
30
|
-
|
|
31
|
-
# Uso simples
|
|
32
|
-
|
|
33
|
-
from ocrlib.utils import File, DocumentPdf
|
|
34
|
-
from ocrlib import RecognizeImage
|
|
35
|
-
|
|
36
|
-
# passo 1 instânciar o objeto para reconhecer texto, ultilzaremos o caminho do tesseract
|
|
37
|
-
# Substitua pelo tesseract do seu sistema
|
|
38
|
-
|
|
39
|
-
tess = File('/usr/bin/tesseract')
|
|
40
|
-
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
41
|
-
|
|
42
|
-
# passo 2 instânciar um arquivo de imagem para extrair o texto.
|
|
43
|
-
image = File('path/to/file.png')
|
|
44
|
-
|
|
45
|
-
# passo 3 extrair o texto
|
|
46
|
-
text = ocr.image_to_string(image)
|
|
47
|
-
print(text)
|
|
48
|
-
|
|
49
|
-
# passo 4 opcional - você pode salvar um arquivo PDF com o texto extraido
|
|
50
|
-
output_file = File('path/to/save.pdf')
|
|
51
|
-
recognized = ocr.image_recognize(image)
|
|
52
|
-
recognized.to_document().to_file_pdf(output_file)
|
|
53
|
-
|
|
54
|
-
# passo 5 opcional - você pode salvar uma planilha com o texto da imagem
|
|
55
|
-
output_excel = File('path/to/file.xlsx')
|
|
56
|
-
recognized = ocr.image_recognize(image)
|
|
57
|
-
recognized.to_document().to_excel(output_excel)
|
ocr_stream-1.1/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# ocrlib
|
|
2
|
-
|
|
3
|
-
# Uso simples
|
|
4
|
-
|
|
5
|
-
from ocrlib.utils import File, DocumentPdf
|
|
6
|
-
from ocrlib import RecognizeImage
|
|
7
|
-
|
|
8
|
-
# passo 1 instânciar o objeto para reconhecer texto, ultilzaremos o caminho do tesseract
|
|
9
|
-
# Substitua pelo tesseract do seu sistema
|
|
10
|
-
|
|
11
|
-
tess = File('/usr/bin/tesseract')
|
|
12
|
-
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
13
|
-
|
|
14
|
-
# passo 2 instânciar um arquivo de imagem para extrair o texto.
|
|
15
|
-
image = File('path/to/file.png')
|
|
16
|
-
|
|
17
|
-
# passo 3 extrair o texto
|
|
18
|
-
text = ocr.image_to_string(image)
|
|
19
|
-
print(text)
|
|
20
|
-
|
|
21
|
-
# passo 4 opcional - você pode salvar um arquivo PDF com o texto extraido
|
|
22
|
-
output_file = File('path/to/save.pdf')
|
|
23
|
-
recognized = ocr.image_recognize(image)
|
|
24
|
-
recognized.to_document().to_file_pdf(output_file)
|
|
25
|
-
|
|
26
|
-
# passo 5 opcional - você pode salvar uma planilha com o texto da imagem
|
|
27
|
-
output_excel = File('path/to/file.xlsx')
|
|
28
|
-
recognized = ocr.image_recognize(image)
|
|
29
|
-
recognized.to_document().to_excel(output_excel)
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ocr_stream
|
|
3
|
-
Version: 1.1
|
|
4
|
-
Summary: Extrair textos de documentos digitalizados e imagens.
|
|
5
|
-
Author: Bruno Chaves
|
|
6
|
-
Requires: PyPDF2
|
|
7
|
-
Requires: PyMuPDF
|
|
8
|
-
Requires: reportlab
|
|
9
|
-
Requires: openpyxl
|
|
10
|
-
Requires: openpyxl
|
|
11
|
-
Requires: pandas
|
|
12
|
-
Requires: Pillow
|
|
13
|
-
Requires: opencv_python
|
|
14
|
-
Requires: requests
|
|
15
|
-
Requires: pytesseract
|
|
16
|
-
Requires-Python: >=3.11
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
Requires-Dist: soup_files==1.0.1
|
|
19
|
-
Requires-Dist: PyPDF2==3.0.1
|
|
20
|
-
Requires-Dist: PyMuPDF==1.25.5
|
|
21
|
-
Requires-Dist: reportlab==4.3.1
|
|
22
|
-
Requires-Dist: openpyxl==3.1.5
|
|
23
|
-
Requires-Dist: pandas==2.2.3
|
|
24
|
-
Requires-Dist: Pillow==11.2.1
|
|
25
|
-
Requires-Dist: opencv-python==4.11.0.86
|
|
26
|
-
Requires-Dist: convert_stream==1.1.1
|
|
27
|
-
Dynamic: requires
|
|
28
|
-
|
|
29
|
-
# ocrlib
|
|
30
|
-
|
|
31
|
-
# Uso simples
|
|
32
|
-
|
|
33
|
-
from ocrlib.utils import File, DocumentPdf
|
|
34
|
-
from ocrlib import RecognizeImage
|
|
35
|
-
|
|
36
|
-
# passo 1 instânciar o objeto para reconhecer texto, ultilzaremos o caminho do tesseract
|
|
37
|
-
# Substitua pelo tesseract do seu sistema
|
|
38
|
-
|
|
39
|
-
tess = File('/usr/bin/tesseract')
|
|
40
|
-
ocr = RecognizeImage.create(path_tesseract=tess)
|
|
41
|
-
|
|
42
|
-
# passo 2 instânciar um arquivo de imagem para extrair o texto.
|
|
43
|
-
image = File('path/to/file.png')
|
|
44
|
-
|
|
45
|
-
# passo 3 extrair o texto
|
|
46
|
-
text = ocr.image_to_string(image)
|
|
47
|
-
print(text)
|
|
48
|
-
|
|
49
|
-
# passo 4 opcional - você pode salvar um arquivo PDF com o texto extraido
|
|
50
|
-
output_file = File('path/to/save.pdf')
|
|
51
|
-
recognized = ocr.image_recognize(image)
|
|
52
|
-
recognized.to_document().to_file_pdf(output_file)
|
|
53
|
-
|
|
54
|
-
# passo 5 opcional - você pode salvar uma planilha com o texto da imagem
|
|
55
|
-
output_excel = File('path/to/file.xlsx')
|
|
56
|
-
recognized = ocr.image_recognize(image)
|
|
57
|
-
recognized.to_document().to_excel(output_excel)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|