diff --git a/src/image_analyzer.py b/src/image_analyzer.py --- a/src/image_analyzer.py +++ b/src/image_analyzer.py @@ -1,22 +1,26 @@ -from go import * +import logging +from go import * class ImageAnalyzer: - def __init__(self): + def __init__(self,tresB=30,tresW=60): self.board=[[Go.EMPTY]*19 for r in range(19)] self.grid=None - def analyze(self,image,tresB,tresW,sizeCoef,shift): + self.tresB=tresB + self.tresW=tresW + + def analyze(self,image,sizeCoef,shift): if self.grid==None: return False for r in range(19): for c in range(19): intersection=self.grid.intersections[r][c] - self.board[r][c]=self.analyzePoint(image,intersection*sizeCoef+shift,*(self.grid.stoneSizeAt(r,c,sizeCoef)),tresB,tresW) + self.board[r][c]=self.analyzePoint(image,r,c,intersection*sizeCoef+shift,*(self.grid.stoneSizeAt(r,c,sizeCoef))) - def analyzePoint(self,image,imageCoords,stoneWidth,stoneHeight,tresB,tresW): + def analyzePoint(self,image,row,col,imageCoords,stoneWidth,stoneHeight): b=w=e=0 ((x1,y1),(x2,y2))=self.relevantRect(imageCoords,stoneWidth,stoneHeight) @@ -28,10 +32,12 @@ class ImageAnalyzer: I=(red+green+blue)/255/3 m=min(red,green,blue) S=1-m/I - if 100*ItresW: w+=1 + if 100*Iself.tresW: w+=1 else: e+=1 + logging.debug("(%d,%d) ... (b=%d,w=%d,e=%d)", row, col, b, w, e) + if b>=w and b>=e: return Go.BLACK if w>=b and w>=e: return Go.WHITE return Go.EMPTY