diff --git a/app.py b/app.py index 885739a6803d0555db541ef4fa470d4d634c7d56..34a8d1e91a25fd8a3df390eef6dce3e73a59a247 100644 --- a/app.py +++ b/app.py @@ -1,30 +1,50 @@ +import os +import random + import gradio as gr import numpy as np from ocr import Recognizer -with gr.Blocks() as app: +chars = [os.path.join(dn, fn) for dn, _, ff in os.walk("chars") for fn in ff] + +font = gr.themes.GoogleFont("Noto Sans") +theme = gr.themes.Soft(font=font) + +with gr.Blocks(theme=theme, title="Kana Writer") as app: recog = Recognizer("model/model.xml", "model/char_list.txt") + brush = gr.Brush(default_color="#111", default_size=15) + sketch = gr.Sketchpad( + random.choice(chars), + type="numpy", + brush=brush, + layers=False, + image_mode="RGB", + label="寫字練習", + ) + result = gr.TextArea(label="辨識結果", lines=1) + with gr.Row(): - brush = gr.Brush(default_color="#FFF", default_size=15) - sketch = gr.Sketchpad("bg.png", type="numpy", brush=brush, layers=False) - result = gr.TextArea() - check = gr.Button() + check_btn = gr.Button("辨識") + rand_btn = gr.Button("隨機") def parse_item(item): prob = item["prob"] char = item["char"] - return f"{char}: {prob}" + return f"{char}: {prob:.2%}" def do_recog(img: dict[str, np.ndarray]): - _, nbest = recog(img["composite"]) - return "\n".join(parse_item(i) for item in nbest for i in item) + img: np.ndarray = img["layers"][0] + img[img == 0] = 255 + img[img != 255] = 0 + _, nbest = recog(img) + return "\n".join(parse_item(i) for item in nbest for i in item if i["prob"] > 1e-2) - def clear(): - return "bg.png" + def rand_char(): + return random.choice(chars) - check.click(do_recog, sketch, result) - sketch.clear(clear, None, sketch) + check_btn.click(do_recog, sketch, result) + rand_btn.click(rand_char, None, sketch) app.launch() diff --git "a/chars/\343\201\202.png" "b/chars/\343\201\202.png" new file mode 100644 index 0000000000000000000000000000000000000000..8d0730ddd2a54f68c3ff1180de244933a7803a87 Binary files /dev/null and "b/chars/\343\201\202.png" differ diff --git "a/chars/\343\201\204.png" "b/chars/\343\201\204.png" new file mode 100644 index 0000000000000000000000000000000000000000..8b8cef915cf940f8f3badc8035ceb4e78dee6f7b Binary files /dev/null and "b/chars/\343\201\204.png" differ diff --git "a/chars/\343\201\206.png" "b/chars/\343\201\206.png" new file mode 100644 index 0000000000000000000000000000000000000000..2216927bb036553cd8608b9bd40af530d89b6e41 Binary files /dev/null and "b/chars/\343\201\206.png" differ diff --git "a/chars/\343\201\210.png" "b/chars/\343\201\210.png" new file mode 100644 index 0000000000000000000000000000000000000000..cc7d35ed5f89ccbbfc4c6cd1d2c3f77184b45f7e Binary files /dev/null and "b/chars/\343\201\210.png" differ diff --git "a/chars/\343\201\212.png" "b/chars/\343\201\212.png" new file mode 100644 index 0000000000000000000000000000000000000000..63e32f48c66c29c83e9c70609df39d0b47df6477 Binary files /dev/null and "b/chars/\343\201\212.png" differ diff --git "a/chars/\343\201\213.png" "b/chars/\343\201\213.png" new file mode 100644 index 0000000000000000000000000000000000000000..aecc085b09223998989918d36add70eac36be401 Binary files /dev/null and "b/chars/\343\201\213.png" differ diff --git "a/chars/\343\201\215.png" "b/chars/\343\201\215.png" new file mode 100644 index 0000000000000000000000000000000000000000..ac65d766542c5df3b4cb0dc8fde585a9b47f4022 Binary files /dev/null and "b/chars/\343\201\215.png" differ diff --git "a/chars/\343\201\217.png" "b/chars/\343\201\217.png" new file mode 100644 index 0000000000000000000000000000000000000000..b3833937a9f6db243a92de64a342a0e6f9a0cf96 Binary files /dev/null and "b/chars/\343\201\217.png" differ diff --git "a/chars/\343\201\221.png" "b/chars/\343\201\221.png" new file mode 100644 index 0000000000000000000000000000000000000000..998bb1aefba5a13f625f7d1d0b5314b1bfd3e21e Binary files /dev/null and "b/chars/\343\201\221.png" differ diff --git "a/chars/\343\201\223.png" "b/chars/\343\201\223.png" new file mode 100644 index 0000000000000000000000000000000000000000..e43914af98e81183a833208bf721306109ecd68a Binary files /dev/null and "b/chars/\343\201\223.png" differ diff --git "a/chars/\343\201\225.png" "b/chars/\343\201\225.png" new file mode 100644 index 0000000000000000000000000000000000000000..1fbc2826e8eccf7ea9eaf46557fb858730845a7a Binary files /dev/null and "b/chars/\343\201\225.png" differ diff --git "a/chars/\343\201\227.png" "b/chars/\343\201\227.png" new file mode 100644 index 0000000000000000000000000000000000000000..06ce397007a95fe4ef2f3f83ba5dd3a320641a32 Binary files /dev/null and "b/chars/\343\201\227.png" differ diff --git "a/chars/\343\201\231.png" "b/chars/\343\201\231.png" new file mode 100644 index 0000000000000000000000000000000000000000..0e0edf5c79e16e327a3581952581b93e4b1622dc Binary files /dev/null and "b/chars/\343\201\231.png" differ diff --git "a/chars/\343\201\233.png" "b/chars/\343\201\233.png" new file mode 100644 index 0000000000000000000000000000000000000000..b5a185ebe62e014dbf7aac4e5d0669854a8868c0 Binary files /dev/null and "b/chars/\343\201\233.png" differ diff --git "a/chars/\343\201\235.png" "b/chars/\343\201\235.png" new file mode 100644 index 0000000000000000000000000000000000000000..8f58803c024e61aa90efa879d0376f04d88dc717 Binary files /dev/null and "b/chars/\343\201\235.png" differ diff --git "a/chars/\343\201\237.png" "b/chars/\343\201\237.png" new file mode 100644 index 0000000000000000000000000000000000000000..49825f6ce2a1fe5dcab4cf3ade42a15e8e7ad8c6 Binary files /dev/null and "b/chars/\343\201\237.png" differ diff --git "a/chars/\343\201\241.png" "b/chars/\343\201\241.png" new file mode 100644 index 0000000000000000000000000000000000000000..201edc2a6b6f083718d5bed2f27b1805a2e73cec Binary files /dev/null and "b/chars/\343\201\241.png" differ diff --git "a/chars/\343\201\244.png" "b/chars/\343\201\244.png" new file mode 100644 index 0000000000000000000000000000000000000000..13db5786ee39c122c8ddadee1094f10b4ee0ca45 Binary files /dev/null and "b/chars/\343\201\244.png" differ diff --git "a/chars/\343\201\246.png" "b/chars/\343\201\246.png" new file mode 100644 index 0000000000000000000000000000000000000000..51734928e84acb571d722bf22e8f56c046c9c774 Binary files /dev/null and "b/chars/\343\201\246.png" differ diff --git "a/chars/\343\201\250.png" "b/chars/\343\201\250.png" new file mode 100644 index 0000000000000000000000000000000000000000..c9171f844425aba3cbacd4d6a6a31a3920e3cf59 Binary files /dev/null and "b/chars/\343\201\250.png" differ diff --git "a/chars/\343\201\252.png" "b/chars/\343\201\252.png" new file mode 100644 index 0000000000000000000000000000000000000000..fda41da47040a25c6dbd14fef336f1250d6380c4 Binary files /dev/null and "b/chars/\343\201\252.png" differ diff --git "a/chars/\343\201\253.png" "b/chars/\343\201\253.png" new file mode 100644 index 0000000000000000000000000000000000000000..208b80caa9db732572376201da9d9cea75ed80f2 Binary files /dev/null and "b/chars/\343\201\253.png" differ diff --git "a/chars/\343\201\254.png" "b/chars/\343\201\254.png" new file mode 100644 index 0000000000000000000000000000000000000000..7d30730fbab4825c48a0d29653ac29aa53c3c600 Binary files /dev/null and "b/chars/\343\201\254.png" differ diff --git "a/chars/\343\201\255.png" "b/chars/\343\201\255.png" new file mode 100644 index 0000000000000000000000000000000000000000..958f200ac147ca4821eae68de7ce0a35d16b183a Binary files /dev/null and "b/chars/\343\201\255.png" differ diff --git "a/chars/\343\201\256.png" "b/chars/\343\201\256.png" new file mode 100644 index 0000000000000000000000000000000000000000..1db512c5d7a2fe8845cfe9389efa9be3fe54ad92 Binary files /dev/null and "b/chars/\343\201\256.png" differ diff --git "a/chars/\343\201\257.png" "b/chars/\343\201\257.png" new file mode 100644 index 0000000000000000000000000000000000000000..340c59a464458e5f88584fbbe7a0a0631aaba646 Binary files /dev/null and "b/chars/\343\201\257.png" differ diff --git "a/chars/\343\201\262.png" "b/chars/\343\201\262.png" new file mode 100644 index 0000000000000000000000000000000000000000..e4ed9662ffb40c6c01059ae5818c599c99d0b088 Binary files /dev/null and "b/chars/\343\201\262.png" differ diff --git "a/chars/\343\201\265.png" "b/chars/\343\201\265.png" new file mode 100644 index 0000000000000000000000000000000000000000..9f84ef69dad621b5c6ce7cfde59e978dcd74170a Binary files /dev/null and "b/chars/\343\201\265.png" differ diff --git "a/chars/\343\201\270.png" "b/chars/\343\201\270.png" new file mode 100644 index 0000000000000000000000000000000000000000..6425aa87212fc5e53ae5844857773f74a9c3948f Binary files /dev/null and "b/chars/\343\201\270.png" differ diff --git "a/chars/\343\201\273.png" "b/chars/\343\201\273.png" new file mode 100644 index 0000000000000000000000000000000000000000..fe050ecc852bc1f50debff23179d74f06132af6e Binary files /dev/null and "b/chars/\343\201\273.png" differ diff --git "a/chars/\343\201\276.png" "b/chars/\343\201\276.png" new file mode 100644 index 0000000000000000000000000000000000000000..05b812319a8b0115c2aad44e5cd0f9a41f97880c Binary files /dev/null and "b/chars/\343\201\276.png" differ diff --git "a/chars/\343\201\277.png" "b/chars/\343\201\277.png" new file mode 100644 index 0000000000000000000000000000000000000000..65991ef3a70a8e1925592f70e5ec3ebf9d984095 Binary files /dev/null and "b/chars/\343\201\277.png" differ diff --git "a/chars/\343\202\200.png" "b/chars/\343\202\200.png" new file mode 100644 index 0000000000000000000000000000000000000000..f612bae6d34d8cf6f74d3830989ceb55dd2e7106 Binary files /dev/null and "b/chars/\343\202\200.png" differ diff --git "a/chars/\343\202\201.png" "b/chars/\343\202\201.png" new file mode 100644 index 0000000000000000000000000000000000000000..58263b4b834f38be75a376b74db104d16c43750d Binary files /dev/null and "b/chars/\343\202\201.png" differ diff --git "a/chars/\343\202\202.png" "b/chars/\343\202\202.png" new file mode 100644 index 0000000000000000000000000000000000000000..555d73f15a2dae3640456cb203944a05db9ecbc1 Binary files /dev/null and "b/chars/\343\202\202.png" differ diff --git "a/chars/\343\202\204.png" "b/chars/\343\202\204.png" new file mode 100644 index 0000000000000000000000000000000000000000..faece9aff62d3c46c369392dcba1d4d51ef552f1 Binary files /dev/null and "b/chars/\343\202\204.png" differ diff --git "a/chars/\343\202\206.png" "b/chars/\343\202\206.png" new file mode 100644 index 0000000000000000000000000000000000000000..890320f7b811312583dfbc673d3de0cf1587bc86 Binary files /dev/null and "b/chars/\343\202\206.png" differ diff --git "a/chars/\343\202\210.png" "b/chars/\343\202\210.png" new file mode 100644 index 0000000000000000000000000000000000000000..4b8fdb0ded27f0d7eefb0a4d64e5e5d49d731416 Binary files /dev/null and "b/chars/\343\202\210.png" differ diff --git "a/chars/\343\202\211.png" "b/chars/\343\202\211.png" new file mode 100644 index 0000000000000000000000000000000000000000..2c22697510d6f2c245c136aa291d449a29e0df92 Binary files /dev/null and "b/chars/\343\202\211.png" differ diff --git "a/chars/\343\202\212.png" "b/chars/\343\202\212.png" new file mode 100644 index 0000000000000000000000000000000000000000..69d783f931220375a25a889e3ac6042546a140f8 Binary files /dev/null and "b/chars/\343\202\212.png" differ diff --git "a/chars/\343\202\213.png" "b/chars/\343\202\213.png" new file mode 100644 index 0000000000000000000000000000000000000000..69e8858d757e6c8ae96598a09f11183e4e77f000 Binary files /dev/null and "b/chars/\343\202\213.png" differ diff --git "a/chars/\343\202\214.png" "b/chars/\343\202\214.png" new file mode 100644 index 0000000000000000000000000000000000000000..1e1f14592ad4e8ecb203bb1c514eb71da508a0f1 Binary files /dev/null and "b/chars/\343\202\214.png" differ diff --git "a/chars/\343\202\215.png" "b/chars/\343\202\215.png" new file mode 100644 index 0000000000000000000000000000000000000000..73f82100212e0c82b1f21b7c2700aecb3daf3ec0 Binary files /dev/null and "b/chars/\343\202\215.png" differ diff --git "a/chars/\343\202\217.png" "b/chars/\343\202\217.png" new file mode 100644 index 0000000000000000000000000000000000000000..934743613d968f9db185cad6e039b0d93e6435c6 Binary files /dev/null and "b/chars/\343\202\217.png" differ diff --git "a/chars/\343\202\222.png" "b/chars/\343\202\222.png" new file mode 100644 index 0000000000000000000000000000000000000000..a2e6a3e33a2d59fdc274540be86207f5f4a3fb80 Binary files /dev/null and "b/chars/\343\202\222.png" differ diff --git "a/chars/\343\202\223.png" "b/chars/\343\202\223.png" new file mode 100644 index 0000000000000000000000000000000000000000..e5d52ac3319058645c162bba496300135bdce589 Binary files /dev/null and "b/chars/\343\202\223.png" differ diff --git "a/chars/\343\202\242.png" "b/chars/\343\202\242.png" new file mode 100644 index 0000000000000000000000000000000000000000..39511d0bc1d9eded023d121486b8bbd381d44fec Binary files /dev/null and "b/chars/\343\202\242.png" differ diff --git "a/chars/\343\202\244.png" "b/chars/\343\202\244.png" new file mode 100644 index 0000000000000000000000000000000000000000..728875f465ba99cd203ca90d5d80d95d6a6b3c6e Binary files /dev/null and "b/chars/\343\202\244.png" differ diff --git "a/chars/\343\202\246.png" "b/chars/\343\202\246.png" new file mode 100644 index 0000000000000000000000000000000000000000..cfcd01e821739a45cdf9e8c280c34872cd84ea04 Binary files /dev/null and "b/chars/\343\202\246.png" differ diff --git "a/chars/\343\202\250.png" "b/chars/\343\202\250.png" new file mode 100644 index 0000000000000000000000000000000000000000..d3f3fc492da89b79bdec83a9ea18fd31da95a824 Binary files /dev/null and "b/chars/\343\202\250.png" differ diff --git "a/chars/\343\202\252.png" "b/chars/\343\202\252.png" new file mode 100644 index 0000000000000000000000000000000000000000..832e4f94823cda3d8e0d62eb4bcb2c7bcc4fb1f2 Binary files /dev/null and "b/chars/\343\202\252.png" differ diff --git "a/chars/\343\202\253.png" "b/chars/\343\202\253.png" new file mode 100644 index 0000000000000000000000000000000000000000..e2aa77c347adf2eac15fc78e19a342156f833d38 Binary files /dev/null and "b/chars/\343\202\253.png" differ diff --git "a/chars/\343\202\255.png" "b/chars/\343\202\255.png" new file mode 100644 index 0000000000000000000000000000000000000000..2459860fdd146d3d494a179b68637db1b4a8eaf2 Binary files /dev/null and "b/chars/\343\202\255.png" differ diff --git "a/chars/\343\202\257.png" "b/chars/\343\202\257.png" new file mode 100644 index 0000000000000000000000000000000000000000..fc58764a56a7d9122a61f7e8e74bbf69124970d1 Binary files /dev/null and "b/chars/\343\202\257.png" differ diff --git "a/chars/\343\202\261.png" "b/chars/\343\202\261.png" new file mode 100644 index 0000000000000000000000000000000000000000..a07fbd5bc91bb9709cc519985a9a96f1cfb681df Binary files /dev/null and "b/chars/\343\202\261.png" differ diff --git "a/chars/\343\202\263.png" "b/chars/\343\202\263.png" new file mode 100644 index 0000000000000000000000000000000000000000..351eda282710f2ebdfc604c3ddfd93b667fefebb Binary files /dev/null and "b/chars/\343\202\263.png" differ diff --git "a/chars/\343\202\265.png" "b/chars/\343\202\265.png" new file mode 100644 index 0000000000000000000000000000000000000000..0fc24556f589715e57f37e8d75801405496ac4f7 Binary files /dev/null and "b/chars/\343\202\265.png" differ diff --git "a/chars/\343\202\267.png" "b/chars/\343\202\267.png" new file mode 100644 index 0000000000000000000000000000000000000000..f01d442747ee316cc3bb9a0260fefa26e5b799ee Binary files /dev/null and "b/chars/\343\202\267.png" differ diff --git "a/chars/\343\202\271.png" "b/chars/\343\202\271.png" new file mode 100644 index 0000000000000000000000000000000000000000..24082d071f39b84911b669e1ed68587df907a51f Binary files /dev/null and "b/chars/\343\202\271.png" differ diff --git "a/chars/\343\202\273.png" "b/chars/\343\202\273.png" new file mode 100644 index 0000000000000000000000000000000000000000..54fa117792d305b75053142f21393317c46c760c Binary files /dev/null and "b/chars/\343\202\273.png" differ diff --git "a/chars/\343\202\275.png" "b/chars/\343\202\275.png" new file mode 100644 index 0000000000000000000000000000000000000000..f5aececc33b42e07feb9d9730e226c35127b111d Binary files /dev/null and "b/chars/\343\202\275.png" differ diff --git "a/chars/\343\202\277.png" "b/chars/\343\202\277.png" new file mode 100644 index 0000000000000000000000000000000000000000..a6330199820b2beac74403f17b50d2e9c9f2ffa8 Binary files /dev/null and "b/chars/\343\202\277.png" differ diff --git "a/chars/\343\203\201.png" "b/chars/\343\203\201.png" new file mode 100644 index 0000000000000000000000000000000000000000..eef283a86a663f54a42f33cdd419c7bc98e314b0 Binary files /dev/null and "b/chars/\343\203\201.png" differ diff --git "a/chars/\343\203\204.png" "b/chars/\343\203\204.png" new file mode 100644 index 0000000000000000000000000000000000000000..968895ab89832ee828c0bd548deb4b6bb1408ebf Binary files /dev/null and "b/chars/\343\203\204.png" differ diff --git "a/chars/\343\203\206.png" "b/chars/\343\203\206.png" new file mode 100644 index 0000000000000000000000000000000000000000..489af924b059f9bc7ea9abdc0361b1f8030c808c Binary files /dev/null and "b/chars/\343\203\206.png" differ diff --git "a/chars/\343\203\210.png" "b/chars/\343\203\210.png" new file mode 100644 index 0000000000000000000000000000000000000000..cad87da33594da16582e2a8e4ac4f3ffdd8c6a34 Binary files /dev/null and "b/chars/\343\203\210.png" differ diff --git "a/chars/\343\203\212.png" "b/chars/\343\203\212.png" new file mode 100644 index 0000000000000000000000000000000000000000..c4d5efd5f28d80aa8cb40551e0790beeba7c1581 Binary files /dev/null and "b/chars/\343\203\212.png" differ diff --git "a/chars/\343\203\213.png" "b/chars/\343\203\213.png" new file mode 100644 index 0000000000000000000000000000000000000000..b064a835cc8d5dec90c41fdf81047289802881c0 Binary files /dev/null and "b/chars/\343\203\213.png" differ diff --git "a/chars/\343\203\214.png" "b/chars/\343\203\214.png" new file mode 100644 index 0000000000000000000000000000000000000000..ab39504a50e270ffec954c3126b51bd22fe03f9c Binary files /dev/null and "b/chars/\343\203\214.png" differ diff --git "a/chars/\343\203\215.png" "b/chars/\343\203\215.png" new file mode 100644 index 0000000000000000000000000000000000000000..0f90855d05ae37dd7802b4aacf54a489e8de442e Binary files /dev/null and "b/chars/\343\203\215.png" differ diff --git "a/chars/\343\203\216.png" "b/chars/\343\203\216.png" new file mode 100644 index 0000000000000000000000000000000000000000..de14a5d531d0d2ed4f7689716c5e4b0a666d9ce9 Binary files /dev/null and "b/chars/\343\203\216.png" differ diff --git "a/chars/\343\203\217.png" "b/chars/\343\203\217.png" new file mode 100644 index 0000000000000000000000000000000000000000..700dbc0d0abccb862dffa9009dd5ec8d625c7c02 Binary files /dev/null and "b/chars/\343\203\217.png" differ diff --git "a/chars/\343\203\222.png" "b/chars/\343\203\222.png" new file mode 100644 index 0000000000000000000000000000000000000000..7b10e80b7018d44f4ec8477bc0be5923bdae0698 Binary files /dev/null and "b/chars/\343\203\222.png" differ diff --git "a/chars/\343\203\225.png" "b/chars/\343\203\225.png" new file mode 100644 index 0000000000000000000000000000000000000000..4bcc1769137e78830018d48de22056e9f795793d Binary files /dev/null and "b/chars/\343\203\225.png" differ diff --git "a/chars/\343\203\230.png" "b/chars/\343\203\230.png" new file mode 100644 index 0000000000000000000000000000000000000000..4966a4cc31873abf75bcca315a094537fd3dd9ae Binary files /dev/null and "b/chars/\343\203\230.png" differ diff --git "a/chars/\343\203\233.png" "b/chars/\343\203\233.png" new file mode 100644 index 0000000000000000000000000000000000000000..b976d25d1321b277be32c7669efc7de1688e86f5 Binary files /dev/null and "b/chars/\343\203\233.png" differ diff --git "a/chars/\343\203\236.png" "b/chars/\343\203\236.png" new file mode 100644 index 0000000000000000000000000000000000000000..3ea34076a5bc813020cf72bfd572703b40b44533 Binary files /dev/null and "b/chars/\343\203\236.png" differ diff --git "a/chars/\343\203\237.png" "b/chars/\343\203\237.png" new file mode 100644 index 0000000000000000000000000000000000000000..a655d917f3db3f404ed4c7942e59260172f67c76 Binary files /dev/null and "b/chars/\343\203\237.png" differ diff --git "a/chars/\343\203\240.png" "b/chars/\343\203\240.png" new file mode 100644 index 0000000000000000000000000000000000000000..35c8d2b8da2d45f235d4f9a2139d562452ad7344 Binary files /dev/null and "b/chars/\343\203\240.png" differ diff --git "a/chars/\343\203\241.png" "b/chars/\343\203\241.png" new file mode 100644 index 0000000000000000000000000000000000000000..f0f08ffae42e0165a7d6d880947ee7e975927c68 Binary files /dev/null and "b/chars/\343\203\241.png" differ diff --git "a/chars/\343\203\242.png" "b/chars/\343\203\242.png" new file mode 100644 index 0000000000000000000000000000000000000000..3952df7f6a84f2a426c0e9e5ff00fc3b31d15f8a Binary files /dev/null and "b/chars/\343\203\242.png" differ diff --git "a/chars/\343\203\244.png" "b/chars/\343\203\244.png" new file mode 100644 index 0000000000000000000000000000000000000000..8d40a34dc9c2a763415bd1a29beb8627800dd1e7 Binary files /dev/null and "b/chars/\343\203\244.png" differ diff --git "a/chars/\343\203\246.png" "b/chars/\343\203\246.png" new file mode 100644 index 0000000000000000000000000000000000000000..0b850d3328f1547e30d2fa4c10654499a9ded499 Binary files /dev/null and "b/chars/\343\203\246.png" differ diff --git "a/chars/\343\203\250.png" "b/chars/\343\203\250.png" new file mode 100644 index 0000000000000000000000000000000000000000..34861c22446747190775542f3c16fb42c899d66a Binary files /dev/null and "b/chars/\343\203\250.png" differ diff --git "a/chars/\343\203\251.png" "b/chars/\343\203\251.png" new file mode 100644 index 0000000000000000000000000000000000000000..29da2d28b440b073ec668331fd8a51438bc7fff5 Binary files /dev/null and "b/chars/\343\203\251.png" differ diff --git "a/chars/\343\203\252.png" "b/chars/\343\203\252.png" new file mode 100644 index 0000000000000000000000000000000000000000..600e3971e9831d0a163dbd95964142fb6b0045f6 Binary files /dev/null and "b/chars/\343\203\252.png" differ diff --git "a/chars/\343\203\253.png" "b/chars/\343\203\253.png" new file mode 100644 index 0000000000000000000000000000000000000000..e27dd715768df18193f5aa103fcfbdd9893c7ff1 Binary files /dev/null and "b/chars/\343\203\253.png" differ diff --git "a/chars/\343\203\254.png" "b/chars/\343\203\254.png" new file mode 100644 index 0000000000000000000000000000000000000000..a5b4dc2bcd228cd0f8a6a38fcb28ce62c2306009 Binary files /dev/null and "b/chars/\343\203\254.png" differ diff --git "a/chars/\343\203\255.png" "b/chars/\343\203\255.png" new file mode 100644 index 0000000000000000000000000000000000000000..69f1aeeb1bc7a284483c7e69735d9c8ba19b48ca Binary files /dev/null and "b/chars/\343\203\255.png" differ diff --git "a/chars/\343\203\257.png" "b/chars/\343\203\257.png" new file mode 100644 index 0000000000000000000000000000000000000000..3fc386bf60e4699681142208310abf3a6af7f153 Binary files /dev/null and "b/chars/\343\203\257.png" differ diff --git "a/chars/\343\203\262.png" "b/chars/\343\203\262.png" new file mode 100644 index 0000000000000000000000000000000000000000..af18782b545921c5cb525134fff52070ceaac7db Binary files /dev/null and "b/chars/\343\203\262.png" differ diff --git "a/chars/\343\203\263.png" "b/chars/\343\203\263.png" new file mode 100644 index 0000000000000000000000000000000000000000..fcd173e29c3868ccc88e987d52d934a9ee61224e Binary files /dev/null and "b/chars/\343\203\263.png" differ diff --git a/ocr.py b/ocr.py index 57a1175348a2cafa6d8bb33895007294cf530547..2210ad1aa9dc72e271b24fffee57250b59957e69 100644 --- a/ocr.py +++ b/ocr.py @@ -38,7 +38,9 @@ class CodecCTC: probs = self.softmax(preds[i][0]) k_idx = np.argsort(-probs)[:top_k] k_probs = probs[k_idx] - k_res = [dict(prob=p, char=self.chars[j]) for j, p in zip(k_idx, k_probs)] + k_res = [ + dict(prob=p, char=self.chars[j]) for j, p in zip(k_idx, k_probs) + ] nbest.append(k_res) text = "".join(char_list) @@ -79,9 +81,9 @@ class Recognizer: return result, nbest - def preprocess(self, image, height, width): + def preprocess(self, image, height, width, invert=False): src: np.ndarray = cv2.cvtColor(image, cv2.COLOR_RGBA2GRAY) - src = 255 - src + src = (255 - src) if invert else src cv2.imwrite("a.png", src) ratio = float(src.shape[1]) / float(src.shape[0])