Click here to Skip to main content
15,880,405 members
Articles / Multimedia / GDI

UPV – UNIPEN online handwriting recognition database viewer control

Rate me:
Please Sign up or sign in to vote.
4.82/5 (13 votes)
19 Mar 2012CPOL4 min read 50.2K   5.2K   50   6
UPV – UNIPEN online handwriting recognition database viewer control

Introduction

Since my last article named “Neural Network for Recognition of Handwritten Digits in C#” has been posted on Codeproject.com, I received several emails contributing to it. It was really appreciated. In order to encourage people who want to study on handwriting recognition techniques I have written a small control named UPV (UNIPEN handwriting database viewer) to view online handwritten samples of UNIPEN, one of biggest handwriting database all over the world. From this control, hand written pen streams can be exported to bitmap to use in other programs. The control uses a dll file named UPUnipenLib.dll, a small part of a library I am developing for a sponsored handwriting character recognition project. It is not open source project at moment but this file is free to use completely in non-commerce.

Image 1

Background 

Requirements

UNIPEN database download from: http://unipen.nici.kun.nl/

(The downloaded folder should be changed to “UnipenData” before using)

UNIPEN library: UPUnipenLib.dll (attached in source code and demo)

UNIPEN vs MNIST database

In my last article, I used MNIST for my neural network. It is a database of handwritten digits has a training set of 60,000 examples, and a test set of 10,000 examples. It is really good database for learning techniques and pattern recognition methods on real-world data. However, due to its limit, MNIST database is not enough to a more complex recognition system.

By virtue of a handwriting recognition system, having a large enough database is a challenge. As of 1999, the international Unipen Foundation was installed to safeguard the distribution of a large database of on-line handwritten samples, collected by a consortium of 40 companies and institutes. It is a huge free database having over 5 million characters, from more than 2200 writers. The database has been being used by researchers at many labs and universities in all over the world. It is also was used as testing samples for many pattern recognition competitions like ICDAR.

In general, UNIPEN data set is difficult to recognize despite the data format is standardized.  The UNIPEN format can be referenced here

Although UNIPEN project have some tools to view and edit the database on their website but they were written on the very old computer systems in 15 years ago. So, they are almost useless to me to understand how to view the data. Therefore, the method I used in my project was completely built based on my own knowledge on the data format. 

Using the code

How to use the UPUnipenLib.dll file and the UPV control

UPUnipenLib.dll is a library of functions for reading UNIPEN data files as well as exporting UNIPEN streams to bitmap object. Classes have been constructed based on UNIPEN file definition. The below diagram will give you a general view which should help easier to understand and use the library file.

Image 2

Using library to get pen-stream and export it to bitmap is very simple as follows: 

C#
private void btnOpen_Click(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.InitialDirectory = Environment.CurrentDirectory;
    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog.FilterIndex = 2;
    openFileDialog.RestoreDirectory = true;
    upDataset = new UPUnipenLib.UPDataSet();
    if (openFileDialog.ShowDialog(this) == DialogResult.OK)
    {
        try
        {
            //set upDataset.InitialDirectory=full path of unipen folder if it is not "UnipenData".
            upDataset.InitialDirectory = "";
            upDataset.FillDataSetFromFile(openFileDialog.FileName);
            if (upDataset.Datalayouts.Count > 0)
            {
                //fill up the treeview
                FillUpTreeview();
                //
                iDatalayout = 0;
                //
                foreach (UPDataLayout dl in upDataset.Datalayouts)
                {
                    if (dl.UpUnipens.Count > 0)
                    {
                        unipen = dl.UpUnipens[0];
                        UpdateBitmap();
                        break;
                    }
                    iDatalayout++;
                }
            }
            else
            {
                MessageBox.Show("The opened file is invalid, please select other file");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
    UpdatePanels(true);
}

Export to bitmap:

C#
private void UpdateBitmap()
{
    UnipenBitmap ibox = new UnipenBitmap(unipen, (int)udPenwidth.Value);
    if (rbLine.Checked)
    {
        ibox.Drawtype = DrawType.Line;
    }
    else if (rbPie.Checked)
    {
        ibox.Drawtype = DrawType.Pie;
    }
    ibox.Multicolor = cbMultipenColor.Checked;
    ibox.PenWidth =(int) udPenwidth.Value;
    ibox.Uppen = cbUppen.Checked;
    // convert to and show the bitmap 
    this.Image = ibox.Image;
}

Points of Interest

The UPV control is constructed based on the project “Image Viewer UserControl”  of Jordy "Kaiwa" Ruiter, but it was adjusted to fit to the purpose of pen stream presentation. On this control, you can view not only the pen stream but also know how the pen stream is made through its colors. You can also view pen-down trajectories as well as pen-up ones.

Image 3

Picture 2: Unipen sample with up pen trajectories

Image 4

Picture 2: Unipen sample without up pen trajectories

The UPV control can show UNIPEN samples accurately in most cases. However, because the database is too large, so I have not time to fix all problem should have. Your feedback would be highly appreciated. 

History 

ver 1.01:

Fix bugs in special SEGMENT case (example):

  .SEGMENT CHARACTER 1:40-3,5,6:0-6:12 OK "1" 

Fix mutil included files. Tested ok in almost unipen data files (1a,1b,1c,1d,2) 

TuDienTiengViet.Net
Image 5 Image 6
<iframe id="dictFrame" name="dictFrame" height="220" src="about:blank" frameborder="0" width="100%" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> &amp;amp;lt;/td&amp;amp;gt;&amp;amp;lt;/tr&amp;amp;gt;&amp;amp;lt;tr align=&amp;amp;quot;center&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;td width=&amp;amp;quot;100%&amp;amp;quot; height=&amp;amp;quot;20&amp;amp;quot;&amp;amp;gt;©2007 &amp;amp;lt;a href=&amp;amp;quot;http://www.tudientiengviet.net&amp;amp;quot; target=&amp;amp;quot;_blank&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;strong&amp;amp;gt;Open Vietnamese Dictionaries Project&amp;amp;lt;/strong&amp;amp;gt;&amp;amp;lt;/a&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;&amp;amp;lt;/tr&amp;amp;gt;&amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;&amp;amp;lt;/fieldset&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;&amp;amp;lt;/tr&amp;amp;gt;&amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;&amp;amp;lt;/tr&amp;amp;gt;&amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;</iframe>
TuDienTiengViet.Net
Image 7 Image 8
<iframe id="dictFrame" name="dictFrame" height="220" src="about:blank" frameborder="0" width="100%" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> </td></tr><tr align="center"><td width="100%" height="20">©2007 <a href="http://www.tudientiengviet.net" target="_blank"><b>Open Vietnamese Dictionaries Project</b></a></td></tr></tbody></table></fieldset></td></tr></tbody></table></td></tr></tbody></table></div></iframe>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Vietnam Maritime University
Vietnam Vietnam
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPlease want your help dear Pin
Member 1207166719-Oct-15 17:57
Member 1207166719-Oct-15 17:57 
QuestionAbout UNIPEN format and drawing algorithm Pin
Jerry Jin9-Jul-12 21:47
Jerry Jin9-Jul-12 21:47 
QuestionUPV demo Pin
blasphemy2126-Mar-12 21:18
blasphemy2126-Mar-12 21:18 
AnswerRe: UPV demo Pin
Vietdungiitb27-Mar-12 16:28
Vietdungiitb27-Mar-12 16:28 
GeneralMy vote of 5 Pin
Filip D'haene14-Mar-12 7:17
Filip D'haene14-Mar-12 7:17 
GeneralRe: My vote of 5 Pin
Vietdungiitb14-Mar-12 15:31
Vietdungiitb14-Mar-12 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.