Giter Club home page Giter Club logo

kanjidraw's Introduction

GitHub Release PyPI Version Python Versions CI AGPLv3+ Sponsor

Packaging status Packaging status

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 Android app.

Demo

Jiten Japanese Dictionary uses kanjidraw with a JavaScript frontend.

Installing

Debian

Official packages are available in Debian unstable and Ubuntu jammy.

$ apt install kanjidraw

You can also manually build a Debian package using the debian/sid branch, or download pre-built .debs via GitHub releases.

NixOS

An official package is also available in nixpkgs unstable.

Using pip

$ 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.

$ 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:

$ cd kanjidraw
$ git pull --rebase

Dependencies

  • Python >= 3.5 (w/ Tk support for the GUI).

Debian/Ubuntu

$ 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.

#!/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

$ 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, <esc> to go back.

Enabling Dark Mode

$ export KANJIDRAW_DARK=1

Disabling the Grid

$ export KANJIDRAW_NOGRID=1

License

Code

© FC Stegerman

AGPLv3+

KanjiVG (stroke data)

© Ulrich Apel

CC-BY-SA

kanjidraw's People

Contributors

obfusk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kanjidraw's Issues

gui: allow custom styling?

  • (Japanese) font?
  • font size?
  • canvas size? allow resize?
  • number of rows/cols/results?
  • colours? custom themes?

gui: support multiple use cases

  • print to stdout instead of copying to clipboard (for scripting)?
  • "oneshot" mode to draw one character, copy/print it, and exit?
  • "multiple" mode to draw multiple characters and copy/print all of them when done?

cleanup code etc.

  • use indent 4
  • add type annotations
  • modernise code & style
  • flake8
  • pylint
  • mypy --strict --disallow-any-unimported
  • supported python versions
  • #21

See also obfusk/jiten#158

[Question] Asking about the coordinate of points

Hello author,

strokes is the list of pair (x,y) coordinates. However, I does not understand why you multiply 255 and divide by width or height.

As far as I know, the width and height is equal to 400 ?

Is it just a normalization step to ensure the coordinates are consistent?

How did you define the magic number 255 ?

CleanShot 2023-03-03 at 12 48 34@2x

[debian] update package

  • use dh-sequence-python3
  • Standards-Version: 4.6.1
  • update copyright & Maintainer:
  • ack NMU
  • ship AGPL

optimise!

  • fuzzy: only sort 1x (before match() loop & before offby1 loop)
  • only calculate dirs&locs 1x (pre-calc for DB)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.