<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import cv2 <EOL> import itertools as it <EOL> from common import draw_str <EOL> w , h = <NUM_LIT> , <NUM_LIT> <EOL> def toint ( p ) : <EOL> return tuple ( map ( int , p ) ) <EOL> def sample_line ( p1 , p2 , n , noise = <NUM_LIT:0.0> ) : <EOL> p1 = np . float32 ( p1 ) <EOL> t = np . random . rand ( n , <NUM_LIT:1> ) <EOL> return p1 + ( p2 - p1 ) * t + np . random . normal ( size = ( n , <NUM_LIT:2> ) ) * noise <EOL> dist_func_names = it . cycle ( '<STR_LIT>' . split ( ) ) <EOL> cur_func_name = dist_func_names . next ( ) <EOL> def update ( _ = None ) : <EOL> noise = cv2 . getTrackbarPos ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> n = cv2 . getTrackbarPos ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> r = cv2 . getTrackbarPos ( '<STR_LIT>' , '<STR_LIT>' ) / <NUM_LIT> <EOL> outn = int ( n * r ) <EOL> p0 , p1 = ( <NUM_LIT> , <NUM_LIT> ) , ( w - <NUM_LIT> , h - <NUM_LIT> ) <EOL> img = np . zeros ( ( h , w , <NUM_LIT:3> ) , np . uint8 ) <EOL> cv2 . line ( img , toint ( p0 ) , toint ( p1 ) , ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> if n > <NUM_LIT:0> : <EOL> line_points = sample_line ( p0 , p1 , n - outn , noise ) <EOL> outliers = np . random . rand ( outn , <NUM_LIT:2> ) * ( w , h ) <EOL> points = np . vstack ( [ line_points , outliers ] ) <EOL> for p in line_points : <EOL> cv2 . circle ( img , toint ( p ) , <NUM_LIT:2> , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) , - <NUM_LIT:1> ) <EOL> for p in outliers : <EOL> cv2 . circle ( img , toint ( p ) , <NUM_LIT:2> , ( <NUM_LIT:64> , <NUM_LIT:64> , <NUM_LIT:255> ) , - <NUM_LIT:1> ) <EOL> func = getattr ( cv2 , cur_func_name ) <EOL> vx , vy , cx , cy = cv2 . fitLine ( np . float32 ( points ) , func , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> cv2 . line ( img , ( int ( cx - vx * w ) , int ( cy - vy * w ) ) , ( int ( cx + vx * w ) , int ( cy + vy * w ) ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> draw_str ( img , ( <NUM_LIT:20> , <NUM_LIT:20> ) , cur_func_name ) <EOL> cv2 . imshow ( '<STR_LIT>' , img ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print __doc__ <EOL> cv2 . namedWindow ( '<STR_LIT>' ) <EOL> cv2 . createTrackbar ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:3> , <NUM_LIT:50> , update ) <EOL> cv2 . createTrackbar ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:100> , <NUM_LIT> , update ) <EOL> cv2 . createTrackbar ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:30> , <NUM_LIT:100> , update ) <EOL> while True : <EOL> update ( ) <EOL> ch = cv2 . waitKey ( <NUM_LIT:0> ) <EOL> if ch == ord ( '<STR_LIT:f>' ) : <EOL> cur_func_name = dist_func_names . next ( ) <EOL> if ch == <NUM_LIT> : <EOL> break </s>
