Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

Neural Network OCR

, 11 Aug 2005
Some ideas about optical character recognition using neural networks.
neuroocr_demo.zip
AForge.Imaging.dll
AForge.Math.dll
AForge.NeuralNet.dll
NeuroOCR.exe
SourceGrid2.dll
SourceLibrary.dll
neuroocr_src.zip
AForge
Math
Math.csproj.user
NeuralNet
Learning
NeuralNet.csproj.user
NeuroOCR
App.ico
NeuroOCR.csproj.user
References
AForge.Imaging.dll
SourceGrid2.dll
SourceLibrary.dll
namespace NeuroOCR
{
	using System;
	using System.ComponentModel;
	
	using SourceGrid2.Cells.Virtual;

	/// <summary>
	/// Summary description for GridIntArray.
	/// </summary>
	public class GridArray : SourceGrid2.GridVirtual
	{
		private CellVirtual	columnHeader;
		private CellVirtual	rowHeader;
		private CellVirtual	cellHeader;
		private CellVirtual	dataCell;
		private Array		array;
		private bool		readOnly = false;

		// Readonly property
		[DefaultValue(false)]
		public bool ReadOnly
		{
			get { return readOnly; }
			set
			{
				readOnly = value;
				RefreshCellsStyle();
			}
		}

		// Constructor
		public GridArray()
		{
		}

		// Load data
		public void LoadData(Array array)
		{
			//
			this.array = array;

			// set column and row headers
			FixedRows = 1;
			FixedColumns = 1;

			// Redim the grid
			Redim(array.GetLength(0) + FixedRows, array.GetLength(1) + FixedColumns);

			// Col Header Cell Template
			columnHeader = new CellColumnHeaderTemplate();
			columnHeader.BindToGrid(this);

			// Row Header Cell Template
			rowHeader = new CellRowHeaderTemplate();
			rowHeader.BindToGrid(this);

			// Header Cell Template (0,0 cell)
			cellHeader = new CellHeaderTemplate();
			cellHeader.BindToGrid(this);

			// Data Cell Template
			dataCell = new CellArrayTemplate(array);;
			dataCell.BindToGrid(this);

			RefreshCellsStyle();
		}

		// Return the Cell at the specified Row and Col position
		public override SourceGrid2.Cells.ICellVirtual GetCell(int row, int col)
		{
			try
			{
				if (array != null)
				{
					if ((row < FixedRows) && (col < FixedColumns))
						return cellHeader;
					else if (row < FixedRows)
						return columnHeader;
					else if (col < FixedColumns)
						return rowHeader;
					else
						return dataCell;
				}
				else
					return null;
			}
			catch(Exception)
			{
				return null;
			}		
		}

		// Set the specified cell int he specified position
		public override void SetCell(int row, int col, SourceGrid2.Cells.ICellVirtual cell)
		{
			throw new ApplicationException("Cannot set cell for this kind of grid");
		}

		// Refresh cells style
		private void RefreshCellsStyle()
		{
			if (dataCell != null)
			{
				dataCell.DataModel.EnableEdit = !readOnly;
			}
		}


		// Column header template
		private class CellColumnHeaderTemplate : SourceGrid2.Cells.Virtual.ColumnHeader
		{
			// Get the value of the cell at the specified position 
			public override object GetValue(SourceGrid2.Position position)
			{
				return position.Column - Grid.FixedColumns;
			}
			// Set the value of the cell at the specified position
			public override void SetValue(SourceGrid2.Position position, object val)
			{
				throw new ApplicationException("Cannot change this kind of cell");
			}
			// Get sort status
			public override SourceGrid2.SortStatus GetSortStatus(SourceGrid2.Position position)
			{
				return new SourceGrid2.SortStatus (SourceGrid2.GridSortMode.None, false);
			}
			// Set sort status
			public override void SetSortMode(SourceGrid2.Position position, SourceGrid2.GridSortMode mode)
			{
			}		
		}

		// Row header template
		private class CellRowHeaderTemplate : SourceGrid2.Cells.Virtual.RowHeader
		{	
			// Get the value of the cell at the specified position
			public override object GetValue(SourceGrid2.Position position)
			{
				return position.Row - Grid.FixedRows;
			}
			// Set the value of the cell at the specified position
			public override void SetValue(SourceGrid2.Position position, object val)
			{
				throw new ApplicationException("Cannot change this kind of cell");
			}		
		}

		// Cell header template
		private class CellHeaderTemplate : SourceGrid2.Cells.Virtual.Header
		{
			// Get the value of the cell at the specified position
			public override object GetValue(SourceGrid2.Position position)
			{
				return null;
			}
			// Set the value of the cell at the specified position
			public override void SetValue(SourceGrid2.Position position, object val)
			{
				throw new ApplicationException("Cannot change this kind of cell");
			}		
		}

		// Cell temlate
		public class CellArrayTemplate : SourceGrid2.Cells.Virtual.CellVirtual
		{
			private Array array;

			// Constructor
			public CellArrayTemplate(Array array)
			{
				this.array = array;
				DataModel = SourceGrid2.Utility.CreateDataModel(array.GetType().GetElementType());
			}
			// Get the value of the cell at the specified position
			public override object GetValue(SourceGrid2.Position position)
			{
				return array.GetValue(position.Row - Grid.FixedRows, position.Column - Grid.FixedColumns);
			}
			// Set the value of the cell at the specified position
			public override void SetValue(SourceGrid2.Position position, object val)
			{
				array.SetValue(val, position.Row - Grid.FixedRows, position.Column-Grid.FixedColumns);
				OnValueChanged(new SourceGrid2.PositionEventArgs(position, this));
			}
		}
	}
}

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 GNU General Public License (GPLv3)

Share

About the Author

Andrew Kirillov
Software Developer (Senior) Cisco Systems
United Kingdom United Kingdom
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET.
 
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid