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.

http://i.stack.imgur.com/ky4dh.png

here simple method (but not sure if work everywhere. test yourself)

nb: code in python, don't java, sorry :(

  1. load grayscale image
  2. 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:

enter image description here

now can try 2 methods:

3a. median blurring 3x3 kernel

res = cv2.medianblur(thresh,3)

result:

enter image description here

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:

enter image description here

finally, find contours. pick noise left in preprocessed image, can filter out them checking aspect ratio, area etc.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -