title: Extract Specific block of text from image using OCR in python
body: <p>I want to target specific area of image to extract some specific block of text from image using OCR in python. i have already written some code which extracts text from image but i don't need everything on that image, like i have a chinese ID card which has name, date of birth, address and the ID number on it and i want to extract only the name which is on top of the ID card and the ID number which is at the bottom of image.This is the code i have written so far.</p>
  
  <pre><code>import cv2
  import numpy as np
  from PIL import Image
  import pytesseract
  import argparse
  import os
  
  test_image = cv2.imread("E:/sh.jpg")
  
  gray = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
  dilated_img = cv2.dilate(gray, np.ones((5, 5)), iterations=1)
  bg_img = cv2.medianBlur(dilated_img, 23)
  
  #--- finding absolute difference to preserve edges ---
  diff_img = 255 - cv2.absdiff(test_image[:,:,1], bg_img)
  
  #--- normalizing between 0 to 255 ---
  norm_img = cv2.normalize(diff_img, None, alpha=0, beta=255, 
  norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
  cv2.imshow('norm_img', cv2.resize(norm_img, (0, 0), fx = 0.5, fy = 0.5))
  
  #--- Otsu threshold ---
  th = cv2.threshold(norm_img, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
  cv2.imshow('th', cv2.resize(th, (0, 0), fx = 0.5, fy = 0.5))
  
  filename = "{}.png".format(os.getpid())
  cv2.imwrite(filename,th)
  
  text = pytesseract.image_to_string(Image.open(filename), lang='chi_sim')
  print(text)
  os.remove(filename)
  
  cv2.waitKey(0)
  </code></pre>
  
  <p>Kindly help me if anyone have any solution in mind.
  <a href="https://i.stack.imgur.com/BZkOf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BZkOf.jpg" alt="This is the image from which i am trying to extract text"></a></p>