コード例 #1
0
ファイル: bot.py プロジェクト: Varal7/Set-Solver
def handle_cards(update, filename):
    # Read cards
    queue = Queue()
    im, contours = card.get_im_contours(filename)
    contours = card.filter_cards_contours(contours)
    update.message.reply_text("I can see " + str(len(contours)) + " cards")
    update.message.reply_text("Not sure what they are, though")
    update.message.reply_text("Let me see...")
    trained = card.load_trained()
    cards = []
    for contour in contours:
        worker = SetWorker(update, queue, im, trained, cards)
        worker.daemon = True
        worker.start()

    for contour in contours:
        queue.put(contour)

    queue.join()
    contours, cards = zip(*cards)
    update.message.reply_text("Here's what I got:")
    update.message.reply_text(
        functools.reduce(lambda x, y: x + "," + y, map(str, cards)))

    my_set = set.Set(im, contours, cards)
    prefix = os.path.basename(filename).split(".")[0]
    filenames = my_set.save_sets(SAVE_FOLDER, prefix)
    return filenames
コード例 #2
0
def train(photos_folder, train_folder):
    for filename in os.listdir(photos_folder):
        extension = os.path.splitext(filename)[1]
        if extension.lower() not in EXTENSIONS:
            continue
        print(filename)
        photo_path = os.path.join(photos_folder, filename)
        dest_path = os.path.join(train_folder, filename)
        im, contours = card.get_im_contours(photo_path)
        my_card = card.Card(im, contours[0])
        prep_shape = my_card.prep_shape
        cv2.imwrite(dest_path, prep_shape)
    print("Done")
コード例 #3
0
ファイル: main.py プロジェクト: Varal7/Set-Solver
def handle_cards(filename):
    # Read cards
    im, contours = card.get_im_contours(filename)
    contours = card.filter_cards_contours(contours)
    trained = card.load_trained()
    cards = []
    for contour in contours:
        my_card = card.Card(im, contour)
        my_card.predict(trained)
        cards.append(my_card)
        print(my_card)
    # Compute sets
    my_set = set.Set(im, contours, cards)
    # Show sets
    # my_set.show_sets()
    # Write sets
    prefix = os.path.basename(args.filename).split(".")[0]
    filenames = my_set.save_sets("save", prefix)
    return filenames
コード例 #4
0
ファイル: parallel.py プロジェクト: Varal7/Set-Solver
def handle_cards(filename):
    cards = []
    queue = Queue()
    im, contours = card.get_im_contours(filename)
    contours = card.filter_cards_contours(contours)
    trained = card.load_trained()
    for contour in contours:
        worker = DownloadWorker(queue, im, trained, cards)
        worker.daemon = True
        worker.start()
    for contour in contours:
        queue.put(contour)

    queue.join()
    contours, cards = zip(*cards)

    # Compute sets
    my_set = set.Set(im, contours, cards)
    # Show sets
    my_set.show_sets()
    # Write sets
    prefix = os.path.basename(args.filename).split(".")[0]
    filenames = my_set.save_sets("save", prefix)
    return filenames
コード例 #5
0
ファイル: main.py プロジェクト: Varal7/Set-Solver
def print_card(filename):
    im, contours = card.get_im_contours(filename)
    trained = card.load_trained()
    my_card = card.Card(im, contours[0])
    my_card.predict(trained)
    print(my_card)