Zinnia is a great handwriting recognition library based on SVM. Our Japanese dictionary app uses a customized version of Zinnia, called ZinnaCocoaTouch, for the Kanji input engine.
This sample demonstrates how to use ZinnaCocoaTouch (which already provided the model and interface implementation in Objective-C) in an iOS project. It is written in Swift 4 with XCode 10.1.
The process is a bit long but fairly simple. Look here for detailed instructions.
See DrawableView.swift for a simple implementation of the drawing canvas and HandritingViewModel.swift on how to use the library.
Basically, we create an instance of Recognizer
and for each newly drawn stroke, feed that to Recognizer.classify()
method which accepts an [NSValue]
as the argument.
The method returns a Result
that represent the classified values ordered by confidence. Then we can apply result!.map { $0.value }
to get an array of String
, each of which represents a kanji.
When you use a third-party library which is also happen to define a Result
class (Alamofire for example), XCode may fail to resolve.
If that happens, look into Result.h, Result.m and change the interface name to something else, like ZinniaResult
to avoid the conflict.