width = img.size[0] height = img.size[1] is_sign = False split_num = [] for x in range(0, width): check_flag = False for y in range(0, height): pix_data = img.getpixel((x,y)) ifnot (pix_data[0] > 250and pix_data[1] > 250and pix_data[2] > 250): check_flag = True break if is_sign ^ check_flag: split_num.append(int(x)) is_sign = not is_sign sum_num = 0 for block in block_arr: rt_str = '' for num_str in block: for i in range(0, len(split_num)): if int(self.position_dic[num_str]) < split_num[i]: rt_str = rt_str + str(int(i/2)) break