Python - text recognition image

I wrote this code with the premise of recognizing words in an image. This method finds some, but not all, words, as shown in the link.

My code is:

def methods_text_recognition_and_delete(self, path_floorplans, f, path_fw): image = cv2.imread(path_floorplans +f) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # grayscale _, thresh = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV) # threshold kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3)) dilated = cv2.dilate(thresh, kernel, iterations = 1) # dilate contours, hierarchy = cv2.findContours(dilated, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) # get contours # for each contour found, draw a rectangle around it on original image for contour in contours: # get rectangle bounding contour [x, y, w, h] = cv2.boundingRect(contour) # discard areas that are too large if h > 300 and w > 300: continue # discard areas that are too small if h < 10 or w < 10: continue # draw rectangle around contour on original image cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 255), 2) # write original image with added contours to disk cv2.imwrite(path_fw + 'text_recognition_' + f, image) 

Anyone have recommendations on how to improve the quality of this method?

Image example: http://imageshack.com/a/img673/1598/QFaZ3i.png

+6
source share

Source: https://habr.com/ru/post/986180/


All Articles