Text Detection and Recognition in Natural Images
img = cv2.imread('test2.jpg',0) #0 indicates read in gray scale
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
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
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
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
Xnorm = [mynormalization(image,(64,64)) for image in X]