-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Nikita Shevtsov <[email protected]> Co-authored-by: Nasty <[email protected]>
- Loading branch information
1 parent
e2f5553
commit d0201e5
Showing
8 changed files
with
60 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Changelog | ||
========= | ||
|
||
v0.2 (2023-08-01) | ||
------------------- | ||
* TesseractTextDetector is added | ||
|
||
v0.1 (2023-07-26) | ||
------------------- | ||
* First version of the library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1 | ||
0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .abstract_text_detector import AbstractTextDetector | ||
from .doctr_text_detector.doctr_text_detector import DoctrTextDetector | ||
from .tesseract_text_detector import TesseractTextDetector | ||
|
||
__all__ = ["AbstractTextDetector", "DoctrTextDetector"] | ||
__all__ = ["AbstractTextDetector", "DoctrTextDetector", "TesseractTextDetector"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import List, Optional | ||
|
||
import numpy as np | ||
import pytesseract | ||
|
||
from dedocutils.data_structures import BBox | ||
from dedocutils.text_detection import AbstractTextDetector | ||
|
||
|
||
class TesseractTextDetector(AbstractTextDetector): | ||
def __init__(self, config: str = "--psm 3") -> None: | ||
self.config = config | ||
|
||
def detect(self, image: np.ndarray, parameters: Optional[dict] = None) -> List[BBox]: | ||
parameters = {} if parameters is None else parameters | ||
lang = parameters.get("language", "rus+eng") | ||
|
||
data = pytesseract.image_to_data(image, lang=lang, output_type="dict", config=self.config) | ||
|
||
left, top, width, height, levels = data["left"], data["top"], data["width"], data["height"], data["level"] | ||
|
||
bboxes = [] | ||
for x, y, w, h, level in zip(left, top, width, height, levels): | ||
if level == 5: | ||
bbox = BBox(x_top_left=x, y_top_left=y, width=w, height=h) | ||
bboxes.append(bbox) | ||
|
||
return bboxes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters