BitArray

http://www.cnblogs.com/lanse777/archive/2007/04/01/695801.html

关于OCR矩阵采用 海明距离 检验相似度的算法实现
将 0 1 2 3 4 5 6 7 8 9 改为直接序列化
为 二进制 而不是 字符串然后求的时候 根据 矩形 算出长度
根据长度
构造一个 二进制数组
将数组根据 RGB 赋值 0 1
这样就有 两个 二进制 数组了
构造两个 BitArray  求 海明距离
然后 海明距离 跟阀值相比 计算相似度
http://www.cnblogs.com/i80386/archive/2012/02/20/2359493.html


using System;

using System.Collections;

public class SamplesBitArray  {



   public static void Main()  {



      // Creates and initializes two BitArrays of the same size.

      BitArray myBA1 = new BitArray( 4 );

      BitArray myBA2 = new BitArray( 4 );

      myBA1[0] = myBA1[1] = false;

      myBA1[2] = myBA1[3] = true;

      myBA2[0] = myBA2[2] = false;

      myBA2[1] = myBA2[3] = true;



      // Performs a bitwise XOR operation between BitArray instances of the same size.

      Console.WriteLine( "Initial values" );

      Console.Write( "myBA1:" );

      PrintValues( myBA1, 8 );

      Console.Write( "myBA2:" );

      PrintValues( myBA2, 8 );

      Console.WriteLine();



      Console.WriteLine( "Result" );

      Console.Write( "XOR:" );

      PrintValues( myBA1.Xor( myBA2 ), 8 );

      Console.WriteLine();



      Console.WriteLine( "After XOR" );

      Console.Write( "myBA1:" );

      PrintValues( myBA1, 8 );

      Console.Write( "myBA2:" );

      PrintValues( myBA2, 8 );

      Console.WriteLine();



      // Performing XOR between BitArray instances of different sizes returns an exception.

      try  {

         BitArray myBA3 = new BitArray( 8 );

         myBA3[0] = myBA3[1] = myBA3[2] = myBA3[3] = false;

         myBA3[4] = myBA3[5] = myBA3[6] = myBA3[7] = true;

         myBA1.Xor( myBA3 );

      } catch ( Exception myException )  {

         Console.WriteLine("Exception: " + myException.ToString());

      }

   }





   public static void PrintValues( IEnumerable myList, int myWidth )  {

      int i = myWidth;

      foreach ( Object obj in myList ) {

         if ( i <= 0 )  {

            i = myWidth;

            Console.WriteLine();

         }

         i--;

         Console.Write( "{0,8}", obj );

      }

      Console.WriteLine();

   }



}





/* 

This code produces the following output.



Initial values

myBA1:   False   False    True    True

myBA2:   False    True   False    True



Result

XOR:   False    True    True   False



After XOR

myBA1:   False    True    True   False

myBA2:   False    True   False    True



Exception: System.ArgumentException: Array lengths must be the same.

   at System.Collections.BitArray.Xor(BitArray value)

   at SamplesBitArray.Main()



*/ 
 
  

 



                            

你可能感兴趣的:(array)