def getBoard(self,im): try: board = Board() y = self.StartY for i in range(0,9): x = self.StartX for j in range(0,9): xx = x+35 yy = y+40 c=0 try: pix = im[xx,yy] c += pix[0] c += pix[1] c += pix[2] except Exception as e: c=0 board.getItems()[i][j].setX(x) board.getItems()[i][j].setY(y) board.getItems()[i][j].setColor(c) x += 71 y+=63 except Exception as e: raise Exception('Error in partionaing image.',e) return board
def getParts(self,input,height,width,i,k): try: board = Board() im = Image.open(input) imgwidth, imgheight = im.size x =0 y = 0 temp1 =0 yAxis =0 for i in range(0,imgheight,height): y =0 temp2 =0 xAxis =0 yAxis =(x+1)*width for j in range(0,imgwidth,width): box = (j+temp2, i-temp1, j+width, (i+abs(temp1))+height) a = im.crop(box) aw,ah = a.size pixel = a.getpixel((aw/2,ah/2)) #if pixel == (0,0,0): #print('empty image') if pixel != (0,0,0): xAxis =(y+1)*height name = os.getcwd()+'\\parts\\'+str(x)+str(y)+'.png' a.save(name) board.getItems()[x][y].setImName(name) board.getItems()[x][y].setX(self.getLeft()+xAxis) board.getItems()[x][y].setY(self.getTop()+yAxis) board.getItems()[x][y].setWidth(width) board.getItems()[x][y].setHeigh(height) y +=1 k +=1 temp2+=1 temp1 -=3 x +=1 except Exception as e: raise Exception('Error in partionaing image.',e) return board