コード例 #1
0
 def __init__(self, a_queue):
     self.a_queue = a_queue
     self.black_model = keras.models.load_model(
         get_absolute_path("../resources/black_model.h5", __file__)
     )
     self.white_model = keras.models.load_model(
         get_absolute_path("../resources/white_model.h5", __file__)
     )
コード例 #2
0
def get_squares_ids() -> dict:
    """
    :return: squares_ids.json as python dict
    """
    with open(get_absolute_path("squares_ids.json", __file__),
              encoding="utf-8") as file:
        return json.loads(file.read())
コード例 #3
0
def get_squares_ids_absolute_paths() -> dict:
    squares_ids: dict = get_squares_ids()
    result: dict = {}
    for square_color, pieces in squares_ids.items():
        for piece, piece_id in pieces.items():
            relative_path = dataset_squares + "/" + square_color + "/" + piece
            result[get_absolute_path(relative_path, __file__)] = piece_id

    return result
コード例 #4
0
    def __init__(self, root, *args, **kwargs):
        tk.Frame.__init__(self, root, *args, **kwargs)

        self.canvas = tk.Canvas(self, width=560, height=560)
        self.canvas.place(x=20, y=20)

        self.board_image = ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/board.jpg", __file__)).resize((560, 560))
        )
        self.canvas.create_image(0, 0, image=self.board_image, anchor=tk.NW)

        self.pieces = load_pieces()
        self.showed_pieces = []
コード例 #5
0
def save_counter(count: int) -> None:
    with open(get_absolute_path("count_diagrams.txt", __file__),
              "w") as counter_file:
        counter_file.write(str(count) + "\n")
コード例 #6
0
def get_counter() -> int:
    with open(get_absolute_path("count_diagrams.txt", __file__),
              "r") as counter_file:
        return int(counter_file.readline().strip())
コード例 #7
0
################################################################################
# Crop 'diagrams' from 'raw_diagrams'
################################################################################
from relative_to_absolute_path import get_absolute_path

import sys

sys.path.insert(0, get_absolute_path("../src", __file__))

import cv2 as cv
from os import listdir, remove
from os.path import isfile, join, exists
from detection import get_diagram_position
################################################################################
################################################################################
# Set paths:
input_dataset: str = get_absolute_path("../datasets/raw_diagrams", __file__)
assert exists(
    input_dataset), "'%s' must be a valid directory path" % input_dataset

output_dataset: str = get_absolute_path("../datasets/unused_diagrams",
                                        __file__)
assert exists(
    output_dataset), "'%s' must be a valid directory path" % output_dataset

################################################################################
################################################################################


# Read 'count' from file
def get_counter() -> int:
コード例 #8
0
def load_pieces() -> dict:
    return {
        4: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bB.png", __file__)).resize((70, 70))
        ),
        6: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bK.png", __file__)).resize((70, 70))
        ),
        3: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bN.png", __file__)).resize((70, 70))
        ),
        1: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bP.png", __file__)).resize((70, 70))
        ),
        5: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bQ.png", __file__)).resize((70, 70))
        ),
        2: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/bR.png", __file__)).resize((70, 70))
        ),
        10: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wB.png", __file__)).resize((70, 70))
        ),
        12: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wK.png", __file__)).resize((70, 70))
        ),
        9: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wN.png", __file__)).resize((70, 70))
        ),
        7: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wP.png", __file__)).resize((70, 70))
        ),
        11: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wQ.png", __file__)).resize((70, 70))
        ),
        8: ImageTk.PhotoImage(
            Image.open(get_absolute_path("../resources/pieces/wR.png", __file__)).resize((70, 70))
        ),
    }
コード例 #9
0
################################################################################
# Use this script to classify unlabeled squares
################################################################################
from relative_to_absolute_path import get_absolute_path
import cv2 as cv
import tkinter as tk
from PIL import Image, ImageTk
import sys
from os import listdir
from os.path import isfile, join, exists
import os

################################################################################
# Set paths:
input_dataset: str = get_absolute_path("../datasets/unlabeled_squares/",
                                       __file__)
assert exists(
    input_dataset), "'%s' must be a valid directory path" % input_dataset

output_dataset: str = get_absolute_path("../datasets/squares/", __file__)
assert exists(
    output_dataset), "'%s' must be a valid directory path" % output_dataset
################################################################################

OPTIONS = [
    "empty", "black_bishop", "black_king", "black_knight", "black_pawn",
    "black_queen", "black_rook", "white_bishop", "white_king", "white_knight",
    "white_pawn", "white_queen", "white_rook"
]

i = 0
コード例 #10
0
################################################################################
# For all diagrams in 'diagrams' crop each square
# and put all squares in 'unlabeled squares'
################################################################################
from relative_to_absolute_path import get_absolute_path
import cv2 as cv
from os import listdir, rename
from os.path import isfile, join, exists

################################################################################
################################################################################
# Set paths:
input_dataset = get_absolute_path("../datasets/unused_diagrams", __file__)
output_dataset_diagrams = get_absolute_path("../datasets/diagrams", __file__)
output_dataset = get_absolute_path("../datasets/unlabeled_squares", __file__)

output_dataset_black = output_dataset + "/black"
assert exists(output_dataset_black
              ), "'%s' must be a valid directory path" % output_dataset_black

output_dataset_white = output_dataset + "/white"
assert exists(output_dataset_white
              ), "'%s' must be a valid directory path" % output_dataset_white

################################################################################
################################################################################


# Read 'count' from file
def get_counter() -> int:
    with open(get_absolute_path("count_squares.txt", __file__),
コード例 #11
0
def main():
    X, Y = get_data()
    save_data_as_csv(X, Y, get_absolute_path(output_file, __file__))
コード例 #12
0
################################################################################
# Print number of files for each dataset
################################################################################
from squares_ids import get_squares_ids_absolute_paths
from relative_to_absolute_path import get_absolute_path
from os import listdir
from os.path import isfile, join, basename

################################################################################
################################################################################
# Set paths:
dataset_diagrams: str = get_absolute_path("../datasets/diagrams", __file__)
################################################################################
################################################################################


def print_status_squares() -> None:
    print("************************************************************")
    print("S Q U A R E S")
    print()
    paths: dict = get_squares_ids_absolute_paths()
    count_all: int = 0

    print("black_square:")
    for path in paths:
        if "black_square" in path:
            number_of_squares = len(
                [f for f in listdir(path) if isfile(join(path, f))])
            count_all += number_of_squares
            print("\t" + basename(path), ":", number_of_squares)
コード例 #13
0
def load_data() -> np.ndarray:
    absolute_path = get_absolute_path(dataset_squares, __file__)
    assert exists(absolute_path), "'%s' must be a valid directory path" % absolute_path
    return np.genfromtxt(absolute_path, delimiter=",", dtype=np.uint8)