keras # 26:from keras.models models model_from_json numpy np pandas pd PIL Image pickle os model_path weight_path image_path new_width input_shape add_mergin # XXXX:def add_mergin(img, mergin): img mergin mergin img_new np ones img shape mergin img shape mergin dtype np uint8 img_new mergin mergin mergin mergin img img_new img img_new pickleload # XXXX:def pickleload( path open path mode f data pickle load f data json_string open model_path read model model_from_json json_string model load_weights weight_path char_list_path char_list pd read_csv char_list_path encoding len char_list char_list char_list char_list char_list char_list as_matrix k v enumerate char_list v space k space mergin input_shape img Image open image_path orig_width orig_height img size new_width new_width orig_width new_height int img size new_width img size img img resize new_width new_height Image LANCZOS img np array img len img shape img img img_new np ones img shape mergin img shape mergin dtype np uint8 img_new mergin mergin new_height mergin mergin new_width img img img_new astype np float32 char_dict_path char_dict pickleload char_dict_path len char_dict output_dir os path isdir output_dir os makedirs output_dir slide range slide num_line img shape input_shape img_width img shape new_line np ones img_width img np concatenate new_line img axis predicts text h range num_line w penalty predict_line text_line w img_width input_shape input_img img h h input_shape w w input_shape input_img input_img reshape input_shape input_shape predict model predict input_img penalty predict space predict np argmax predict penalty predict space char char_list predict predict_line append char char_width char_dict char shape w char_width text_line char predicts append predict_line text append text_line img_aa np ones_like img dtype np uint8 h range num_line w char predicts h char_width char_dict char shape char_img char_dict char astype np uint8 img_aa h h w w char_width char_img w char_width img_aa Image fromarray img_aa img_aa img_aa crop slide new_width new_height slide save_path output_dir os path basename image_path str new_width str slide img_aa save save_path f open save_path f writelines text f close