title: OpenCV MSER detect text areas - Python
body: <p>I have an invoice image, and I want to detect the text on it. So I plan to use 2 steps: first is to identify the text areas, and then using OCR to recognize the text.</p>
  <p>I am using OpenCV 3.0 in python for that. I am able to identify the text(including some non text areas) but I further want to identify text boxes from the image(also excluding the non-text areas).</p>
  <p>My input image is:</p>
  <p><img src="https://i.stack.imgur.com/5Bvzv.jpg" alt="Original" /></p>
  <p>And the output is:</p>
  <p><img src="https://i.stack.imgur.com/2uCSQ.jpg" alt="Processed" /></p>
  <p>I am using the below code for this:</p>
  <pre><code>img = cv2.imread('/home/mis/Text_Recognition/bill.jpg')
  mser = cv2.MSER_create()
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Converting to GrayScale
  gray_img = img.copy()
  
  regions = mser.detectRegions(gray, None)
  hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
  cv2.polylines(gray_img, hulls, 1, (0, 0, 255), 2)
  cv2.imwrite('/home/mis/Text_Recognition/amit.jpg', gray_img) #Saving
  </code></pre>
  <p>Now, I want to identify the text boxes, and remove/unidentify any non-text areas on the invoice. I am new to OpenCV and am a beginner in Python. I am able to find some examples in <a href="https://in.mathworks.com/help/vision/examples/automatically-detect-and-recognize-text-in-natural-images.html" rel="nofollow noreferrer">MATAB example</a> and <a href="https://stackoverflow.com/questions/23506105/extracting-text-opencv">C++ example</a>, but If I convert them to python, it will take a lot of time for me.</p>
  <p>Is there any example with python using OpenCV, or can anyone help me with this?</p>