diff --git a/src/gui.py b/src/gui.py old mode 100644 new mode 100755 --- a/src/gui.py +++ b/src/gui.py @@ -1,13 +1,14 @@ import tkinter as tk from PIL import ImageTk import PIL -import math -from epoint import * from corners import * from grid import * from image_analyzer import * from go import * +showBigPoints=True +showGrid=False + class Application(tk.Frame): def __init__(self, master=None): @@ -57,10 +58,18 @@ class Application(tk.Frame): ## Redraws the current image and its overlay. def redrawImgView(self): self.imgView.create_image(2,2,anchor="nw",image=self.img) + + origWidth,origHeight=self.imgOrig.size + widthRatio=origWidth/self.img.width() + heightRatio=origHeight/self.img.height() + sizeCoef=max(widthRatio,heightRatio) + tresB=self.scaleTresB.get() + tresW=self.scaleTresW.get() + for corner in self.corners.corners: self.markPoint(corner.x,corner.y) - if self.boardGrid!=None: + if self.boardGrid!=None and showGrid: for r in range(19): a=self.boardGrid.intersections[r][0] b=self.boardGrid.intersections[r][-1] @@ -69,16 +78,15 @@ class Application(tk.Frame): a=self.boardGrid.intersections[0][c] b=self.boardGrid.intersections[-1][c] self.imgView.create_line(a.x,a.y,b.x,b.y,fill='#00ff00') + + if self.boardGrid!=None and showBigPoints: + for r in range(19): + for c in range(19): + ((r1,c1),(r2,c2))=self.boardView.detector.relevantRect(self.boardGrid.intersections[r][c],*(self.boardGrid.stoneSizeAt(r,c,sizeCoef))) + self.imgView.create_rectangle(r1,c1,r2,c2,outline="#00ffff") self.imgView.grid() - origWidth,origHeight=self.imgOrig.size - widthRatio=origWidth/self.img.width() - heightRatio=origHeight/self.img.height() - sizeCoef=max(widthRatio,heightRatio) - tresB=self.scaleTresB.get() - tresW=self.scaleTresW.get() - shift=EPoint(origWidth-self.img.width()*sizeCoef,origHeight-self.img.height()*sizeCoef)/2 self.boardView.redrawState(self.imgOrig,sizeCoef,shift,tresB,tresW) @@ -91,7 +99,7 @@ class Application(tk.Frame): self.imgView.grid() -## Handles and presents the game state as detected by the program. +## Handles and presents the game state as detected by the program. class BoardView(tk.Canvas): def __init__(self, master=None): self.detector=ImageAnalyzer() @@ -99,7 +107,7 @@ class BoardView(tk.Canvas): tk.Canvas.__init__(self, master) self.configure(width=360,height=360,background="#ffcc00") - + self.drawGrid() self.grid() @@ -109,6 +117,9 @@ class BoardView(tk.Canvas): # @param tresB upper intensity treshold for a pixel to be considered black, [0-100] # @param tresW lower intensity treshold for a pixel to be considered white, [0-100] def redrawState(self,img,sizeCoef,shift,tresB,tresW): + self.create_rectangle(0,0,360,360,fill="#ffcc00") + self.drawGrid() + self.detector.analyze(img,tresB,tresW,sizeCoef,shift) for r,row in enumerate(self.detector.board):