<s> import cv2 . cv as cv <EOL> class PyrSegmentation : <EOL> def __init__ ( self , img0 ) : <EOL> self . thresh1 = <NUM_LIT:255> <EOL> self . thresh2 = <NUM_LIT:30> <EOL> self . level = <NUM_LIT:4> <EOL> self . storage = cv . CreateMemStorage ( ) <EOL> cv . NamedWindow ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> cv . ShowImage ( "<STR_LIT>" , img0 ) <EOL> cv . NamedWindow ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> cv . CreateTrackbar ( "<STR_LIT>" , "<STR_LIT>" , self . thresh1 , <NUM_LIT:255> , self . set_thresh1 ) <EOL> cv . CreateTrackbar ( "<STR_LIT>" , "<STR_LIT>" , self . thresh2 , <NUM_LIT:255> , self . set_thresh2 ) <EOL> self . image0 = cv . CloneImage ( img0 ) <EOL> self . image1 = cv . CloneImage ( img0 ) <EOL> cv . ShowImage ( "<STR_LIT>" , self . image1 ) <EOL> def set_thresh1 ( self , val ) : <EOL> self . thresh1 = val <EOL> self . on_segment ( ) <EOL> def set_thresh2 ( self , val ) : <EOL> self . thresh2 = val <EOL> self . on_segment ( ) <EOL> def on_segment ( self ) : <EOL> comp = cv . PyrSegmentation ( self . image0 , self . image1 , self . storage , self . level , self . thresh1 + <NUM_LIT:1> , self . thresh2 + <NUM_LIT:1> ) <EOL> cv . ShowImage ( "<STR_LIT>" , self . image1 ) <EOL> def run ( self ) : <EOL> self . on_segment ( ) <EOL> cv . WaitKey ( <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> img0 = cv . LoadImage ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> PyrSegmentation ( img0 ) . run ( ) <EOL> cv . DestroyAllWindows ( ) </s>
