title: My own OCR-program in Python
body: <p>I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling.</p>
  
  <pre><code>from PIL import Image
  import numpy as np
  
  im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild_schrift.jpg")
  
  w,h = im.size
  w = int(w)
  h = int(h)
  
  #2D-Array for area
  area = []
  for x in range(w):
      area.append([])
      for y in range(h):
          area[x].append(2) #number 0 is white, number 1 is black
  
  #2D-Array for letter
  letter = []
  for x in range(50):
      letter.append([])
      for y in range(50):
          letter[x].append(0)
  
  #2D-Array for label
  label = []
  for x in range(50):
      label.append([])
      for y in range(50):
          label[x].append(0)
  
  #image to number conversion
  pix = im.load()
  threshold = 200
  for x in range(w):
      for y in range(h):
          aaa = pix[x, y]
          bbb = aaa[0] + aaa[1] + aaa[2] #total value
          if bbb&lt;=threshold:
              area[x][y] = 1
          if bbb&gt;threshold:
              area[x][y] = 0
  np.set_printoptions(threshold='nan', linewidth=10)
  
  #matrix transponation
  ccc = np.array(area) 
  area = ccc.T #better solution?
  
  #find all black pixel and set temporary label numbers
  i=1
  for x in range(40): # width (later)
      for y in range(40): # heigth (later)
          if area[x][y]==1:
              letter[x][y]=1
              label[x][y]=i
              i += 1
  
  #connected components labeling
  for x in range(40): # width (later)
      for y in range(40): # heigth (later)
          if area[x][y]==1:
              label[x][y]=i
              #if pixel has neighbour:
              if area[x][y+1]==1:
                  #pixel and neighbour get the lowest label             
                  pass # tomorrows work
              if area[x+1][y]==1:
                  #pixel and neighbour get the lowest label             
                  pass # tomorrows work            
              #should i also compare pixel and left neighbour?
  
  #find width of the letter
  #find height of the letter
  #find the middle of the letter
  #middle = [width/2][height/2] #?
  #divide letter into 30 parts --&gt; 5 x 6 array
  
  #model letter
  #letter A-Z, a-z, 0-9 (maybe more)
  
  #compare each of the 30 parts of the letter with all model letters
  #make a weighting
  
  #print(letter)
  
  im.save("D:\\Python26\\PYTHON-PROGRAMME\\bild2.jpg")
  print('done')
  </code></pre>