示例#1
0
def test_xanadoku_sudokus(sudoku_doc):
    if not sudoku_doc.get('verified'):
        assert True
    else:
        print(sudoku_doc.get('_id'))
        image = download_image(sudoku_doc.get('raw_image_url'))
        predictions, sudoku, subimage = extract_sudoku(image, classifier(), force=True)
        parsed_sudoku = predictions_to_suduko_string(predictions, oneliner=True)
        if parsed_sudoku != sudoku_doc.get('parsed_sudoku'):
            predictions, sudoku, subimage = extract_sudoku(image.rotate(-90), classifier(), force=True)
            parsed_sudoku = predictions_to_suduko_string(predictions, oneliner=True)
        assert parsed_sudoku == sudoku_doc.get('parsed_sudoku')
示例#2
0
def test_url_1_straight():
    url = "https://static-secure.guim.co.uk/sys-images/Guardian/Pix/pictures/2013/2/27/1361977880123/Sudoku2437easy.jpg"
    image = download_image(url)
    solution = ("041006029\n"
                "300790000\n"
                "009000308\n"
                "800604290\n"
                "070050060\n"
                "036108007\n"
                "403000900\n"
                "000032004\n"
                "650400730")
    _process_an_image(image, solution)
示例#3
0
def test_url_1_straight():
    url = "https://static-secure.guim.co.uk/sys-images/Guardian/Pix/pictures/2013/2/27/1361977880123/Sudoku2437easy.jpg"
    image = download_image(url)
    solution = ("041006029\n"
                "300790000\n"
                "009000308\n"
                "800604290\n"
                "070050060\n"
                "036108007\n"
                "403000900\n"
                "000032004\n"
                "650400730")
    _process_an_image(image, solution)
示例#4
0
def fetch_all_xanadoku_images(folder_to_store_in, api_token):
    import json
    doc = json.loads(urlopen("https://xanadoku.herokuapp.com/getallsudokus/{0}".format(
        api_token)).read().decode('utf8'))
    for d in doc.get('sudokus'):
        if not d.get('verified'):
            continue
        print("Saving {0}...".format(d.get('_id')))
        img = download_image(d.get('raw_image_url'))
        with open(os.path.join(os.path.abspath(os.path.expanduser(
                folder_to_store_in)), d.get('_id') + '.jpg'), 'w') as f:
            img.save(f)
        with open(os.path.join(os.path.abspath(os.path.expanduser(
                folder_to_store_in)), d.get('_id') + '.txt'), 'w') as f:
            f.writelines([d.get('parsed_sudoku')[i:i+9] + '\n' for i in range(0, len(d.get('parsed_sudoku')), 9)])
示例#5
0
def main():
    import argparse
    parser = argparse.ArgumentParser(description="Running SudokuExtract as a command line tool")
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-p', '--path', dest='path', type=str, default=None, help="Path to an image to parse.")
    group.add_argument('-u', '--url', dest='url', type=str, default=None, help="Url to an image to parse.")
    parser.add_argument('--oneliner', action='store_true', help="Print oneliner solution.")

    args = parser.parse_args()

    if args.path is not None:
        image = load_image(args.path)
    else:
        image = download_image(args.url)

    preds, images, subimage = extract_sudoku(image)
    sudoku_string = predictions_to_suduko_string(preds, args.oneliner)
    print(sudoku_string)
示例#6
0
def test_xanadoku_sudokus(sudoku_doc):
    if not sudoku_doc.get('verified'):
        assert True
    else:
        print(sudoku_doc.get('_id'))
        image = download_image(sudoku_doc.get('raw_image_url'))
        predictions, sudoku, subimage = extract_sudoku(image,
                                                       classifier(),
                                                       force=True)
        parsed_sudoku = predictions_to_suduko_string(predictions,
                                                     oneliner=True)
        if parsed_sudoku != sudoku_doc.get('parsed_sudoku'):
            predictions, sudoku, subimage = extract_sudoku(image.rotate(-90),
                                                           classifier(),
                                                           force=True)
            parsed_sudoku = predictions_to_suduko_string(predictions,
                                                         oneliner=True)
        assert parsed_sudoku == sudoku_doc.get('parsed_sudoku')
示例#7
0
def fetch_all_xanadoku_images(folder_to_store_in, api_token):
    import json
    doc = json.loads(
        urlopen("https://xanadoku.herokuapp.com/getallsudokus/{0}".format(
            api_token)).read().decode('utf8'))
    for d in doc.get('sudokus'):
        if not d.get('verified'):
            continue
        print("Saving {0}...".format(d.get('_id')))
        img = download_image(d.get('raw_image_url'))
        with open(
                os.path.join(
                    os.path.abspath(os.path.expanduser(folder_to_store_in)),
                    d.get('_id') + '.jpg'), 'w') as f:
            img.save(f)
        with open(
                os.path.join(
                    os.path.abspath(os.path.expanduser(folder_to_store_in)),
                    d.get('_id') + '.txt'), 'w') as f:
            f.writelines([
                d.get('parsed_sudoku')[i:i + 9] + '\n'
                for i in range(0, len(d.get('parsed_sudoku')), 9)
            ])
示例#8
0
from sudokuextract.extract import extract_sudoku
from sudokuextract.ml import fit
from sudokuextract.utils import download_image, load_image

from sudokuextract import data
#images, labels, X, y = data.create_mnist_dataset()
#data.save_training_data(X, y, data_source='mnist')
#images, labels, X, y = data.create_data_set_from_images('~/Documents/SudokuExtract_Train', force=True)
#data.save_training_data(X, y, data_source='se')

#data.fetch_all_xanadoku_images('~/Documents/SudokuExtract_Test', 'bjornbar')

#image_url = "https://static-secure.guim.co.uk/sys-images/Guardian/Pix/pictures/2013/2/27/1361977880123/Sudoku2437easy.jpg"
the_image = download_image(
    "https://res.cloudinary.com/hzlcxa6rf/image/upload/56d9d0df9f94ac0009519152"
)

#the_image = load_image('~/Documents/SudokuExtract_Test/56d9aad9ae834500099af4da.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e006a63e921a0009d40071.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e0053e3e921a0009d40070.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e0a6237303ae0009e9a994.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Train/i1.png')
#the_image = load_image('tests/img18.jpg')

#the_image = the_image.rotate(-90)

preds, sudoku, subimage = extract_sudoku(the_image, force=True)

import matplotlib.pyplot as plt
ax = plt.subplot2grid((9, 9 + 9), (0, 0), colspan=9, rowspan=9)
示例#9
0
from __future__ import absolute_import

from sudokuextract.extract import extract_sudoku
from sudokuextract.ml import fit
from sudokuextract.utils import download_image, load_image

from sudokuextract import data
#images, labels, X, y = data.create_mnist_dataset()
#data.save_training_data(X, y, data_source='mnist')
#images, labels, X, y = data.create_data_set_from_images('~/Documents/SudokuExtract_Train', force=True)
#data.save_training_data(X, y, data_source='se')

#data.fetch_all_xanadoku_images('~/Documents/SudokuExtract_Test', 'bjornbar')

#image_url = "https://static-secure.guim.co.uk/sys-images/Guardian/Pix/pictures/2013/2/27/1361977880123/Sudoku2437easy.jpg"
the_image = download_image("https://res.cloudinary.com/hzlcxa6rf/image/upload/56d9d0df9f94ac0009519152")

#the_image = load_image('~/Documents/SudokuExtract_Test/56d9aad9ae834500099af4da.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e006a63e921a0009d40071.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e0053e3e921a0009d40070.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Test/56e0a6237303ae0009e9a994.jpg')
#the_image = load_image('~/Documents/SudokuExtract_Train/i1.png')
#the_image = load_image('tests/img18.jpg')

#the_image = the_image.rotate(-90)

preds, sudoku, subimage = extract_sudoku(the_image, force=True)

import matplotlib.pyplot as plt
ax = plt.subplot2grid((9, 9+9), (0, 0), colspan=9, rowspan=9)
ax.imshow(subimage, plt.cm.gray)