Beispiel #1
0
def test_canvas_to_cv2():

    # Make sure that the conversion works for different input types.
    assert np.allclose(canvas_to_cv2([1, 2]), [2, 1])
    assert np.allclose(canvas_to_cv2((1, 2)), [2, 1])
    assert np.allclose(canvas_to_cv2(np.array([10, 11])), [11, 10])
    assert np.allclose(canvas_to_cv2(np.array([[1, 2], [3, 4]])),
                       [[2, 1], [4, 3]])
Beispiel #2
0
def test_invalid_canvas_to_cv2():

    with pytest.raises(MorphacLogicError):
        _ = canvas_to_cv2([1, 2, 3])
    with pytest.raises(MorphacLogicError):
        _ = canvas_to_cv2((1, 2, 3))
    with pytest.raises(MorphacLogicError):
        _ = canvas_to_cv2(np.zeros(3))
    with pytest.raises(MorphacLogicError):
        _ = canvas_to_cv2(np.zeros((3, 3)))
Beispiel #3
0
def paint_polygon_using_canvas_coords(canvas, canvas_coords, color):
    # Interchanging x and y while drawing as opencv points requires the x and
    # y axes to be the regular axes, with the origin at the top left.

    # fillPoly needs the input coordinates in a weird format.
    coords = [canvas_to_cv2(canvas_coords)]
    cv2.fillPoly(canvas, coords, color, lineType=cv2.LINE_AA)
Beispiel #4
0
def evolve_map_with_polygonal_obstacle(env_map, polygon_points):
    env_map_data = np.copy(env_map.data)
    points = canvas_to_cv2(
        world_to_canvas(
            polygon_points,
            env_map.resolution,
            env_map.data.shape,
        ))
    cv2.fillPoly(env_map_data, [points],
                 MapConstants.OBSTACLE,
                 lineType=cv2.LINE_AA)

    return env_map.evolve(env_map_data)
Beispiel #5
0
def evolve_map_with_circular_obstacle(env_map, circle_shape):
    env_map_data = np.copy(env_map.data)
    center = canvas_to_cv2(
        world_to_canvas(circle_shape.center, env_map.resolution,
                        env_map.data.shape))
    radius = world_to_canvas(circle_shape.radius, env_map.resolution)
    cv2.circle(env_map_data,
               tuple(center),
               radius,
               MapConstants.OBSTACLE,
               thickness=-1)

    return env_map.evolve(env_map_data)