java - Fill the hole in the image properly -
i have find out contour of image. after that, want find out how fill in hole in number characters, not in other space. image following.
http://i.stack.imgur.com/jllye.jpg
actually, if not possible, there other method me perform segmentation of image using opencv in java platform? want image contains characters only. thankyou.
here simple method (but not sure if work everywhere. test yourself)
nb: code in python, don't java, sorry :(
- load grayscale image
- apply otsu's binarization
import cv2 import numpy np img = cv2.imread('test.png',0) ret, thresh = cv2.threshold(img, 0, 255, cv2.thresh_binary+cv2.thresh_otsu)
below thresholded image:
now can try 2 methods:
3a. median blurring 3x3 kernel
res = cv2.medianblur(thresh,3)
result:
3b. erosion 3x1 kernel (vertical). 3x1 because lines in image more-horizontal. there vertical lines in other images, may need take 3x3 kernel (not sure. check it)
kernel = np.ones((3,1)) cls = cv2.erode(thresh, kernel)
if think losing parts of digits also, can apply dilation after erosion, or replace morphological opening function.
result:
finally, find contours. pick noise left in preprocessed image, can filter out them checking aspect ratio, area etc.
Comments
Post a Comment