All Projects → ChenYuHo → handwriting.js

ChenYuHo / handwriting.js

Licence: MIT license
A simple API access to the handwriting recognition service of Google IME

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to handwriting.js

iinkJS
✏️ ☁️ iinkJS is the fastest way to integrate rich handwriting recognition features in your webapp.
Stars: ✭ 65 (-26.97%)
Mutual labels:  handwriting, handwriting-recognition
Word-recognition-EmbedNet-CAB
Code implementation for our ICPR, 2020 paper titled "Improving Word Recognition using Multiple Hypotheses and Deep Embeddings"
Stars: ✭ 19 (-78.65%)
Mutual labels:  recognition
Onion Rime Files
電腦 Rime 洋蔥方案(注音、雙拼、拼音、形碼、行列30)
Stars: ✭ 88 (-1.12%)
Mutual labels:  ime
fridaMemoryAccessTrace
android memory access trace utility powered by frida framework
Stars: ✭ 134 (+50.56%)
Mutual labels:  trace
PyCasia
A python library to work with the CASIA Chinese handwriting database.
Stars: ✭ 38 (-57.3%)
Mutual labels:  handwriting-recognition
chromeos-key-remapper
IME / tooling for remapping key combos to other key combos on Chrome OS
Stars: ✭ 29 (-67.42%)
Mutual labels:  ime
openface mass compare
An openface script that runs a REST server. Posted images are compared against a large dataset, and the most likely match is returned. Works with https://hub.docker.com/r/uoacer/openface-mass-compare/
Stars: ✭ 22 (-75.28%)
Mutual labels:  recognition
TraceR
Trace Replay and Network Simulation Framework
Stars: ✭ 17 (-80.9%)
Mutual labels:  trace
ObjRecPoseEst
Object Detection and 3D Pose Estimation
Stars: ✭ 71 (-20.22%)
Mutual labels:  recognition
TraceEvent
Trace events in real time sessions
Stars: ✭ 26 (-70.79%)
Mutual labels:  trace
zipkin-ruby-opentracing
OpenTracing Tracer implementation for Zipkin in Ruby
Stars: ✭ 15 (-83.15%)
Mutual labels:  trace
strokeText.js
Simple, pixel-perfect text stroking for the web.
Stars: ✭ 30 (-66.29%)
Mutual labels:  stroke
ner-d
Python module for Named Entity Recognition (NER) using natural language processing.
Stars: ✭ 14 (-84.27%)
Mutual labels:  recognition
TensorFlow-Powered Robot Vision
No description or website provided.
Stars: ✭ 34 (-61.8%)
Mutual labels:  recognition
Car-Model-Recognition
Car Model Recognition project
Stars: ✭ 53 (-40.45%)
Mutual labels:  recognition
air writing
Online Hand Writing Recognition using BLSTM
Stars: ✭ 26 (-70.79%)
Mutual labels:  handwriting-recognition
tweet-music-recognizer
🎙️ Node.js Bot to identify songs in Twitter videos
Stars: ✭ 57 (-35.96%)
Mutual labels:  recognition
OutlineTextView
Android TextView with outline
Stars: ✭ 59 (-33.71%)
Mutual labels:  stroke
FormTracer
A Mathematica Tracing Package Using FORM
Stars: ✭ 16 (-82.02%)
Mutual labels:  trace
go-sensor
🚀 Go Distributed Tracing & Metrics Sensor for Instana
Stars: ✭ 90 (+1.12%)
Mutual labels:  trace

handwriting.js

A simple API access to the incredible handwriting recognition of Google IME

Demo

See here

Usage

Include src

    <script type="text/javascript" src="handwriting.js"></script>

Capture trace

The captured trace looks like:

var trace = 
    [   //the trace is an array of strokes
        [   //a stroke is an array of pairs of captured (x, y) coordinates
            [300, 310, 320, 330, 340], //x coordinate
            [320, 320, 320, 320, 320]  //y coordinate
            //each pair of (x, y) coordinates represents one sampling point 
        ],
        [
             [320, 320, 320, 320, 320],
             [300, 310, 320, 330, 340]
        ]
    ];

For example, the trace above is composed of two strokes,

(300, 320), (310, 320), (320, 320), (330, 320), (340, 320)

and

(320, 300), (320, 310), (320, 320), (320, 330), (320, 340),

which is produced by writing "十".

Manage options

options argument is an optional object of following fields:

var options = {
    width : 800,         //int, width of the writing area, default: undefined
    height : 800,        //int, height of the writing area, default: undefined
    language : "zh_TW",  //string, language of input trace, default: "zh_TW"
    numOfWords : 1,      //int, number of words of input trace, default: undefined
    numOfReturn : 5,     //int, number of maximum returned results, default: undefined
};

Under most conditions, only language field is required. However, specifying writing area width and height helps in improving precision.

See Language Support

Specify callback function

The recognition function will invoke the callback function argument passed in after recognition process. The callback function should accept two arguments as shown below:

var callback = function(result, err){
    if(err) throw err;
    else console.log(result);	
};

The returned result will be an array of string, for example, the trace above (with other options set to default) generates:

[ "十", "+", "一|", "一1", "一个", "-|", "一'", "-1", "一.", "-." ]

If no error occurred, err will be undefined.

Call recognition function

bound on a button as an example:

<button onclick="handwriting.recognize(trace, options, callback);">Recognize</button>

Fully functional library

Include handwriting.canvas.js instead of handwriting.js if you want to use the pre-implemented canvas behaviors.

<script type="text/javascript" src="./handwriting.canvas.js"></script>

Usage

Declare html canvas as handwriting.Canvas object by passing that canvas element to the constructor:

<canvas id="can" width="400" height="400" style="border: 2px solid; cursor: crosshair;"></canvas>

<script>
    var can1 = new handwriting.Canvas(document.getElementById("can"));
</script>

Now trace is automatically captured, stored in the object, and shown on the given element (either by mouse dragging or touch).

APIs

The captured trace and other fields are independent through objects, so call the following functions exactly on which object you wish to take action to:

    //Set callback function
    can1.setCallBack(function(data, err) {
        if(err) throw err;
        else console.log(data);
    });

    //Set line width shown on the canvas element (default: 3)
    can1.setLineWidth(5);

    //Set options
    can1.setOptions(
        {
            language: "ja",
            numOfReturn: 3
        }
    );

    //recognize captured trace
    can1.recognize();
	
    //Clear canvas, captured trace, and stored steps
    can1.erase();

undo and redo functionality

This feature is achieved by saving every stroke in object, however, such attempt consumes relatively higher memory, so undo and redo functionalities are disabled by default, to change the availability, simply call :

    //only turn on undo functionality
    can1.set_Undo_Redo(true, false);

    //turn on both functionalities
    can1.set_Undo_Redo(true, true);

note that redo functionality can be turned on only if undo functionality is also turned on

    //calling any of the two functions below leads to the same consequence: turn off both undo, redo functionality, and clear stored steps (if any) 
    can1.set_Undo_Redo(false, false);
    can1.set_Undo_Redo(false, true);

If the functionalities are turned on, the following functions will work, otherwise, nothing will happen:

    can1.undo();
    //set canvas and stored trace to the last state (stroke)

    can1.redo();
    //if there are undo records, return to the state of the next stored step

Note that, even included handwriting.canvas.js now, the previous way of calling recognition still works :

    handwriting.recognize(trace, options, callback);

so that you can take advantage of the handwriting.canvas object, while not changing previous code.


Supported Language

Reference

Note: Google provides a supported language list, but not the language codes. The following codes are collected from the Internet and only zh_TW, en, ja are tested. If you notice weird recognition results then maybe the language code is wrong.

Language 語言 code
Afrikaans 南非荷蘭文 af
Albanian 阿爾巴尼亞文 sq
Basque 巴斯克文 eu
Belarusian 白俄羅斯文 be
Bulgarian 保加利亞文 bg
Catalan 卡達隆尼亞文 ca
Chinese (Simplified) 中文 (簡體) zh_CN
Chinese (Traditional) 中文 (繁體) zh_TW
Croatian 克羅埃西亞文 hr
Czech 捷克文 cs
Danish 丹麥文 da
Dutch 荷蘭文 nl
English 英文 en
Estonian 愛沙尼亞文 et
Filipino 菲律賓文 fil
Finnish 芬蘭文 fi
French 法文 fr
Galician 加里西亞文 gl
German 德文 de
Greek 希臘文 el
Haitian 海地文 ht
Hindi 北印度文 hi
Hungarian 匈牙利文 hu
Icelandic 冰島文 is
Indonesian 印尼文 id
Irish 愛爾蘭文 ga
Italian 義大利文 it
Japanese 日文 ja
Korean 韓文 ko
Latin 拉丁語系 la
Latvian 拉脫維亞文 lv
Lithuanian 立陶宛文 lt
Macedonian 馬其頓文 mk
Malay 馬來文 ms
Norwegian 挪威文 no
Polish 波蘭文 pl
Portuguese (Brazil) 葡萄牙文 (巴西) pt_BR
Portuguese (Portugal) 葡萄牙文 (葡萄牙) pt_PT
Romanian 羅馬尼亞文 ro
Russian 俄文 ru
Serbian 塞爾維亞文 sr
Slovak 斯洛伐克文 sk
Slovenian 斯洛維尼亞文 sl
Spanish 西班牙文 es
Swahili 斯瓦希里文 sw
Swedish 瑞典文 sv
Thai 泰文 th
Turkish 土耳其文 tr
Ukranian 烏克蘭文 yk
Vietnamese 越南文 vi
Welsh 威爾斯文 cy

License

MIT licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].