-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.html
349 lines (309 loc) · 11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel=stylesheet href="zinnia.css" media=all>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Zinnia: Online hand writing recognition system with machine learning</title>
</head>
<body>
<h1>Zinnia: Online hand recognition system with machine learning</h1>
<p><a href="index-ja.html">[Japanese]</a><a href="index.html">[English]</a></p>
<p>
Zinnia is a simple, customizable and portable online hand recognition system
based on Support Vector Machines. Zinnia simply receives user pen strokes
as a sequence of coordinate data and outputs n-best characters sorted by
SVM confidence. To keep portability, Zinnia doesn't have any rendering
functionality. In addition to recognition, Zinnia provides training
module that allows us to create any hand-written recognition systems with low-cost.
</p>
<h2>Features</h2>
<ul>
<li>Practical accuracy with support vector machines
<li>Portable and compact design -- POSIX/Windows (depending on C++/STL)
<li>Thread-safe C/C++/Perl/Ruby/Python libraries
<li>Practical recognition speed (50--100char / sec)
<li>Fast training
</ul>
<h2>Download</h2>
<ul>
<li><b>Zinnia</b> is free software; you can redistribute it
and/or modify it under the terms of the <a
href="http://www.opensource.org/licenses/bsd-license.php">new BSD
License</a></li>
<li><b>Zinnia</b> main program
<h3><a name="source">Source</a></h3>
<ul>
<li>zinnia-0.07.tar.gz:<a href="src">download</a>
<li>No recognition models are included.
</ul>
<h3><a name="win">Binary package for MS-Windows</a></h3>
<ul>
<li>zinnia-0.07.zip:<a href="src">Download</a>
</ul>
<li><b>Zinnia</b> Recognition models
<h3>Zinnia-Tomoe</h3>
<ul>
<li>Model files trained with Tomoe data: <a href="src">download</a></li>
<li>Licence of Zinnia-tomoe is the same as that of Tomoe</li>
</ul>
</ul>
<h2>Install</h2>
<h3>UNIX</a></h3>
<pre>
% tar zxfv zinnia-X.X.tar.gz
% cd zinnia-X.X
% ./configure
% make
% su
# make install
</pre>
</li>
<p>Install recognition models</p>
<pre>
% tar zxfv zinnia-tomoe-XXXX.tar.gz
% zinnia-tomoe-XXXX
% ./configure
% make
% su
# make install
</pre>
<h3>Windows</h3>
<p>DLL and executable are included in zip file.
No recognition models are included. Run the following command after
putting model files in zip archived directory.
<pre>
bin\zinnia_convert.exe handwriting-ja.model.txt handwriting-ja.model
bin\zinnia_convert.exe handwriting-zh_CN.model.txt handwriting-zh_CN.model
</pre>
<h2>Usage (Recognition)</h2>
<p>Zinnia provides C/C++ libraries. Perl/Ruby/Python
libraries are also available with SWIG </p>
<h3>Sample code with C</h3>
<pre>
#include <stdio.h>
#include "zinnia.h"
int main(int argc, char **argv) {
size_t i;
zinnia_recognizer_t *recognizer;
zinnia_character_t *character;
zinnia_result_t *result;
recognizer = zinnia_recognizer_new();
if (!zinnia_recognizer_open(recognizer, "/usr/local/lib/zinnia/model/tomoe/handwriting-ja.model")) {
fprintf(stderr, "ERROR: %s\n", zinnia_recognizer_strerror(recognizer));
return -1;
}
zinnia_character_t *character = zinnia_character_new();
zinnia_character_clear(character);
zinnia_character_set_width(character, 300);
zinnia_character_set_height(character, 300);
zinnia_character_add(character, 0, 51, 29);
zinnia_character_add(character, 0, 117, 41);
zinnia_character_add(character, 1, 99, 65);
zinnia_character_add(character, 1, 219, 77);
zinnia_character_add(character, 2, 27, 131);
zinnia_character_add(character, 2, 261, 131);
zinnia_character_add(character, 3, 129, 17);
zinnia_character_add(character, 3, 57, 203);
zinnia_character_add(character, 4, 111, 71);
zinnia_character_add(character, 4, 219, 173);
zinnia_character_add(character, 5, 81, 161);
zinnia_character_add(character, 5, 93, 281);
zinnia_character_add(character, 6, 99, 167);
zinnia_character_add(character, 6, 207, 167);
zinnia_character_add(character, 6, 189, 245);
zinnia_character_add(character, 7, 99, 227);
zinnia_character_add(character, 7, 189, 227);
zinnia_character_add(character, 8, 111, 257);
zinnia_character_add(character, 8, 189, 245);
result = zinnia_recognizer_classify(recognizer, character, 10);
if (result == NULL) {
fprintf(stderr, "%s\n", zinnia_recognizer_strerror(recognizer));
return -1;
}
for (i = 0; i < zinnia_result_size(result); ++i) {
fprintf(stdout, "%s\t%f\n",
zinnia_result_value(result, i),
zinnia_result_score(result, i));
}
zinnia_result_destroy(result);
zinnia_character_destroy(character);
zinnia_recognizer_destroy(recognizer);
return 0;
}
</pre>
</p>
<pre>
% gcc example.c -lzinnia -o zinnia_sample
% ./zinnia_sample
</pre>
<h3>Comment</h3>
<ul>
<li>create recognizer
<li>load model file
<li>create character object
<li>clear character
<li>set canvas size
<li>specify stroke data (number of stroke, x-axis, y-axis)
<li>do recognition. result object is created. The last arg means the maximum size of characters requested
<li>print recognized character with score. results are sorted by score
<li>delete result object
<li>delete character object
<li>delete recognizer object
</ul>
<h3>Sample code with C++</h3>
<pre>
#include <iostream>
#include "zinnia.h"
int main(int argc, char **argv) {
zinnia::Recognizer *recognizer = zinnia::Recognizer::create();
if (!recognizer->open("/usr/local/lib/zinnia/model/tomoe/handwriting-ja.model")) {
std::cerr << recognizer->what() << std::endl;
return -1;
}
zinnia::Character *character = zinnia::Character::create();
character->clear();
character->set_width(300);
character->set_height(300);
character->add(0, 51, 29);
character->add(0, 117, 41);
character->add(1, 99, 65);
character->add(1, 219, 77);
character->add(2, 27, 131);
character->add(2, 261, 131);
character->add(3, 129, 17);
character->add(3, 57, 203);
character->add(4, 111, 71);
character->add(4, 219, 173);
character->add(5, 81, 161);
character->add(5, 93, 281);
character->add(6, 99, 167);
character->add(6, 207, 167);
character->add(6, 189, 245);
character->add(7, 99, 227);
character->add(7, 189, 227);
character->add(8, 111, 257);
character->add(8, 189, 245);
zinnia::Result *result = recognizer->classify(*character, 10);
if (!result) {
std::cerr << recognizer->what() << std::endl;
return -1;
}
for (size_t i = 0; i < result->size(); ++i) {
std::cout << result->value(i) << "\t" << result->score(i) << std::endl;
}
delete result;
delete character;
delete recognizer;
return 0;
}
</pre>
<h3>Sexp representation for character</h3>
<p>Character class (zinnia_character_t / zinnia::Character) has method
for an Sexp-based serialization.</p>
<pre>
(character
(width canvas width)
(height canvas height)
(strokes
((0-th-stroke 0-th-strokey) ... (0-th-stroke 0-th-strokey))
((1-th-stroke 0-th-strokey) ... (1-th-stroke 1-th-strokey))
((2-th-stroke 2-th-strokey) ... (2-th-stroke 2-th-strokey))
...))
</pre>
<p>Example</p>
<pre>
static const char sexp[] = "(character (width 1000)(height 1000)(strokes ((243 273)(393 450))((700 253)(343 486)(280 716)(393 866)(710 880))))";
zinnia_character_t *character = zinnia_character_new();
zinnia_character_parse(character, sexp);
</pre>
<pre>
static const char sexp[] = "(character (width 1000)(height 1000)(strokes ((243 273)(393 450))((700 253)(343 486)(280 716)(393 866)(710 880))))";
zinnia::Character *character = zinnia::Character::create();
character->parse(sexp);
</pre>
<h2>Training</h2>
<p>
In order to make a training with Zinnia, you need to make a golden
(training) data. Training data is written in S-expression.
Generally speaking, more data yields better quality. Zinnia only supports
batch training so far.</p>
<p>Example</p>
<pre>
(character (value あ) (width 300) (height 300) (strokes ((54 58)(249 68)) ((147 10)(145 201)(182 252)) ((224 103)(149 230)(82 240)(53 204)(86 149)(182 139)(240 172)(248 224)(228 250))))
(character (value い) (width 300) (height 300) (strokes ((56 63)(43 213)(67 259)(94 243)) ((213 66)(231 171)(208 217))))
(character (value う) (width 300) (height 300) (strokes ((102 35)(187 45)) ((73 121)(167 105)(206 139)(198 211)(135 275))))
(character (value え) (width 300) (height 300) (strokes ((140 19)(162 38)) ((62 105)(208 100)(51 263)(128 205)(188 268)(260 252))))
(character (value お) (width 300) (height 300) (strokes ((64 94)(240 98)) ((148 35)(159 129)(140 199)(105 247)(64 228)(101 161)(192 161)(222 223)(189 257)) ((223 49)(253 89))))
</pre>
</p>
<p>You might want to look into *.s file in zinnia-tomoe as references</p>
<p>Use zinnia_learn to conduct training</p>
<pre>
% zinnia_learn train-file model-file
...
learning: (8/3033) 8 ....
learning: (9/3033) 9 ...
learning: (10/3033) 々 ............
learning: (11/3033) 〆 ....
learning: (12/3033) あ ....
learning: (13/3033) い .......
learning: (14/3033) う ...............
learning: (15/3033) え ......................................................................................
learning: (16/3033) お ......
learning: (17/3033) か .......
learning: (18/3033) き .......
learning: (19/3033) く .......
</pre>
<p>train-file is a training data and model-file is a model file
zinnia_learn generates</p>
<p>use zinnia command for testing</p>
<pre>
% zinnia -m model-file < test-file
</pre>
<p>model-file is a file zinnia_learn generates. text-file is a test data
written in Sexp format.</p>
<p>Once training completes successfully, model-file.txt (text file)
and model-file (binary file) will be generated.
text-model is an architecture-independent format, and model-file is
an architecture-dependent binary model. Zinnia recognizer can only load
binary model. zinnia_convert program converts text-model
into binary model.</p>
<pre>
% zinnia_convert model-file.txt model-file
</pre>
<p>In addition, text-model can be converted into C-header file.</p>
<pre>
% zinnia_convert --name=my_model --make_header model-file.txt my_model.h
</pre>
<p>In order to use a header file, include my_model.h in C/C++ source
file and load the data using zinnia_recognizer_open_from_ptr().
my_model(content of mode) and my_model_size(model size) is defined in
the header file.
</p>
<pre>
#include "my_model.h"
if (!zinnia_recognizer_open_from_ptr(recognizer, my_model, my_model_size)) {
/* error */
}
</pre>
<h2>Model compression</h2>
<p>By omitting features having small score, model can be compressed with
scarifying recognition accuracy.
<pre>
% zinnia_convert -c 0.01 model-file.txt model1
% zinnia_convert -c 0.001 model-file.txt model2
% ls -h -l model*
-rw-r--r-- 1 taku taku 3.1M 2008-07-14 12:50 model1
-rw-r--r-- 1 taku taku 25M 2008-07-14 12:50 model2
</pre>
<p>c is a threshold. Default setting 0.001.
Larger threshold gives more aggressive compression.</p>
<h2>API list</h2>
<ul>
<li><a href="doxygen/annotated.html">C++ API</a>
<li><a href="doxygen/zinnia_8h.html">C API functions</a>
</ul>
<p>
</p>
</body>
</html>