Пример #1
0
def test_real_map_scenario():
    """Two pics already done, first is (23, -62) on base, second comes in
    with offset (-17, -86).
    """
    map_shape = [663, 542]
    new_shape = [640, 480]
    offsets = (-17, -86)

    assert paddings(map_shape, new_shape, *offsets) == (86, 0, 17, 0)
Пример #2
0
def add_to_map(img_map, loc_map, img_new, offset_x, offset_y):
    """Apply a new image to an existing map and return."""

    # Pad out the map to fit the new image.
    paddings = geometry.paddings(img_map.shape, img_new.shape, offset_x,
                                 offset_y)
    img_map = cv2.copyMakeBorder(img_map,
                                 paddings[Paddings.Top],
                                 paddings[Paddings.Bottom],
                                 paddings[Paddings.Left],
                                 paddings[Paddings.Right],
                                 cv2.BORDER_CONSTANT,
                                 value=(0, 0, 0, 0))

    # Create a mask from the new image.
    img_new_mask = img_new[:, :, 3]

    # We'll apply an inverted mask to black out parts of the map.
    img_map_mask = cv2.bitwise_not(img_new_mask)

    # The bit of the map where we'll stuff the new image.
    map_roi = geometry.map_roi(img_new.shape, offset_x, offset_y)

    # Black out the bit of the map ROI where we'll put the new image.
    img_map_roi = img_map[map_roi[0]:map_roi[1], map_roi[2]:map_roi[3]]
    img_map_roi = cv2.bitwise_and(img_map_roi, img_map_roi, mask=img_map_mask)

    # Overlay the new image in the ROI from the map.
    img_map_roi = cv2.add(img_map_roi,
                          cv2.bitwise_and(img_new, img_new, mask=img_new_mask))

    # Restore the ROI back into the original map.
    img_map[map_roi[0]:map_roi[1], map_roi[2]:map_roi[3]] = img_map_roi
    return (
        img_map,
        paddings,
        (
            # Location in the new map of the centre of the new image.
            max(offset_x, 0) + (img_new.shape[1] // 2),
            max(offset_y, 0) + (img_new.shape[0] // 2),
        ))
Пример #3
0
def test_smaller_box_contained_moving_right_and_just_staying_contained():
    map_shape = [20, 20]
    new_shape = [10, 10]
    offsets = (5, 10)

    assert paddings(map_shape, new_shape, *offsets) == (0, 0, 0, 0)
Пример #4
0
def test_same_size_box_moving_up():
    map_shape = [20, 20]
    new_shape = [20, 20]
    offsets = (0, -10)

    assert paddings(map_shape, new_shape, *offsets) == (10, 0, 0, 0)
Пример #5
0
def test_smaller_box_contained_moving_right_and_exceeding_container():
    map_shape = [20, 20]
    new_shape = [10, 10]
    offsets = (11, 5)

    assert paddings(map_shape, new_shape, *offsets) == (0, 0, 0, 1)