# HG changeset patch # User Laman # Date 2015-11-23 22:05:03 # Node ID fc8be31ce773e6503ecf8c4703860a731527ead4 # Parent 2ee338a32bcf795eaf3271f033b0f7aedaceab6a added intensity slider diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -1,1 +1,2 @@ -^src/__pycache__/ \ No newline at end of file +^src/__pycache__/ +^\.idea/ \ No newline at end of file diff --git a/readme.md b/readme.md --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Modules: * Watcher: interpreting sequence of game positions as a sequence of moves. * Broadcaster: interfacing with a go server. -Written for Python 3.4.3. Dependencies: Pillow 2.7.0, NumPy 1.9.2. Start gui.py to run. +Written for Python 3.5.0. Dependencies: Pillow 2.7.0, NumPy 1.10.0. Start gui.py to run. Licensed under GNU GPL v2.0 or later. See license.txt. Relicensing possible, don't hesitate to ask. diff --git a/src/corners.py b/src/corners.py --- a/src/corners.py +++ b/src/corners.py @@ -44,6 +44,9 @@ class Corners: # For four points ABCD, there are 24 possible permutations corresponding to the desired KLMN. # When we relax the condition of K being the upper left one, we get six groups of four equivalent permutations. KLMN ~ LMNK ~ MNKL ~ NKLM. # + # We determine which of the points' triplets are oriented clockwise and which counter-clockwise (minus/plus in the table below) + # and swap them so that all triangles turn counter-clockwise. + # # xxxx -> KLMN | ABC | ABD | ACD | BCD | index | swap # ------------ | :-: | :-: | :-: | :-: | ----: | ---- # A BCD | + | + | + | + | 15 | 0 @@ -69,7 +72,7 @@ class Corners: if any(x==0 for x in (abc,abd,acd,bcd)): return False # collinear degenerate swaps=[(1,3),(0,1),(1,2),(0,3),(2,3),(0,0)] - index=(8 if abc>0 else 0)+(4 if abd>0 else 0)+(2 if acd>0 else 0)+(1 if bcd>0 else 0) + index=(8 if abc>0 else 0)|(4 if abd>0 else 0)|(2 if acd>0 else 0)|(1 if bcd>0 else 0) if index%3!=0: return False # concave degenerate swap=swaps[index//3] @@ -88,11 +91,3 @@ class Corners: self.corners=self.corners[kIndex:]+self.corners[:kIndex] # rotate the upper left corner to the first place return True # success - -# import itertools -# points=[(10,8),(8,10),(12,10),(10,12)] -# for perm in itertools.permutations(points): - # corn=Corners() - # for p in perm: corn.add(p[0],p[1]) - # print(corn.canonizeOrder()) - # print(corn.corners) diff --git a/src/gui.py b/src/gui.py --- a/src/gui.py +++ b/src/gui.py @@ -33,7 +33,16 @@ class Application(tk.Frame): # board with detected stones self.boardView=BoardView(self) self.boardView.grid(column=1,row=0) - + + # more controls below the board + self.scaleTresB=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=lambda x: self.redrawImgView()) + self.scaleTresW=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=lambda x: self.redrawImgView()) + self.scaleTresB.set(30.0) + self.scaleTresW.set(60.0) + self.scaleTresB.grid(column=0,row=1,columnspan=2) + self.scaleTresW.grid(column=0,row=2,columnspan=2) + + # render everything self.redrawImgView() ## Stores a grid corner located at x,y coordinates. @@ -67,10 +76,12 @@ class Application(tk.Frame): 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) + self.boardView.redrawState(self.imgOrig,sizeCoef,shift,tresB,tresW) ## Marks a point at the image with a green cross. Used for corners. def markPoint(self,x,y): @@ -92,9 +103,13 @@ class BoardView(tk.Canvas): self.drawGrid() self.grid() - - def redrawState(self,img,sizeCoef,shift): - self.detector.analyze(img,30,65,sizeCoef,shift) + + ## Redraws and reananalyzes the board view. + # + # @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.detector.analyze(img,tresB,tresW,sizeCoef,shift) for r,row in enumerate(self.detector.board): for c,point in enumerate(row): diff --git a/src/image_analyzer.py b/src/image_analyzer.py --- a/src/image_analyzer.py +++ b/src/image_analyzer.py @@ -24,8 +24,8 @@ class ImageAnalyzer: def analyzePoint(self,image,imageCoords,stoneWidth,stoneHeight,tresB,tresW): b=w=e=0 - cmax=max(int(stoneWidth*2//5),2) - rmax=max(int(stoneHeight*2//5),2) + cmax=max(int(stoneWidth*2//7),2) # !! optimal parameters subject to further research + rmax=max(int(stoneHeight*2//7),2) for r in range(-rmax,rmax+1): for c in range(-cmax,cmax+1):