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
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
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)
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())
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
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
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
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
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
def set_position(table): global a log("Board set") a = table
def nxtControlButton_click(self): log("opening NXT window") ui = nxtWindow.nxtWindow(self) ui.exec_()
def new_move(self): log("making move") self.thread.new_move()
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)
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)