<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import cv2 <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> try : <EOL> fn = sys . argv [ <NUM_LIT:1> ] <EOL> except : <EOL> fn = '<STR_LIT>' <EOL> print __doc__ <EOL> img = cv2 . imread ( fn , True ) <EOL> if img is None : <EOL> print '<STR_LIT>' , fn <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> h , w = img . shape [ : <NUM_LIT:2> ] <EOL> mask = np . zeros ( ( h + <NUM_LIT:2> , w + <NUM_LIT:2> ) , np . uint8 ) <EOL> seed_pt = None <EOL> fixed_range = True <EOL> connectivity = <NUM_LIT:4> <EOL> def update ( dummy = None ) : <EOL> if seed_pt is None : <EOL> cv2 . imshow ( '<STR_LIT>' , img ) <EOL> return <EOL> flooded = img . copy ( ) <EOL> mask [ : ] = <NUM_LIT:0> <EOL> lo = cv2 . getTrackbarPos ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> hi = cv2 . getTrackbarPos ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> flags = connectivity <EOL> if fixed_range : <EOL> flags |= cv2 . FLOODFILL_FIXED_RANGE <EOL> cv2 . floodFill ( flooded , mask , seed_pt , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) , ( lo , ) * <NUM_LIT:3> , ( hi , ) * <NUM_LIT:3> , flags ) <EOL> cv2 . circle ( flooded , seed_pt , <NUM_LIT:2> , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) , - <NUM_LIT:1> ) <EOL> cv2 . imshow ( '<STR_LIT>' , flooded ) <EOL> def onmouse ( event , x , y , flags , param ) : <EOL> global seed_pt <EOL> if flags & cv2 . EVENT_FLAG_LBUTTON : <EOL> seed_pt = x , y <EOL> update ( ) <EOL> update ( ) <EOL> cv2 . setMouseCallback ( '<STR_LIT>' , onmouse ) <EOL> cv2 . createTrackbar ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT:255> , update ) <EOL> cv2 . createTrackbar ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT:255> , update ) <EOL> while True : <EOL> ch = <NUM_LIT> & cv2 . waitKey ( ) <EOL> if ch == <NUM_LIT> : <EOL> break <EOL> if ch == ord ( '<STR_LIT:f>' ) : <EOL> fixed_range = not fixed_range <EOL> print '<STR_LIT>' % ( '<STR_LIT>' , '<STR_LIT>' ) [ fixed_range ] <EOL> update ( ) <EOL> if ch == ord ( '<STR_LIT:c>' ) : <EOL> connectivity = <NUM_LIT:12> - connectivity <EOL> print '<STR_LIT>' , connectivity <EOL> update ( ) <EOL> cv2 . destroyAllWindows ( ) </s>
