yomitoku 0.9.2__py3-none-any.whl → 0.9.3__py3-none-any.whl
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.
- yomitoku/cli/main.py +39 -15
- yomitoku/constants.py +1 -1
- yomitoku/utils/searchable_pdf.py +6 -3
- {yomitoku-0.9.2.dist-info → yomitoku-0.9.3.dist-info}/METADATA +2 -3
- {yomitoku-0.9.2.dist-info → yomitoku-0.9.3.dist-info}/RECORD +7 -7
- {yomitoku-0.9.2.dist-info → yomitoku-0.9.3.dist-info}/WHEEL +0 -0
- {yomitoku-0.9.2.dist-info → yomitoku-0.9.3.dist-info}/entry_points.txt +0 -0
yomitoku/cli/main.py
CHANGED
@@ -49,10 +49,15 @@ def merge_all_pages(results):
|
|
49
49
|
else:
|
50
50
|
out += "\n" + data
|
51
51
|
|
52
|
+
elif format == "pdf":
|
53
|
+
if out is None:
|
54
|
+
out = [data]
|
55
|
+
else:
|
56
|
+
out.append(data)
|
52
57
|
return out
|
53
58
|
|
54
59
|
|
55
|
-
def save_merged_file(out_path, args, out):
|
60
|
+
def save_merged_file(out_path, args, out, imgs):
|
56
61
|
if args.format == "json":
|
57
62
|
save_json(out, out_path, args.encoding)
|
58
63
|
elif args.format == "csv":
|
@@ -61,6 +66,13 @@ def save_merged_file(out_path, args, out):
|
|
61
66
|
save_html(out, out_path, args.encoding)
|
62
67
|
elif args.format == "md":
|
63
68
|
save_markdown(out, out_path, args.encoding)
|
69
|
+
elif args.format == "pdf":
|
70
|
+
create_searchable_pdf(
|
71
|
+
imgs,
|
72
|
+
out,
|
73
|
+
output_path=out_path,
|
74
|
+
font_path=args.font_path,
|
75
|
+
)
|
64
76
|
|
65
77
|
|
66
78
|
def validate_encoding(encoding):
|
@@ -82,12 +94,10 @@ def process_single_file(args, analyzer, path, format):
|
|
82
94
|
imgs = load_image(path)
|
83
95
|
|
84
96
|
format_results = []
|
85
|
-
results = []
|
86
97
|
for page, img in enumerate(imgs):
|
87
98
|
result, ocr, layout = analyzer(img)
|
88
99
|
dirname = path.parent.name
|
89
100
|
filename = path.stem
|
90
|
-
results.append(result)
|
91
101
|
|
92
102
|
# cv2.imwrite(
|
93
103
|
# os.path.join(args.outdir, f"{dirname}_{filename}_p{page+1}.jpg"), img
|
@@ -228,6 +238,21 @@ def process_single_file(args, analyzer, path, format):
|
|
228
238
|
"data": md,
|
229
239
|
}
|
230
240
|
)
|
241
|
+
elif format == "pdf":
|
242
|
+
if not args.combine:
|
243
|
+
create_searchable_pdf(
|
244
|
+
[img],
|
245
|
+
[result],
|
246
|
+
output_path=out_path,
|
247
|
+
font_path=args.font_path,
|
248
|
+
)
|
249
|
+
|
250
|
+
format_results.append(
|
251
|
+
{
|
252
|
+
"format": format,
|
253
|
+
"data": result,
|
254
|
+
}
|
255
|
+
)
|
231
256
|
|
232
257
|
out = merge_all_pages(format_results)
|
233
258
|
if args.combine:
|
@@ -236,16 +261,8 @@ def process_single_file(args, analyzer, path, format):
|
|
236
261
|
out_path,
|
237
262
|
args,
|
238
263
|
out,
|
239
|
-
)
|
240
|
-
|
241
|
-
if args.searchable_pdf:
|
242
|
-
pdf_path = os.path.join(args.outdir, f"{filename}.pdf")
|
243
|
-
create_searchable_pdf(
|
244
264
|
imgs,
|
245
|
-
results,
|
246
|
-
output_path=pdf_path,
|
247
265
|
)
|
248
|
-
logger.info(f"Output SearchablePDF: {pdf_path}")
|
249
266
|
|
250
267
|
|
251
268
|
def main():
|
@@ -362,11 +379,11 @@ def main():
|
|
362
379
|
choices=["auto", "left2right", "top2bottom", "right2left"],
|
363
380
|
)
|
364
381
|
parser.add_argument(
|
365
|
-
"--
|
366
|
-
|
367
|
-
|
382
|
+
"--font_path",
|
383
|
+
default=None,
|
384
|
+
type=str,
|
385
|
+
help="Path to the font file(.ttf) for PDF output",
|
368
386
|
)
|
369
|
-
|
370
387
|
args = parser.parse_args()
|
371
388
|
|
372
389
|
path = Path(args.arg1)
|
@@ -379,6 +396,13 @@ def main():
|
|
379
396
|
f"Invalid output format: {args.format}. Supported formats are {SUPPORT_OUTPUT_FORMAT}"
|
380
397
|
)
|
381
398
|
|
399
|
+
if (
|
400
|
+
args.font_path is not None
|
401
|
+
and not os.path.exists(args.font_path)
|
402
|
+
and format == "pdf"
|
403
|
+
):
|
404
|
+
raise FileNotFoundError(f"Font file not found: {args.font_path}")
|
405
|
+
|
382
406
|
validate_encoding(args.encoding)
|
383
407
|
|
384
408
|
if format == "markdown":
|
yomitoku/constants.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import os
|
2
2
|
|
3
3
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
4
|
-
SUPPORT_OUTPUT_FORMAT = ["json", "csv", "html", "markdown", "md"]
|
4
|
+
SUPPORT_OUTPUT_FORMAT = ["json", "csv", "html", "markdown", "md", "pdf"]
|
5
5
|
SUPPORT_INPUT_FORMAT = ["jpg", "jpeg", "png", "bmp", "tiff", "tif", "pdf"]
|
6
6
|
MIN_IMAGE_SIZE = 32
|
7
7
|
WARNING_IMAGE_SIZE = 720
|
yomitoku/utils/searchable_pdf.py
CHANGED
@@ -14,7 +14,6 @@ import jaconv
|
|
14
14
|
from ..constants import ROOT_DIR
|
15
15
|
|
16
16
|
FONT_PATH = ROOT_DIR + "/resource/MPLUS1p-Medium.ttf"
|
17
|
-
pdfmetrics.registerFont(TTFont("MPLUS1p-Medium", FONT_PATH))
|
18
17
|
|
19
18
|
|
20
19
|
def _poly2rect(points):
|
@@ -62,7 +61,12 @@ def to_full_width(text):
|
|
62
61
|
return jaconv_text
|
63
62
|
|
64
63
|
|
65
|
-
def create_searchable_pdf(images, ocr_results, output_path):
|
64
|
+
def create_searchable_pdf(images, ocr_results, output_path, font_path=None):
|
65
|
+
if font_path is None:
|
66
|
+
font_path = FONT_PATH
|
67
|
+
|
68
|
+
pdfmetrics.registerFont(TTFont("MPLUS1p-Medium", font_path))
|
69
|
+
|
66
70
|
packet = BytesIO()
|
67
71
|
c = canvas.Canvas(packet)
|
68
72
|
|
@@ -97,7 +101,6 @@ def create_searchable_pdf(images, ocr_results, output_path):
|
|
97
101
|
|
98
102
|
c.setFont("MPLUS1p-Medium", font_size)
|
99
103
|
c.setFillColorRGB(1, 1, 1, alpha=0) # 透明
|
100
|
-
# c.setFillColorRGB(0, 0, 0)
|
101
104
|
if direction == "vertical":
|
102
105
|
base_y = h - y2 + (bbox_height - font_size)
|
103
106
|
for j, ch in enumerate(text):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: yomitoku
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.3
|
4
4
|
Summary: Yomitoku is an AI-powered document image analysis package designed specifically for the Japanese language.
|
5
5
|
Author-email: Kotaro Kinoshita <kotaro.kinoshita@mlism.com>
|
6
6
|
License: CC BY-NC-SA 4.0
|
@@ -87,7 +87,7 @@ yomitoku ${path_data} -f md -o results -v --figure --lite
|
|
87
87
|
```
|
88
88
|
|
89
89
|
- `${path_data}` 解析対象の画像が含まれたディレクトリか画像ファイルのパスを直接して指定してください。ディレクトリを対象とした場合はディレクトリのサブディレクトリ内の画像も含めて処理を実行します。
|
90
|
-
- `-f`, `--format` 出力形式のファイルフォーマットを指定します。(json, csv, html, md をサポート)
|
90
|
+
- `-f`, `--format` 出力形式のファイルフォーマットを指定します。(json, csv, html, md, pdf(searchable-pdf) をサポート)
|
91
91
|
- `-o`, `--outdir` 出力先のディレクトリ名を指定します。存在しない場合は新規で作成されます。
|
92
92
|
- `-v`, `--vis` を指定すると解析結果を可視化した画像を出力します。
|
93
93
|
- `-l`, `--lite` を指定すると軽量モデルで推論を実行します。通常より高速に推論できますが、若干、精度が低下する可能性があります。
|
@@ -98,7 +98,6 @@ yomitoku ${path_data} -f md -o results -v --figure --lite
|
|
98
98
|
- `--encoding` エクスポートする出力ファイルの文字エンコーディングを指定します。サポートされていない文字コードが含まれる場合は、その文字を無視します。(utf-8, utf-8-sig, shift-jis, enc-jp, cp932)
|
99
99
|
- `--combine` PDFを入力に与えたときに、複数ページが含まれる場合に、それらの予測結果を一つのファイルに統合してエクスポートします。
|
100
100
|
- `--ignore_meta` 文章のheater, fotterなどの文字情報を出力ファイルに含めません。
|
101
|
-
- `--searchable_pdf` 読み取った文字情報をPDFに埋め込み全文検索可能なPDFを出力します。
|
102
101
|
|
103
102
|
その他のオプションに関しては、ヘルプを参照
|
104
103
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
yomitoku/__init__.py,sha256=kXOM8RbpwwLABG3p3vPT3dJWBk4JX2MFGrOeBEW0hKM,543
|
2
2
|
yomitoku/base.py,sha256=9U3sfe69O6vuO430JzzKQQNkgPsLM9WdLfOUUhp3Ljs,3878
|
3
|
-
yomitoku/constants.py,sha256=
|
3
|
+
yomitoku/constants.py,sha256=2jya14UflDkMdYWMKc-ZllkWbJW2qh59Cnt2brrgNb4,693
|
4
4
|
yomitoku/document_analyzer.py,sha256=xliAelQdfsK64FtVuFvstDBr9uf2TwhqW31g2g91_CY,16888
|
5
5
|
yomitoku/layout_analyzer.py,sha256=VhNf1ZQFoozj6WUGk5ll1p2p1jk5X3j-JPcDbTAoSl4,1856
|
6
6
|
yomitoku/layout_parser.py,sha256=0MgbCsD90srQdsxkGEL0TgKm4rkmGzsQYx0sjKQ03yc,7718
|
@@ -10,7 +10,7 @@ yomitoku/table_structure_recognizer.py,sha256=tHjex6deT_FjRK5ePz9bUXA_QIhgv_vYtK
|
|
10
10
|
yomitoku/text_detector.py,sha256=6IwEJJKp_F8YH0Oki0QV-Mqi--P2LGbNKo-_kxBB_eo,4383
|
11
11
|
yomitoku/text_recognizer.py,sha256=eaxozNu-Ms6iv8efbKZzn8pJNW1Wo4f86bGhzSMtv3s,5992
|
12
12
|
yomitoku/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
yomitoku/cli/main.py,sha256=
|
13
|
+
yomitoku/cli/main.py,sha256=5An9usBfBYqNiBA6QqZTCaYI4b3W1j-efAsggK_HCss,13522
|
14
14
|
yomitoku/cli/mcp_server.py,sha256=WnWzxd13HaemC3b-5i9B9NVBGc3WGfum2nYhoBolEnk,5641
|
15
15
|
yomitoku/configs/__init__.py,sha256=x5-ccjGiP6xxRtDPT7f1Enl7SsE0hSk0G8f7eF9V85I,886
|
16
16
|
yomitoku/configs/cfg_layout_parser_rtdtrv2.py,sha256=8PRxB2Ar9UF7-DLtbgSokhrzdXb0veWI6Wc-X8qigRw,2329
|
@@ -51,9 +51,9 @@ yomitoku/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
51
|
yomitoku/utils/graph.py,sha256=LKNB8ZhSQwOZMfeAimPMF5UCVVr2ZaUWoGDkz8z-uGU,456
|
52
52
|
yomitoku/utils/logger.py,sha256=uOmtQDr0A0JD7wyFshedL08BiNrQorHnpktRXba8bjU,424
|
53
53
|
yomitoku/utils/misc.py,sha256=r92x45kQR8lC5jO1MZaHBDtcCWBkQXg_WS9H4RXJzSY,4127
|
54
|
-
yomitoku/utils/searchable_pdf.py,sha256=
|
54
|
+
yomitoku/utils/searchable_pdf.py,sha256=7JQCFhwpBJVV1Fx9q4p6fFGlEsJ-SmR0arddI3NzEeo,3567
|
55
55
|
yomitoku/utils/visualizer.py,sha256=DjDwHiAu1iFRKh96H3Egq4vuI2s_-9dLCDeykhKi8jo,5251
|
56
|
-
yomitoku-0.9.
|
57
|
-
yomitoku-0.9.
|
58
|
-
yomitoku-0.9.
|
59
|
-
yomitoku-0.9.
|
56
|
+
yomitoku-0.9.3.dist-info/METADATA,sha256=0r3tOl0ohoegcYQXWM3ROCSOr5px3IK-0zwqyADc9Mc,8872
|
57
|
+
yomitoku-0.9.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
58
|
+
yomitoku-0.9.3.dist-info/entry_points.txt,sha256=n3c8bQSj5Be5GHAOv_NZ8cldJFmWeigQxSmteFTmu_k,96
|
59
|
+
yomitoku-0.9.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|