Module Expr Str Import alias ImportFrom alias ImportFrom alias Import alias identifier Import alias Import alias Import alias Import alias Import alias FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults body Assign SubscriptStore NameLoad ExtSlice Slice Num NameLoad Slice Num Assign SubscriptStore NameLoad ExtSlice Slice UnaryOpUSub NameLoad Num Assign SubscriptStore NameLoad ExtSlice Slice Slice Num NameLoad Num Assign SubscriptStore NameLoad ExtSlice Slice Slice UnaryOpUSub NameLoad Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Num Num Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr TupleLoad Num Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Num BinOpDiv AttributeLoad NameLoad attr Num Num NameLoad BinOpMult NameLoad Num Num Assign NameStore BinOpMult NameLoad Num Assign NameStore BinOpSub NameLoad NameLoad Assign NameStore BinOpMult NameLoad Num Assign NameStore BinOpSub NameLoad NameLoad If CompareNotEq NameLoad NameLoad body For NameStore SubscriptLoad NameLoad Index Num body Assign NameStore TupleLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore TupleLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore Call AttributeLoad NameLoad attr BinOpSub SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num BinOpSub SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign NameStore BinOpMult BinOpDiv Num AttributeLoad NameLoad attr NameLoad If BoolOpAnd CompareGt NameLoad Num CompareLt NameLoad Num body If BoolOpAnd BoolOpOr CompareLtE SubscriptLoad NameLoad Index Num NameLoad CompareGtE SubscriptLoad NameLoad Index Num NameLoad BoolOpOr CompareLtE SubscriptLoad NameLoad Index Num NameLoad CompareGtE SubscriptLoad NameLoad Index Num NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Num NameLoad If BoolOpAnd CompareGt NameLoad Num CompareLt NameLoad Num body If BoolOpAnd BoolOpOr CompareLtE SubscriptLoad NameLoad Index Num NameLoad CompareGtE SubscriptLoad NameLoad Index Num NameLoad BoolOpOr CompareLtE SubscriptLoad NameLoad Index Num NameLoad CompareGtE SubscriptLoad NameLoad Index Num NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Num NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr If CompareEq NameLoad NameLoad body Print Str NameLoad Str Assign NameStore NameLoad Return NameLoad orelse Print Str NameLoad Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Num Num BinOpBitOr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore NameLoad Assign NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad NameLoad If BoolOpOr Call AttributeLoad NameLoad attr Str Call AttributeLoad NameLoad attr Str body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Num Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Num Num AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad If CompareNotEq Call AttributeLoad NameLoad attr NameLoad Num body Assign NameStore SubscriptLoad NameLoad ExtSlice Slice Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr NameLoad Slice Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr NameLoad orelse Assign NameStore NameLoad Assign NameStore Num Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad TupleLoad NameLoad NameLoad NameLoad Num Num AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Num Num AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Call NameLoad BinOpMult NameLoad NameLoad Call NameLoad BinOpMult NameLoad NameLoad Call NameLoad BinOpMult NameLoad NameLoad Call NameLoad BinOpMult NameLoad NameLoad AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr TupleLoad Num Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list If CompareEq NameLoad Str body Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str keyword NameLoad Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str keyword NameLoad Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str keyword Str keyword NameLoad Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str keyword Num keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr Print Str AttributeLoad NameLoad attr Print Str AttributeLoad NameLoad attr Print Str AttributeLoad NameLoad attr Print Str AttributeLoad NameLoad attr Print BinOpAdd AttributeLoad NameLoad attr Str Expr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr
N/A N/A 
###################################################################################################
Title: ICR Preprocessor
Purpose: Prepare an image of a single hand written character for OCR recognition by applying OpenCV-based filters
Initial version written by: Hasan SHEIKH FARIDUL / Ari Shomair
v0.1 - 5 Mar 2013----

Usage: 
----------
>python preprocessor.py -o original.png-d ~path_for_outputilename.png

Input:
----------
image = An scan image of a single handwritten character

Output:
----------
result.png = a post-processed image which is better suited for the needs of the OCR engine

Dependencies: 
Python 2.7
OpenCV2
scipy
numpy
math
zhangsuen python module

################################################################################################### 
 N/A cv2 sys argv scipy stats N/A numpy np N/A sys N/A os N/A math N/A argparse N/A zhangsuen border_removal N/A N/A box_bw top bottom right left N/A N/A N/A N/A box_bw N/A N/A 0 top N/A 255 N/A N/A box_bw N/A N/A N/A bottom 255 N/A N/A box_bw N/A N/A N/A 0 left 255 N/A N/A box_bw N/A N/A N/A N/A right 255 N/A box_bw N/A remove_line N/A N/A box_bw line_thickness N/A N/A N/A edges N/A N/A cv2 Canny box_bw 80 120 N/A N/A r c N/A N/A np shape box_bw N/A element N/A N/A cv2 getStructuringElement N/A cv2 MORPH_CROSS N/A 1 1 N/A edges N/A N/A cv2 dilate edges element N/A min N/A N/A np minimum r c N/A lines N/A N/A cv2 HoughLinesP edges 1 N/A N/A math pi 2 2 None N/A min 0.75 1 N/A r_low_lim N/A r 0.1 N/A r_high_lim N/A r r_low_lim N/A c_low_lim N/A c 0.1 N/A c_high_lim N/A c c_low_lim N/A N/A lines None N/A N/A line N/A lines N/A 0 N/A N/A pt1 N/A N/A line N/A 0 N/A line N/A 1 N/A pt2 N/A N/A line N/A 2 N/A line N/A 3 N/A theta_radian2 N/A N/A np arctan2 N/A N/A line N/A 2 N/A line N/A 0 N/A N/A line N/A 3 N/A line N/A 1 N/A theta_deg2 N/A N/A 180 N/A math pi theta_radian2 N/A N/A N/A theta_deg2 85 N/A theta_deg2 95 N/A N/A N/A N/A N/A N/A line N/A 1 r_low_lim N/A N/A line N/A 1 r_high_lim N/A N/A N/A line N/A 3 r_low_lim N/A N/A line N/A 3 r_high_lim N/A N/A N/A N/A cv2 line box_bw pt1 pt2 255 line_thickness N/A N/A N/A theta_deg2 175 N/A theta_deg2 185 N/A N/A N/A N/A N/A N/A line N/A 0 c_low_lim N/A N/A line N/A 0 c_high_lim N/A N/A N/A line N/A 2 c_low_lim N/A N/A line N/A 2 c_high_lim N/A N/A N/A N/A cv2 line box_bw pt1 pt2 255 line_thickness N/A box_bw N/A preprocessor N/A N/A original destination noise_removal remove_border_size N/A N/A N/A original_image N/A N/A cv2 imread original N/A cv2 CV_LOAD_IMAGE_GRAYSCALE N/A N/A original_image None N/A N/A original image file =  original   cant be read!!! Check File name. N/A return_value None N/A return_value N/A N/A original file =  original   is read N/A N/A thresh box_bw N/A N/A cv2 threshold original_image 128 255 N/A N/A cv2 THRESH_BINARY N/A cv2 THRESH_OTSU N/A top remove_border_size N/A bottom remove_border_size N/A right remove_border_size N/A left remove_border_size N/A box_bw_border_free N/A border_removal box_bw top bottom right left N/A N/A N/A N/A noise_removal startswith Y N/A N/A noise_removal startswith y N/A N/A box_bw_border_free N/A N/A cv2 medianBlur box_bw_border_free 3 N/A N/A thresh In_bw N/A N/A cv2 threshold box_bw_border_free 128 255 N/A cv2 THRESH_BINARY N/A inverted_In_bw N/A N/A np invert In_bw N/A N/A i j N/A N/A np nonzero inverted_In_bw N/A N/A N/A N/A np size i 0 N/A N/A Out_cropped N/A box_bw_border_free N/A N/A N/A N/A np min i N/A N/A np max i N/A N/A N/A np min j N/A N/A np max j N/A N/A Out_cropped box_bw_border_free N/A width 35 N/A height 35 N/A Ithin_resized N/A N/A cv2 resize Out_cropped N/A width height None 0 0 N/A cv2 INTER_LANCZOS4 N/A N/A thresh Ithin_resized_thresh N/A N/A cv2 threshold Ithin_resized 200 255 N/A cv2 THRESH_BINARY N/A box_bw_thinned N/A N/A zhangsuen thin Ithin_resized_thresh False False False N/A border_width 0.1 N/A box_bw_thinned_bordered N/A N/A cv2 copyMakeBorder box_bw_thinned N/A int N/A height border_width N/A int N/A height border_width N/A int N/A width border_width N/A int N/A width border_width N/A cv2 BORDER_CONSTANT value 255 N/A struc_element N/A N/A cv2 getStructuringElement N/A cv2 MORPH_RECT N/A 5 5 N/A Output N/A N/A cv2 erode box_bw_thinned_bordered struc_element N/A N/A N/A cv2 imwrite destination Output N/A N/A N/A __name__ __main__ N/A N/A parser N/A N/A argparse ArgumentParser N/A N/A N/A parser add_argument -o action store dest original help Original File Name required True N/A N/A N/A parser add_argument -d action store dest destination help Destination File Name required True N/A N/A N/A parser add_argument -n action store dest noise_removal help noise remove?(Y/N) default Y required False N/A N/A N/A parser add_argument -b action store dest remove_border_size help border removal size in pixel default 5 required False N/A results N/A N/A parser parse_args N/A Original Image = N/A results original N/A Destination Image = N/A results destination N/A noise remove?=  N/A results noise_removal N/A Border removal size=  N/A results remove_border_size N/A N/A N/A results destination !!!
 N/A N/A preprocessor N/A results original N/A results destination N/A results noise_removal N/A int N/A results remove_border_size