def testRecognizer(bus, boardsize): print("Testing my eyesight") recognizer = Recognizer(boardsize) board = recognizer.getBoardState() print board print "Terminating" return
def configurerecognizerwithimage(boardsize, filename): recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) display = Display() display.initdisplay() img = cv2.imread('BoardRecognizer/tests/' + filename + '.png') recognizer.initrefdata('BoardRecognizer/tests/' + filename + '.yml') pieces = recognizer.getboardstate(img) print ''.join(pieces) checkPieces = [] for row in recognizer.refBoard: for tile in row: checkPieces.append(tile) for i in range(32): if pieces[i] == checkPieces[i]: checkPieces[i] = ' ' print 'Recognized:' + ' '.join(pieces) print 'Reference: ' + ' '.join(checkPieces) while True: display.showframe(img) annotateboard(recognizer.board, recognizer.pieceRecognizer.means, pieces) display.showboard(recognizer.board) key = cv2.waitKey(0) if key > 0: break display.enddisplay()
def saveboard(boardsize, img_path, dest_path): recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) img = cv2.imread('BoardRecognizer/tests/' + img_path + '.png') recognizer.initrefdata('BoardRecognizer/tests/' + img_path + '.yml') recognizer.getboardstate(img) splitter = BoardSplitter(boardsize) refBoard = recognizer.refBoard tiles = splitter.get_tiles(recognizer.board) for i in range(32): x = getcol(i) y = getrow(i) cv2.imwrite( dest_path + str(img_path) + ' ' + str(x) + '-' + str(y) + '-' + str(refBoard[i // 4][i % 4]) + ".jpg", tiles[x][y])
def saveboard(boardsize, img_path, dest_path): recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) img = cv2.imread('BoardRecognizer/tests/' + img_path + '.png') recognizer.initrefdata('BoardRecognizer/tests/' + img_path + '.yml') recognizer.getboardstate(img) splitter = BoardSplitter(boardsize) refBoard = recognizer.refBoard tiles = splitter.get_tiles(recognizer.board) for i in range(32): x = getcol(i) y = getrow(i) cv2.imwrite(dest_path + str(img_path) + ' ' + str(x) + '-' + str(y) + '-' + str(refBoard[i//4][i%4]) + ".jpg", tiles[x][y])
def getthresholdsfromimg(boardsize, filename): recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) recognizer.initdisplay() img = cv2.imread('BoardRecognizer/tests/' + filename + '.png') recognizer.initrefdata('BoardRecognizer/tests/' + filename + '.yml') checkPieces = [] for row in recognizer.refBoard: for tile in row: checkPieces.append(tile) _, board = recognizer.boardRecognizer.processframe(img) means = recognizer.pieceRecognizer.getmeansfromboard(board) # Browns means = list( map(lambda (_, x): x, filter(lambda (x, _): not iswhite(x, boardsize), enumerate(means)))) blackthres = 0 whitethres = 255 minempty = 255 maxempty = 0 for i in range(32): print checkPieces[i] + ": " + str(means[i]) piece = checkPieces[i] if piece == 'w': whitethres = means[i] if means[i] < whitethres else whitethres elif piece == 'b': blackthres = means[i] if means[i] > blackthres else blackthres else: minempty = means[i] if means[i] < minempty else minempty maxempty = means[i] if means[i] > maxempty else maxempty print 'blackThres: ' + str(blackthres) print 'whiteThres: ' + str(whitethres) print 'Empty: ' + str(minempty) + ' - ' + str(maxempty)
def getthresholdsfromimg(boardsize, filename): recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) recognizer.initdisplay() img = cv2.imread('BoardRecognizer/tests/' + filename + '.png') recognizer.initrefdata('BoardRecognizer/tests/' + filename + '.yml') checkPieces = [] for row in recognizer.refBoard: for tile in row: checkPieces.append(tile) _, board = recognizer.boardRecognizer.processframe(img) means = recognizer.pieceRecognizer.getmeansfromboard(board) # Browns means = list( map(lambda (_, x): x, filter(lambda (x, _): not iswhite(x, boardsize), enumerate(means) ) ) ) blackthres = 0 whitethres = 255 minempty = 255 maxempty = 0 for i in range(32): print checkPieces[i] + ": " + str(means[i]) piece = checkPieces[i] if piece == 'w': whitethres = means[i] if means[i] < whitethres else whitethres elif piece == 'b': blackthres = means[i] if means[i] > blackthres else blackthres else: minempty = means[i] if means[i] < minempty else minempty maxempty = means[i] if means[i] > maxempty else maxempty print 'blackThres: '+str(blackthres) print 'whiteThres: '+str(whitethres) print 'Empty: '+str(minempty)+' - '+str(maxempty)
def testrecognizer(boardsize, filename): print("Testing my eyesight") recognizer = Recognizer(boardsize) recognizer.setconfig(config['recognizer']) display = Display() # Load the test movie recognizer.initcapture('BoardRecognizer/tests/' + filename + '.avi') display.initdisplay() while True: frame = recognizer.getframe() print recognizer.getboardstate(frame) display.showframe(frame) recognizer.endcapture() display.enddisplay() config['recognizer'] = recognizer.getconfig()