Click here to Skip to main content
12,625,395 members (36,850 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

759.6K views
38.3K downloads
362 bookmarked
Posted

Neural Network OCR

, 11 Aug 2005 GPL3
Some ideas about optical character recognition using neural networks.
// Neural Network OCR
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

using System;

namespace NeuroOCR
{
	/// <summary>
	/// Summary description for Receptor.
	/// </summary>
	public class Receptor
	{
		private int		x1, y1, x2, y2;
		private int		left, top, right, bottom;
		private float	k, z;
		private float	a, b, c, d;

		// X1 property
		public int X1
		{
			get { return x1; }
		}
		// Y1 property
		public int Y1
		{
			get { return y1; }
		}
		// X2 property
		public int X2
		{
			get { return x2; }
		}
		// Y2 property
		public int Y2
		{
			get { return y2; }
		}

		// Constructor
		public Receptor(int x1, int y1, int x2, int y2)
		{			
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;

			left	= Math.Min(x1, x2);
			right	= Math.Max(x1, x2);
			top		= Math.Min(y1, y2);
			bottom	= Math.Max(y1, y2);

			if (x1 != x2)
			{
				k = (float) (y2 - y1) / (float) (x2 - x1);
				z = (float) y1 - k * x1;

				a = y1 - y2;
				b = x2 - x1;
				c = y1 * (x1 - x2) + x1 * (y2 - y1);
				d = (float) Math.Sqrt(a * a + b * b);
			}
		}

		// Check receptor state
		public bool GetReceptorState(int x, int y)
		{
			// check, if the point is in receptors bounds
			if ((x < left) || (y < top) || (x > right) || (y > bottom))
				return false;

			// check for horizontal and vertical receptors
			if ((x1 == x2) || (y1 == y2))
				return true;

			// check if the point is on the receptors line

			// more fast, but not very accurate
//			if ((int)(k * x + z - y) == 0)
//				return true;

			// more accurate version
			if (Math.Abs(a * x + b * y + c) / d < 1)
				return true;

			return false;
		}
	}
}

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 IBM
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 and not so open Computer Vision Sandbox.

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 ...

You may also be interested in...

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