https://github.com/obfusk/kanjidraw
kanjidraw - handwritten kanji recognition library + gui
https://github.com/obfusk/kanjidraw
draw gui handwriting japanese kanji library recognition
Last synced: about 1 year ago
JSON representation
kanjidraw - handwritten kanji recognition library + gui
- Host: GitHub
- URL: https://github.com/obfusk/kanjidraw
- Owner: obfusk
- License: agpl-3.0
- Created: 2021-05-09T11:49:05.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-29T18:45:15.000Z (almost 4 years ago)
- Last Synced: 2025-06-14T13:02:50.260Z (about 1 year ago)
- Topics: draw, gui, handwriting, japanese, kanji, library, recognition
- Language: Python
- Homepage:
- Size: 647 KB
- Stars: 25
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.AGPLv3
Awesome Lists containing this project
README
[](https://github.com/obfusk/kanjidraw/releases)
[](https://pypi.python.org/pypi/kanjidraw)
[](https://pypi.python.org/pypi/kanjidraw)
[](https://github.com/obfusk/kanjidraw/actions?query=workflow%3ACI)
[](https://www.gnu.org/licenses/agpl-3.0.html)
[](https://ko-fi.com/obfusk)
# kanjidraw
## handwritten kanji recognition
`kanjidraw` is a simple Python library + GUI for matching (the strokes
of a) handwritten kanji against its database.
You can use the GUI to draw and subsequently select a kanji from the
list of probable matches, which will then be copied to the clipboard.
The database is based on KanjiVG and the algorithms are based on the
[Kanji draw](https://github.com/onitake/kanjirecog) Android app.
## Demo
[Jiten Japanese Dictionary](https://jiten.obfusk.dev)
uses `kanjidraw` with a
[JavaScript frontend](https://github.com/obfusk/jiten/blob/master/jiten/static/kanjidraw.js).
## Installing
### Debian
Official packages are available in
[Debian unstable](https://packages.debian.org/unstable/kanjidraw)
and
[Ubuntu jammy](https://packages.ubuntu.com/jammy/kanjidraw).
```bash
$ apt install kanjidraw
```
You can also manually build a Debian package using the `debian/sid`
branch, or download pre-built `.deb`s via GitHub releases.
### NixOS
An official package is also available in
[nixpkgs unstable](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/kanjidraw/default.nix).
### Using pip
```bash
$ pip install kanjidraw
```
NB: depending on your system you may need to use e.g. `pip3 --user`
instead of just `pip`.
### From git
NB: this installs the latest development version, not the latest
release.
```bash
$ git clone https://github.com/obfusk/kanjidraw.git
$ cd kanjidraw
$ pip install -e .
```
NB: you may need to add e.g. `~/.local/bin` to your `$PATH` in order
to run `kanjidraw`.
To update to the latest development version:
```bash
$ cd kanjidraw
$ git pull --rebase
```
## Dependencies
* Python >= 3.5 (w/ Tk support for the GUI).
### Debian/Ubuntu
```bash
$ apt install python3-tk
```
## Examples
### Kanji Input on Linux
#### kanjidraw-paste
Opens `kanjidraw` to select one (`--oneshot`) or multiple
(`--multiple`) kanji, and afterwards pastes the selected kanji in the
active window. Requires `xclip` and `xdotool`.
```bash
#!/bin/bash
set -e
pid="$( xdotool getactivewindow getwindowpid )"
pids() { xdotool search --classname "$1" getwindowpid %@; }
if pids rxvt | grep -q "^$pid$"; then
key=ctrl+alt+v
elif ( pids terminal; pids st-256color ) | grep -q "^$pid$"; then
key=ctrl+shift+v
else
key=ctrl+v
fi
kanjidraw -s "$@" | tr -d '\n' | xclip -i -selection clipboard
xdotool key --delay 250 "$key"
```
#### i3 config
Keybindings for i3. Creating custom keybindings for `kanjidraw-paste
--oneshot` and/or `kanjidraw-paste --multiple` should work similarly
with other window managers and desktop environments.
```
for_window [title="Kanji Draw"] floating enable
bindsym $mod+Control+k exec --no-startup-id kanjidraw-paste --oneshot
bindsym $mod+Control+m exec --no-startup-id kanjidraw-paste --multiple
```
## Miscellaneous
### GUI Options
```bash
$ kanjidraw --help
usage: kanjidraw [-h] [-s] [-o | -m] [-d] [--version]
optional arguments:
-h, --help show this help message and exit
-s, --stdout print kanji to stdout instead of copying to clipboard
-o, --oneshot quit after one kanji
-m, --multiple queue kanji and copy/print after pressing 'c' or quitting
-d, --dark use dark theme
--version show program's version number and exit
```
Additional keybindings: `q` to quit, `` to go back.
### Enabling Dark Mode
```bash
$ export KANJIDRAW_DARK=1
```
### Disabling the Grid
```bash
$ export KANJIDRAW_NOGRID=1
```
## License
### Code
© FC Stegerman
[](https://www.gnu.org/licenses/agpl-3.0.html)
### KanjiVG (stroke data)
© Ulrich Apel
[](https://github.com/KanjiVG/kanjivg/blob/master/COPYING)