python - cv2.floodFill() hanging with certain inputs -


i have loop run through image , flood fill every 20 pixels:

h, w = image.shape[:2] mask = np.zeros((h+2, w+2), np.uint8) mask[:] |= 0 flags = 4 flags |= cv2.floodfill_fixed_range x in range(20,image.shape[1]-20):     y in range(20,image.shape[0]-20):         if x%20 == 0 , y%20 == 0:             print x, y             flooded = image.copy()             print 'starting flood fill'             minval = min(image.item(x,y,0),image.item(x,y,1),image.item(x,y,2))             maxval = max(image.item(x,y,0),image.item(x,y,1),image.item(x,y,2))             size = cv2.floodfill(flooded,mask,(x,y),(0,)*3, (40,)*3, (40,)*3, flags)[0] 

though @ points cv2.floodfill() never completes. if lower lo , hi bounds able process further still stuck. has else had problem?

with image hangs @ pixel (40,400): /users/justin/downloads/images/2015-07-25-12-53-17-img1.png

you should re-initialize mask inside loops each time floodfill modifying it. can improve performance dropping % operators. , fix bug, image.item(x,y,, should image.item(y,x,.

for x in range(20,image.shape[1]-20, 20):     y in range(20,image.shape[0]-20, 20):         print x, y         mask[:] = 0         flooded = image.copy()         print 'starting flood fill'         size = cv2.floodfill(flooded,mask,(x,y),(0,)*3, (40,)*3, (40,)*3, flags)[0] 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -