Exemplo n.º 1
0
def solve(bot, update):
    file_id = update.message.photo[-1]
    newFile = bot.getFile(file_id)
    newFile.download('download.jpg')
    bot.sendMessage(chat_id=update.message.chat_id, text="Processing...")
    img = imread('download.jpg', IMREAD_GRAYSCALE)
    json_file = open(args.model + '.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    model = model_from_json(loaded_model_json)
    model.load_weights(args.model + '.h5')
    grid = get_grid(img, model, method='cnn')
    B = Board(9, grid)
    # print(B.grid)
    solution_img(B.solution().T, B.grid.T, 'solution.png')
    bot.send_photo(chat_id=update.message.chat_id,
                   photo=open('solution.png', 'rb'))
Exemplo n.º 2
0
def save_generated_dataset(folder, number, randfont=True):
    ''' Save <number> of pictures in the given <folder>s orig subfolder and data as data.csv '''
    y = np.zeros((number, 81), int)
    for i in range(number):
        picname = folder + 'orig/grid' + str(i).zfill(4) + '.png'
        B = Board(9)
        grid = B.solution()
        fonts = [
            'arial.ttf', 'arialbd.ttf', 'APHont-Regular_q15c.ttf',
            'APHont-Bold_q15c.ttf', 'Hack.ttf', 'DejaVuSansMono-Bold.ttf',
            'DroidSerif-Regular.ttf', 'OpenSans-Bold.ttf'
        ]
        if randfont:
            font = ImageFont.truetype('fonts/' + choice(fonts), size=45)
        else:
            font = ImageFont.truetype('fonts/APHont-Regular_q15c.ttf', size=45)
        draw_matrix(grid, picname, frame=True, font=font)
        y[i] = grid.reshape(81)
    np.savetxt(folder + 'data.csv', y, delimiter=',', fmt='%d')