Site of James

Placing my knowledge on a web page

Handwriting Recognition in Mozc (and fixing it)

Mozc is (the open-source subset of) Google’s Japanese IME. It has a kinda-hidden feature of handwriting recognition, which is great for RTK students such as myself which sometimes know how to write a kanji but can’t type it. Usually, Mozc installs to /usr/lib/mozc/, so it can be invoked by:

/usr/lib/mozc/mozc_tool --mode=hand_writing

But sometimes it doesn’t work, and recently I’ve found out more about why.

This is how I helped someone solve this issue on the Mozc repo recently.

alt text

It looks nice, until you go to write a character and see an error appear in the canvas.

alt text

The thing about Mozc’s handwriting mode is that by default there are two modes, “cloud mode” and “zinnia” mode. here is the source for cloud mode. You can see that in the open-source version, it’s incomplete. I expect this is secret sauce only some closed-source builds Google provides have.

So most Linux distributions are left to use the Zinnia recognizer. Zinnia is a SVM-based stroke-to-kanji classifier developed by Taku Kudo upon which Mozc relies.

So, more often than not, the error is due to the Zinnia Japanese model not being installed. Please check that you have the following packages:

  • Ubuntu/Debian: tegaki-zinnia-japanese
  • Manjaro/Arch: tegaki-models-zinnia-japanese
  • All other: On this page download Japanese (all) and place handwriting-ja.model into /usr/share/tegaki/models/zinnia/.

After this, the error should be no more, and you are free to enjoy handwriting kanji.

An aside

If you have a system where the handwriting isn’t working, you can check if you are using the cloud-based or Zinnia-based by building Mozc in debug mode and running the tool, logging to stderr as below. You will most likely see the following message.

./mozc_tool --mode=hand_writing --logtostderr

2019-07-20 23:39:05 20859 140500315393152 ../../handwriting/zinnia_handwriting.cc(76) LOG(ERROR) Cannot open model file:/usr/share/tegaki/models/zinnia/handwriting-ja.model