Hayk Arutyunyan commited on
Commit
01dc506
·
1 Parent(s): db05230

Replace Tesseract with EasyOCR for title only

Browse files
Files changed (3) hide show
  1. apt.txt +0 -2
  2. requirements.txt +1 -1
  3. src/ocr_utils_demo.py +12 -4
apt.txt DELETED
@@ -1,2 +0,0 @@
1
- tesseract-ocr
2
- tesseract-ocr-eng
 
 
 
requirements.txt CHANGED
@@ -10,4 +10,4 @@ gradio==3.41.2
10
  pyyaml==6.0.2
11
  openpyxl==3.1.5
12
 
13
- pytesseract==0.3.10
 
10
  pyyaml==6.0.2
11
  openpyxl==3.1.5
12
 
13
+ easyocr
src/ocr_utils_demo.py CHANGED
@@ -5,16 +5,20 @@ OCR-инструменты: pytesseract для титула и PaddleOCR для
5
  import cv2
6
  import numpy as np
7
  from paddleocr import PaddleOCR
8
- import pytesseract
9
 
10
 
 
 
 
11
  # --------------------------
12
- # OCR титула (pytesseract)
13
  # --------------------------
14
  def ocr_title(img: np.ndarray) -> str:
15
  """
16
  OCR верхней области (титул мнемосхемы).
17
  """
 
18
  if img is None or img.size == 0:
19
  return ""
20
 
@@ -28,8 +32,12 @@ def ocr_title(img: np.ndarray) -> str:
28
  15, 9
29
  )
30
 
31
- text = pytesseract.image_to_string(binary, lang="eng", config="--psm 7").strip()
32
- return text
 
 
 
 
33
 
34
 
35
  # --------------------------
 
5
  import cv2
6
  import numpy as np
7
  from paddleocr import PaddleOCR
8
+ import easyocr
9
 
10
 
11
+ # Инициализация EasyOCR
12
+ _reader_title = easyocr.Reader(['en'], gpu=False)
13
+
14
  # --------------------------
15
+ # OCR титула (EasyOCR)
16
  # --------------------------
17
  def ocr_title(img: np.ndarray) -> str:
18
  """
19
  OCR верхней области (титул мнемосхемы).
20
  """
21
+
22
  if img is None or img.size == 0:
23
  return ""
24
 
 
32
  15, 9
33
  )
34
 
35
+ results = _reader_title.readtext(binary, detail=0, paragraph=False)
36
+
37
+ if not results:
38
+ return "Титул не оцифрован"
39
+
40
+ return results[0].strip()
41
 
42
 
43
  # --------------------------