Ejemplo n.º 1
0
    def __init__(self, boardsize):
        self.boardsize = boardsize

        self.mask = dict()
        self.config = dict()

        self.boardRecognizer = BoardRecognizer()
        self.pieceRecognizer = PieceRecognizer(self.boardsize)
Ejemplo n.º 2
0
    def getBoardState(self):
        recognizer = BoardRecognizer(0)

        try:
            board = recognizer.getBoardState()
            return board
        except Exception as e:
            print "An error occured"
            print e
Ejemplo n.º 3
0
    def getBoardState(self):
        recognizer = BoardRecognizer(0)

        try:
            board = recognizer.getBoardState()
            return board
        except Exception as e:
            print "An error occured"
            print e
Ejemplo n.º 4
0
    def test(self):
        full_path = os.path.realpath(__file__)
        path, filename = os.path.split(full_path)

        recognizer = BoardRecognizer(path + '/tests/test-1.avi')

        while True:
            print recognizer.getBoardState()

            if cv2.waitKey(10) == ord('q'):
                break
Ejemplo n.º 5
0
    def test(self):
        full_path = os.path.realpath(__file__)
        path, filename = os.path.split(full_path)

        recognizer = BoardRecognizer(path + '/tests/test-1.avi')

        while True:
            print recognizer.getBoardState()

            if cv2.waitKey(10) == ord('q'):
                break
Ejemplo n.º 6
0
class Recognizer:
    def __init__(self, boardsize):
        self.boardsize = boardsize

        self.mask = dict()
        self.config = dict()

        self.boardRecognizer = BoardRecognizer()
        self.pieceRecognizer = PieceRecognizer(self.boardsize)

    def initcapture(self, n):
        cap = cv2.VideoCapture(n)

        # This settings are to always set webcam resolution to maximum
        cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 2000)
        cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 2000)

        print "Capturing from: {}".format(n)
        print "Frame Size: ", cap.get(3), "x", cap.get(4)

        self.cap = cap
        return cap.isOpened()

    def initrefdata(self, path):
        file = open(path, 'r')
        refdata = yaml.load(file.read())
        self.refBoard = refdata['board']
        print "Ref data:"
        print refdata

    def endcapture(self):
        self.cap.release()

    def setconfig(self, config):
        self.config = config
        self.boardRecognizer.setmask(config['mask'])

    def getconfig(self):
        return self.config

    def getframe(self):
        _, frame = self.cap.read()
        return frame

    def getboardstate(self, frame):
        self.frame = frame

        boardfound, self.board = self.boardRecognizer.processframe(frame)
        if boardfound:
            self.pieceRecognizer.findpiecesonboard(self.board)
            return self.pieceRecognizer.board_representation