def initPockets(self, emptyImageList ): ''' generates the pocket objects with default data ''' self.pockets = {} for col in range(0, self.gridsize.x): for row in range(0, self.gridsize.y): pointTL = self._PointTL + point( col*self.pocketsize, row*self.pocketsize) self.pockets[(col, row)] = pocket( pointTL, emptyImageList[(col, row)] )
def testSetValue(self): bigImage = numpy.zeros((pocketSize * 10, pocketSize * 10, 3), numpy.float32) p = pocket(offsetPoint, smallBlackImage) p.setValue('X') self.assertEqual(p.value, 'X') p.ShowValue((0, 0, 255), bigImage)
def testGetImage(self): p = pocket(offsetPoint, smallBlackImage) subimage = p.getImage(bigWhiteImage) expectedSubImage = bigWhiteImage[offsetPoint.y:offsetPoint.y + pocketSize, offsetPoint.x:offsetPoint.x + pocketSize, :] self.assertTrue(numpy.array_equal(subimage, expectedSubImage))
def testDrawrectangle(self): color = (0, 0, 255) p = pocket(offsetPoint, smallBlackImage) bigImage = numpy.zeros((pocketSize * 10, pocketSize * 10, 3), numpy.float32) p.ShowBoundary(color, bigImage) # yes, x and y are inverted... self.assertEqual(bigImage[offsetPoint.y, offsetPoint.x][0], color[0]) self.assertEqual(bigImage[offsetPoint.y, offsetPoint.x][1], color[1]) self.assertEqual(bigImage[offsetPoint.y, offsetPoint.x][2], color[2])
def testIsEmpty(self): p = pocket(offsetPoint, smallBlackImage) # it is empty if "emptyimage" is located at the offset, ie. all black self.assertTrue(p.isEmpty(bigBlackImage)) self.assertFalse(p.isEmpty(bigWhiteImage))
def testPocket(self): p = pocket(offsetPoint, smallBlackImage) self.assertEqual(p.pointTopLeft, offsetPoint) self.assertEqual(p.pointBottomRight, offsetPoint + point(pocketSize - 1, pocketSize - 1)) pass