Esempio n. 1
0
 def calibrate_image(self):
     logger.log("calibrating image")
     global image_update_flag
     image_update_flag = False
     try:
         img = Shooter.get_img()
         ImageProcess.calibrate_board(img)
     except Exception as ex:
         logger.log("cannot calibrate image" + str(ex),error=True)
     image_update_flag = True
Esempio n. 2
0
 def calibrate_image(self):
     logger.log("calibrating image")
     global image_update_flag
     image_update_flag = False
     try:
         img = Shooter.get_img()
         ImageProcess.calibrate_board(img)
     except Exception as ex:
         logger.log("cannot calibrate image" + str(ex), error=True)
     image_update_flag = True
Esempio n. 3
0
 def calc_image(self):
     try:
         self.ui.imgNormal = self.img
         self.ui.imgEdges = self.img
         self.table = ImageProcess.frame_table(self.img, False)
         self.ui.imgNormal = ImageProcess.trimmed
         self.ui.imgEdges = ImageProcess.edgesImage
         self.ui.updateImage()
     #print "New image"
     except Exception as ex:
         logger.log("cannot calculate image" + str(ex), error=True)
Esempio n. 4
0
 def calc_image(self):
     try:
         self.ui.imgNormal = self.img
         self.ui.imgEdges = self.img
         self.table = ImageProcess.frame_table(self.img, False)
         self.ui.imgNormal = ImageProcess.trimmed
         self.ui.imgEdges = ImageProcess.edgesImage
         self.ui.updateImage()
     #print "New image"
     except Exception as ex:
         logger.log("cannot calculate image" + str(ex), error=True)
Esempio n. 5
0
    def configButton_click(self):
        import MainApp.conf as Conf

        log("opening configuration window")
        ui = configWindow.configWindow(self)
        ui.WorkingThread = self.thread
        ui.lineEdit.setText(config.get("IP"))
        ui.colorThresholdVal.setValue(int(config.get("threshold")))
        ui.p1.setValue(int(Conf.get("param1")))
        ui.p2.setValue(int(Conf.get("param2")))
        if ui.exec_():
            config.set("IP", ui.lineEdit.text())
            config.set("threshold", ui.colorThresholdVal.value())
Esempio n. 6
0
def check_game_end(table, ui):
    res = table.gameWon()
    if res != 0:
        if res == 1:
            log("AI won!")
            print "AI won!"
        else:
            log("Human won!")
            print "Human won!"
        log("game ended in %d turns" % turns)
        print "In", turns, "turns."
        return True
    return False
Esempio n. 7
0
def check_game_end(table, ui):
    res = table.gameWon()
    if res != 0:
        if res == 1:
            log("AI won!")
            print "AI won!"
        else:
            log("Human won!")
            print "Human won!"
        log("game ended in %d turns" % turns)
        print "In", turns, "turns."
        return True
    return False
Esempio n. 8
0
def move(table, ui):
    global a, turns
    #img = Image.take_photo()
    #b = proc.frame_table(img, False)
    (After, move) = a.boardFromCamera(table)

    #print "points: ",boardPoints(table)

    if move is not None:
        s = movesListToString(move)
        ui.add_move(s)
        print "OK"
        log("move OK")
        bads = 0
        a = After
        ok = 1

        sys.stdout.write("Turn " + str(turns))
        turns += 1

        if check_game_end(a, ui): return True

        log("calculating move... ", line=False, time=False)
        res = minimaks(copy.deepcopy(a), 6)  #was 6
        log("done")
        print "White:", res, res[1]

        s = movesListToString(res[1], True)
        send(res[1])
        ui.add_move(s)
        a.executeMove(res[1])
        print "After Move:\n", a
    else:
        log("bad move", error=True)
        #print "Bad Move! Try again!\nPrevious board:"
        #print a
        #print "Actual board:"
        #print table

    if check_game_end(a, ui): return True
    return False
Esempio n. 9
0
def move(table, ui):
    global a, turns
    #img = Image.take_photo()
    #b = proc.frame_table(img, False)
    (After, move) = a.boardFromCamera(table)

    #print "points: ",boardPoints(table)

    if move is not None:
        s = movesListToString(move)
        ui.add_move(s)
        print "OK"
        log("move OK")
        bads = 0
        a = After
        ok = 1

        sys.stdout.write("Turn " + str(turns))
        turns += 1

        if check_game_end(a, ui): return True

        log("calculating move... ", line=False,time=False)
        res = minimaks(copy.deepcopy(a), 6)  #was 6
        log("done")
        print "White:", res, res[1]

        s = movesListToString(res[1], True)
        send(res[1])
        ui.add_move(s)
        a.executeMove(res[1])
        print "After Move:\n", a
    else:
        log("bad move",error=True)
        #print "Bad Move! Try again!\nPrevious board:"
        #print a
        #print "Actual board:"
        #print table

    if check_game_end(a, ui): return True
    return False
Esempio n. 10
0
def take_photo():
    import MainApp.conf as Conf
    import urllib

    global success

    log("Connecting... ",line=False)

    try:
        urllib.urlretrieve("http://" + str(Conf.get('IP')) + ":8080/shot.jpg", "shot.jpg")
    except Exception as ex:
        success = False
        log("Cannot connect!" + str(ex), error=True,time=False)
        return False
    else:
        log("OK",False)
        success = True
        return True
Esempio n. 11
0
def take_photo():
    import MainApp.conf as Conf
    import urllib

    global success

    log("Connecting... ", line=False)

    try:
        urllib.urlretrieve("http://" + str(Conf.get('IP')) + ":8080/shot.jpg",
                           "shot.jpg")
    except Exception as ex:
        success = False
        log("Cannot connect!" + str(ex), error=True, time=False)
        return False
    else:
        log("OK", False)
        success = True
        return True
Esempio n. 12
0
def set_position(table):
    global a
    log("Board set")
    a = table
Esempio n. 13
0
 def nxtControlButton_click(self):
     log("opening NXT window")
     ui = nxtWindow.nxtWindow(self)
     ui.exec_()
Esempio n. 14
0
 def new_move(self):
     log("making move")
     self.thread.new_move()
Esempio n. 15
0
def set_position(table):
    global a
    log("Board set")
    a = table
Esempio n. 16
0
        global image_update_flag
        image_update_flag = False
        try:
            img = Shooter.get_img()
            ImageProcess.calibrate_board(img)
        except Exception as ex:
            logger.log("cannot calibrate image" + str(ex), error=True)
        image_update_flag = True


if __name__ == "__main__":
    app = QApplication(sys.argv)

    global ui
    ui = mainWindow.mainWindow()
    ui.show()

    logger.register_ui(ui)

    th = Worker(ui)

    ui.use_thread(th)

    th.start()

    logger.log("Starting app")
    x = app.exec_()
    #th.terminate()
    Shooter.timer_stop()
    logger.log("app end")
    sys.exit(x)
Esempio n. 17
0
        global image_update_flag
        image_update_flag = False
        try:
            img = Shooter.get_img()
            ImageProcess.calibrate_board(img)
        except Exception as ex:
            logger.log("cannot calibrate image" + str(ex),error=True)
        image_update_flag = True


if __name__ == "__main__":
    app = QApplication(sys.argv)

    global ui
    ui = mainWindow.mainWindow()
    ui.show()

    logger.register_ui(ui)

    th = Worker(ui)

    ui.use_thread(th)

    th.start()

    logger.log("Starting app")
    x = app.exec_()
    #th.terminate()
    Shooter.timer_stop()
    logger.log("app end")
    sys.exit(x)