Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Neural Network OCR

Rate me:
Please Sign up or sign in to vote.
4.91/5 (155 votes)
11 Aug 2005GPL310 min read 1.1M   46.3K   388  
Some ideas about optical character recognition using neural networks.
// AForge Math Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.Math
{
	using System;
	
	/// <summary>
	/// Complex number
	/// </summary>
	public struct Complex
	{
		public float	Re;		// real component
		public float	Im;		// imaginary component
		
		// Get zero value
		public static Complex Zero
		{
			get { return new Complex(0, 0); }
		}
		
		// Get magnitude (absolute) value
		public float Magnitude
		{
			get { return (float) System.Math.Sqrt(Re * Re + Im * Im); }
		}

		// Get phase value
		public float Phase
		{
			get { return (float) System.Math.Atan(Im / Re); }
		}
		
		// Get squred magnitude value
		public float SquaredMagnitude
		{
			get { return (Re * Re + Im * Im); }
		}
	
	
		// Constructors
		public Complex(float re, float im)
		{
			this.Re = re;
			this.Im = im;
		}
		public Complex(Complex c)
		{
			this.Re = c.Re;
			this.Im = c.Im;
		}
		
		// Get complex number as string
		public override string ToString()
		{
			return String.Format("{0}{1}{2}i", Re, ((Im < 0) ? '-' : '+'), Math.Abs(Im));
		}
		
		// Add two complex numbers
		public static Complex operator+(Complex a, Complex b)
		{
			return new Complex(a.Re + b.Re, a.Im + b.Im);
		}

		// Subtract two complex numbers
		public static Complex operator-(Complex a, Complex b)
		{
			return new Complex(a.Re - b.Re, a.Im - b.Im);
		}
		
		// Multiply two complex numbers
		public static Complex operator*(Complex a, Complex b)
		{
			return new Complex(
				a.Re * b.Re - a.Im * b.Im,
				a.Re * b.Im + a.Im * b.Re);
		}

		// Divide one complex number by another
		public static Complex operator/(Complex a, Complex b)
		{
			float divider = b.Re * b.Re + b.Im * b.Im;
			
			if (divider == 0)
				throw new DivideByZeroException();
		
			return new Complex(
				(a.Re * b.Re + a.Im * b.Im) / divider,
				(a.Im * b.Re - a.Re * b.Im) / divider);
		}
	}
}

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)


Written By
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, Computer Vision Sandbox, cam2web, ANNT, etc.

Comments and Discussions