Skip to content

A Swift wrapper around zinnia, a library to recognize handwritten Japanese (or Chinese) characters.

License

Notifications You must be signed in to change notification settings

RomainPln/zinnia-swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zinnia-Swift

A Swift wrapper around zinnia, a library to recognize handwritten Japanese (or Chinese) characters.

For more information about zinnia, see https://taku910.github.io/zinnia/.

Recognition requires a model file that incorporates training data. Model files can be downloaded, for example from https://tegaki.github.io. A model file is included for unit testing.

Installation

Use the Swift Package Manager. Add the following to your dependencies in Package.swift

dependencies: [
        .package(url: "https://github.com/shinjukunian/zinnia-swift.git", from: "0.1.0"),
    ],

How to use

To get started, initialize the Recognizer

let url = ... //the url of your model file
let recognizer=try? Recognizer(modelURL:url)

Don't forget to specify the canvas size on which the characters are being drawn.

recognizer.canvasSize = Recognizer.Size(width:500, height:500)

Next, add strokes to the recognizer. These would typically come from a gesture recognizer on a UIView or the movements of a mouse. A stroke consists of all the points between touchesBegan(:) and touchesEnded(:).

let stroke = Stroke(points: [Point(x: 50, y: 250], Point(x:450, y: 250)])
//strokes for character 一

recognizer.add(stroke:stroke)

The stroke order is important. To classify strokes, use

let result = recognizer.classify()

let characters = result.map({$0.character})
//the recognized characters

The recognizer can be reset using

recognizer.clear()

to start a new character.

For a sample application, see https://github.com/shinjukunian/KanjiLookup-SwiftUI.

To Do

  • Implement training - [ ] Sample application

Licence

zinnia (Copyright (c) 2005-2007, Taku Kudo), is BSD-licenced.

zinnia-Swift is under the MIT licence

The various model files come with their own licence.

About

A Swift wrapper around zinnia, a library to recognize handwritten Japanese (or Chinese) characters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%