<s> from skimage . transform import pyramid_gaussian <EOL> from skimage . io import imread <EOL> from skimage . feature import hog <EOL> from sklearn . externals import joblib <EOL> import cv2 <EOL> import argparse as ap <EOL> from nms import nms <EOL> from config import * <EOL> def sliding_window ( image , window_size , step_size ) : <EOL> '''<STR_LIT>''' <EOL> for y in xrange ( <NUM_LIT:0> , image . shape [ <NUM_LIT:0> ] , step_size [ <NUM_LIT:1> ] ) : <EOL> for x in xrange ( <NUM_LIT:0> , image . shape [ <NUM_LIT:1> ] , step_size [ <NUM_LIT:0> ] ) : <EOL> yield ( x , y , image [ y : y + window_size [ <NUM_LIT:1> ] , x : x + window_size [ <NUM_LIT:0> ] ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = ap . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , "<STR_LIT>" , help = "<STR_LIT>" , required = True ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , default = <NUM_LIT> , <EOL> type = int ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" ) <EOL> args = vars ( parser . parse_args ( ) ) <EOL> im = imread ( args [ "<STR_LIT:image>" ] , as_grey = False ) <EOL> min_wdw_sz = ( <NUM_LIT:100> , <NUM_LIT> ) <EOL> step_size = ( <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> downscale = args [ '<STR_LIT>' ] <EOL> visualize_det = args [ '<STR_LIT>' ] <EOL> clf = joblib . load ( model_path ) <EOL> detections = [ ] <EOL> scale = <NUM_LIT:0> <EOL> for im_scaled in pyramid_gaussian ( im , downscale = downscale ) : <EOL> cd = [ ] <EOL> if im_scaled . shape [ <NUM_LIT:0> ] < min_wdw_sz [ <NUM_LIT:1> ] or im_scaled . shape [ <NUM_LIT:1> ] < min_wdw_sz [ <NUM_LIT:0> ] : <EOL> break <EOL> for ( x , y , im_window ) in sliding_window ( im_scaled , min_wdw_sz , step_size ) : <EOL> if im_window . shape [ <NUM_LIT:0> ] != min_wdw_sz [ <NUM_LIT:1> ] or im_window . shape [ <NUM_LIT:1> ] != min_wdw_sz [ <NUM_LIT:0> ] : <EOL> continue <EOL> fd = hog ( im_window , orientations , pixels_per_cell , cells_per_block , visualize , normalize ) <EOL> pred = clf . predict ( fd ) <EOL> if pred == <NUM_LIT:1> : <EOL> print "<STR_LIT>" . format ( x , y ) <EOL> print "<STR_LIT>" . format ( scale , clf . decision_function ( fd ) ) <EOL> detections . append ( ( x , y , clf . decision_function ( fd ) , <EOL> int ( min_wdw_sz [ <NUM_LIT:0> ] * ( downscale ** scale ) ) , <EOL> int ( min_wdw_sz [ <NUM_LIT:1> ] * ( downscale ** scale ) ) ) ) <EOL> cd . append ( detections [ - <NUM_LIT:1> ] ) <EOL> if visualize_det : <EOL> clone = im_scaled . copy ( ) <EOL> for x1 , y1 , _ , _ , _ in cd : <EOL> cv2 . rectangle ( clone , ( x1 , y1 ) , ( x1 + im_window . shape [ <NUM_LIT:1> ] , y1 + <EOL> im_window . shape [ <NUM_LIT:0> ] ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , thickness = <NUM_LIT:2> ) <EOL> cv2 . rectangle ( clone , ( x , y ) , ( x + im_window . shape [ <NUM_LIT:1> ] , y + <EOL> im_window . shape [ <NUM_LIT:0> ] ) , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) , thickness = <NUM_LIT:2> ) <EOL> cv2 . imshow ( "<STR_LIT>" , clone ) <EOL> cv2 . waitKey ( <NUM_LIT:30> ) <EOL> scale += <NUM_LIT:1> <EOL> clone = im . copy ( ) <EOL> for ( x_tl , y_tl , _ , w , h ) in detections : <EOL> cv2 . rectangle ( im , ( x_tl , y_tl ) , ( x_tl + w , y_tl + h ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , thickness = <NUM_LIT:2> ) <EOL> cv2 . imshow ( "<STR_LIT>" , im ) <EOL> cv2 . waitKey ( ) <EOL> detections = nms ( detections , threshold ) <EOL> for ( x_tl , y_tl , _ , w , h ) in detections : <EOL> cv2 . rectangle ( clone , ( x_tl , y_tl ) , ( x_tl + w , y_tl + h ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , thickness = <NUM_LIT:2> ) <EOL> cv2 . imshow ( "<STR_LIT>" , clone ) <EOL> cv2 . waitKey ( ) </s>
