# HG changeset patch # User Laman # Date 2017-02-26 19:44:00 # Node ID 2bc2ee0a021c587a4e970969868307c02800cc72 # Parent 9fa3f70d50ba46bea01f009207ecf6e61aefe04f fixed imgview resizing, passing tresholds to analyzer, passing new state to core diff --git a/src/core.py b/src/core.py --- a/src/core.py +++ b/src/core.py @@ -14,8 +14,6 @@ class Core: self.grid=None self.go=Go() self.detector=ImageAnalyzer() - self.tresW=60.0 - self.tresB=30.0 self._ownMessages=MsgQueue(self._handleEvent) self._guiMessages=MsgQueue() @@ -33,8 +31,8 @@ class Core: self._guiMessages.send("setGameState",(self.detector.board,)) def setTresholds(self,tresB=None,tresW=None): - if tresB is not None: self.tresB=tresB - if tresW is not None: self.tresW=tresW + if tresB is not None: self.detector.tresB=tresB + if tresW is not None: self.detector.tresW=tresW if self.detector.analyze(self._frame): self._guiMessages.send("setGameState",(self.detector.board,)) diff --git a/src/gui/imgview.py b/src/gui/imgview.py --- a/src/gui/imgview.py +++ b/src/gui/imgview.py @@ -5,7 +5,6 @@ from PIL import ImageTk import config from .resizablecanvas import ResizableCanvas from corners import Corners -from epoint import EPoint from grid import Grid import imageanalyzer @@ -21,7 +20,6 @@ class ImgView(ResizableCanvas): self._img=None self._tkImg=None self._imgSizeCoef=1 - self._imgShift=EPoint(0,0) self.configure(width=480,height=360) self.bind('<1>',lambda e: self.addCorner(e.x,e.y)) @@ -62,21 +60,20 @@ class ImgView(ResizableCanvas): widthRatio=wo/w heightRatio=ho/h self._imgSizeCoef=max(widthRatio,heightRatio) - # shift compensates possible horizontal or vertical empty margins from unmatching aspect ratios - self._imgShift=EPoint(wo-w*self._imgSizeCoef,ho-h*self._imgSizeCoef)/2 self._img=img + self.configure(width=wo,height=ho) ## Stores a grid corner located at x,y coordinates. def addCorner(self,x,y): self._corners.add(x,y) log.debug("click on %d,%d",x,y) - log.debug("sizeCoef: %f, shift: %d,%d",self._imgSizeCoef,self._imgShift.x,self._imgShift.y) + log.debug("sizeCoef: %f",self._imgSizeCoef) if self._corners.canonizeOrder(): # transform corners from show coordinates to real coordinates log.debug(self._corners.corners) self._boardGrid=Grid(self._corners.corners) - corners=[(c*self._imgSizeCoef+self._imgShift) for c in self._corners.corners] + corners=[(c*self._imgSizeCoef) for c in self._corners.corners] self._parent.sendMsg("setCorners",(corners,)) self.redraw() diff --git a/src/imageanalyzer.py b/src/imageanalyzer.py --- a/src/imageanalyzer.py +++ b/src/imageanalyzer.py @@ -26,6 +26,7 @@ class ImageAnalyzer: self.board[r][c]=self.analyzePoint(image,r,c,intersection,*(self.grid.stoneSizeAt(r,c))) log.info("board analyzed:\n%s", exportBoard(self.board)) + return True def analyzePoint(self,image,row,col,imageCoords,stoneWidth,stoneHeight): b=w=e=0