-
Notifications
You must be signed in to change notification settings - Fork 194
/
test_table_ocr.py
44 lines (37 loc) · 1.14 KB
/
test_table_ocr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding: utf-8
import pytest
import os
from pix2text.ocr_engine import prepare_ocr_engine
from pix2text.table_ocr import TableOCR
def test_recognize():
image_path = 'docs/examples/table3.jpg'
os.environ['HF_ENDPOINT'] = os.getenv('HF_ENDPOINT', 'https://hf-mirror.com')
languages = ('en', 'ch_sim')
text_ocr = prepare_ocr_engine(languages, {})
ocr = TableOCR(text_ocr=text_ocr)
result = ocr.recognize(
image_path,
out_csv=True,
out_cells=True,
out_objects=False,
out_html=True,
out_markdown=True,
save_analysis_res='out-table-rec.png',
)
print(result)
def test_recognize2():
image_path = 'docs/examples/table3.jpg'
os.environ['HF_ENDPOINT'] = os.getenv('HF_ENDPOINT', 'https://hf-mirror.com')
languages = ('en', 'ch_sim')
text_ocr = prepare_ocr_engine(languages, {})
ocr = TableOCR.from_config(text_ocr=text_ocr)
result = ocr.recognize(
image_path,
out_csv=True,
out_cells=True,
out_objects=False,
out_html=True,
out_markdown=True,
save_analysis_res='out-table-rec.png',
)
print(result)