コード例 #1
0
def test_extract_shape_contour_from_binimg():
	binimg1 = [[ 1, 0],
			   [ 0, 0]]

	binimg2 = [[ 0, 0, 0, 0],
			   [ 0, 0, 0, 0],
			   [ 0, 1, 1, 1],
			   [ 0, 1, 1, 0]]

	assert extractShapeContourPathFromBinImg(binimg1) == [Vec2(0,0), Vec2(0,1), Vec2(1,1), Vec2(1,0)]

	assert extractShapeContourPathFromBinImg(binimg2) == [Vec2(1,2), Vec2(1,3), Vec2(1,4), Vec2(2,4),
		Vec2(3,4), Vec2(3,3), Vec2(4,3), Vec2(4,2), Vec2(3,2), Vec2(2,2)]
コード例 #2
0
def test_extract_shape_contour_from_binimg():
    binimg1 = [[1, 0], [0, 0]]

    binimg2 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 1], [0, 1, 1, 0]]

    assert extractShapeContourPathFromBinImg(binimg1) == [
        Vec2(0, 0), Vec2(0, 1), Vec2(1, 1),
        Vec2(1, 0)
    ]

    assert extractShapeContourPathFromBinImg(binimg2) == [
        Vec2(1, 2),
        Vec2(1, 3),
        Vec2(1, 4),
        Vec2(2, 4),
        Vec2(3, 4),
        Vec2(3, 3),
        Vec2(4, 3),
        Vec2(4, 2),
        Vec2(3, 2),
        Vec2(2, 2)
    ]
コード例 #3
0

pygame.init()

size = [640, 640]
screen = pygame.display.set_mode(size)

clock = pygame.time.Clock()
done = False

binImg = imgUtils.getBinImg('img/7.png')
biSize = len(binImg), len(binImg[0])

imgGrid = Grid(len(binImg), len(binImg[0]), Rect(Vec2(0, 0), size[0], size[1]))

path = contour_extraction.extractShapeContourPathFromBinImg(binImg)
poly = optimal_polygon.getOptimalPolygonFromPath(path)

poly2 = [Vec2(v.x * imgGrid.cellWidth, v.y * imgGrid.cellHeight) for v in poly]


def postProcessPolygon(poly):
    n = len(poly)
    lens = 0.0
    for i in xrange(0, n):
        lens += (poly[i] - poly[(i + 1) % n]).norm()

    avg = lens / n

    newPoly = []
    for i in xrange(0, n):
コード例 #4
0
        pygame.draw.line(screen, color, (a.x*grid.cellWidth, a.y*grid.cellHeight), (b.x*grid.cellWidth, b.y*grid.cellHeight))

pygame.init()
 
size = [640, 640]
screen = pygame.display.set_mode(size)
 
clock = pygame.time.Clock()
done = False

binImg = imgUtils.getBinImg('img/1.png')
biSize = len(binImg), len(binImg[0])

imgGrid = Grid(len(binImg), len(binImg[0]), Rect(Vec2(0,0), size[0], size[1]))

path = contour_extraction.extractShapeContourPathFromBinImg(binImg)
poly = optimal_polygon.getOptimalPolygonFromPath(path)

poly2 = [ Vec2(v.x*imgGrid.cellWidth, v.y*imgGrid.cellHeight) for v in poly ]

def postProcessPolygon(poly):
    n = len(poly)
    lens = 0.0
    for i in xrange(0,n):
        lens += (poly[i]-poly[(i+1)%n]).norm()

    avg = lens/n


    newPoly = []
    for i in xrange(0,n):