Sharan-Lobana / ImageTextRecognition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImageTextRecognition

Text Detection and Recognition in Natural Images

Pipeline

Conversion from color to gray scale

img = cv2.imread('test2.jpg',0) #0 indicates read in gray scale

Apply MSER algorithm to get regions that probably contain text

Use MSER to extract regions that may contain text. For more information refer to, Wikipedia: (MSER) MAXIMALLY STABLE EXTREMAL REGIONS

mser = cv2.MSER()
regions = mser.detect(img, None)    #detect and extract MSER lasso-contours

Form convex-hulls from the lasso contours

Convex-hulls are formed from the lasso contours

hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]  #take convex-hull of each contour

Convert convex-hulls to bounding rectangles

The convex hulls are converted to bounded rectangles and redundant rectangles that are contained in other rectangles are removed.

x,y,w,h = cv2.boundingRect(hull)    #convert the hull to bounding rectangle

Perform OTSU Binarization

OTSU Binarization of region under rectangle is performed to make the text stand out from the background For more information refer to, Wikipedia: OTSU Binarization

thresh,letter = cv2.threshold(letter,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

For regions getting binarized into black backgrounds and white text, inversion is performed using simple heuristic

Normalize the rectangle to standard size 64x64

Xnorm = [mynormalization(image,(64,64)) for image in X]

About


Languages

Language:Python 100.0%