Click here to Skip to main content
15,885,757 members
Articles / Artificial Intelligence / Neural Networks

Multiple convolution neural networks approach for online handwriting recognition

Rate me:
Please Sign up or sign in to vote.
4.95/5 (37 votes)
9 Apr 2013CPOL8 min read 76K   25.1K   74  
The research focuses on the presentation of word recognition technique for an online handwriting recognition system which uses multiple component neural networks (MCNN) as the exchangeable parts of the classifier.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;

namespace UPImage.FileFormat
{
    public class UPDataLayout
    {
        List<UPUnipen> upUnipens;
        int iX_Dim;
        int iY_Dim;
        List<int> iH_Line;
        List<int> iV_Line;
        //
        int iUPUnipenID;
        int iStarboxID;
        
        //public parameters
        public List<UPUnipen> UpUnipens
        {
            get
            {
                return upUnipens;
            }
        }
        public int X_Dim
        {
            get
            {
                return iX_Dim;
            }
        }
        public int Y_Dim
        {
            get
            {
                return iY_Dim;
            }
        }
        public List<int> H_Line
        {
            get
            {
                return iH_Line;
            }
        }
        public List<int> V_Line
        {
            get
            {
                return iV_Line;
            }
        }
        //
        public UPDataLayout()
        {
            iX_Dim = -1;
            iY_Dim = -1;
            iH_Line = new List<int>();
            iV_Line = new List<int>();
            iStarboxID = -1;
            upUnipens = new List<UPUnipen>();
            iUPUnipenID = -1;
        }
        public void InitialDataLayout()
        {
        }
        public void SetDataLayoutParameter(UPKEYWORD kw)
        {
            try
            {
                String tempSt;
                switch (kw.keyName)
                {
                    case ".X_DIM":

                        foreach (var s in kw.content_list)
                        {
                            //get X_DIM number
                            if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, ".X_DIM"))
                            {
                                tempSt = s.Substring(s.IndexOf(" ")).Trim();
                                iX_Dim = Convert.ToInt32(tempSt);
                            }
                        }

                        break;
                    case ".Y_DIM":
                        foreach (var s in kw.content_list)
                        {
                            //get Y_DIM number
                            if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, ".Y_DIM"))
                            {
                                tempSt = s.Substring(s.IndexOf(" ")).Trim();
                                iY_Dim = Convert.ToInt32(tempSt);
                                break;
                            }
                        }

                        break;
                    case ".H_LINE":
                        foreach (var s in kw.content_list)
                        {
                            //get H_LINE numbers
                            if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, ".H_LINE"))
                            {
                                tempSt = s.Substring(s.IndexOf(" ")).Trim();
                                //get string list
                                List<string> st_list = new List<string>();
                                UPImage.Common.UpCommonLib.GetWordsFromString(null, tempSt, out st_list);
                                foreach (var st in st_list)
                                {
                                    int i = Convert.ToInt32(st);
                                    iH_Line.Add(i);
                                }
                                break;
                            }
                        }
                        break;
                    case ".V_LINE":
                        foreach (var s in kw.content_list)
                        {
                            //get H_LINE numbers
                            if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, ".V_LINE"))
                            {
                                tempSt = s.Substring(s.IndexOf(" ")).Trim();
                                //get string list
                                List<string> st_list = new List<string>();
                                UPImage.Common.UpCommonLib.GetWordsFromString(null, tempSt, out st_list);
                                foreach (var st in st_list)
                                {
                                    int i = Convert.ToInt32(st);
                                    iV_Line.Add(i);
                                }
                                break;
                            }
                        }
                        break;
                    case ".START_BOX":
                        iStarboxID++;
                        iUPUnipenID = -1;
                        break;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void SetUPUnipen(UPKEYWORD kw, List<UPSEGMENT> segments, int compID)
        {
            switch (kw.keyName)
            {
                case ".PEN_DOWN":
                    //check if Component in segments
                    if (kw.content_list.Count > 1)
                    {
                        if (iStarboxID == -1)
                        {
                            iStarboxID++;
                        }
                     
                        foreach (var sm in segments)
                        {
                            if(sm.ComponentValues.Count>0)
                            {
                                if (sm.ComponentValues[0].ComponentID == compID)
                                {
                                    //component is belong to a Unipen
                                    UPUnipen curr_pent = new UPUnipen();
                                    iUPUnipenID++;
                                    curr_pent.InitUPUnipen(kw, sm, iStarboxID, iUPUnipenID);
                                    //add current pen trajectory to list
                                    upUnipens.Add(curr_pent);
                                }
                                
                            }
                        }
                        foreach(var up in upUnipens)
                        {
                            foreach (var cv in up.Segment.ComponentValues)
                            {
                                if (cv.ComponentID==compID)
                                {
                                    up.AddPenTrajectory(kw, cv);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case ".PEN_UP":
                    //check if Component in segments
                    if (kw.content_list.Count > 1)
                    {
                        if (iStarboxID == -1)
                        {
                            iStarboxID++;
                        }

                        foreach (var sm in segments)
                        {
                            if (sm.ComponentValues.Count > 0)
                            {
                                if (sm.ComponentValues[0].ComponentID == compID)
                                {
                                    //component is belong to a Unipen
                                    UPUnipen curr_pent = new UPUnipen();
                                    iUPUnipenID++;
                                    curr_pent.InitUPUnipen(kw, sm, iStarboxID, iUPUnipenID);
                                    //add current pen trajectory to list
                                    upUnipens.Add(curr_pent);
                                 
                                }

                            }
                        }
                        foreach (var up in upUnipens)
                        {
                            foreach (var cv in up.Segment.ComponentValues)
                            {
                                if (cv.ComponentID == compID)
                                {
                                    up.AddPenTrajectory(kw, cv);
                                    break;
                                }
                            }
                        }
                    }
                    break;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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