def testLocator(self):
image = mk_img(400, 600)
# draw a rectangle
A = (5, 5)
B = (5, 300)
C = (250, 5)
D = (250, 300)
ABCD = Polygon([A, B, D, C, A])
image = draw_poly(image, ABCD)
# locate it
locator = BinaryLocator()
located = locator.locate(image)
polygons, labels = zip(*located)
self.assertEqual(1, len(located), "One polygon found")
self.assertTrue(ABCD.equals(polygons[0]), "Found polygon has the same shape")
# test locate with an offset
locator2 = BinaryLocator()
located2 = locator2.locate(image, offset=(50, 40))
polygons2, labels2 = zip(*located2)
self.assertEqual(1, len(located2), "One polygon found")
self.assertTrue(translate(ABCD, 50, 40).equals(polygons2[0]), "Found translated polygon")
评论列表
文章目录