def test_layer_overlay_rotated(): black_frame_image = np.zeros((100, 200, 3), dtype='uint8') rand_frame_1_image = black_frame_image.copy() rand_frame_2_image = black_frame_image.copy() add_random_circles(rand_frame_1_image, seed=42) add_random_circles(rand_frame_2_image, seed=8675309) rand_frame_1 = Frame(rand_frame_1_image) rand_frame_2 = Frame(rand_frame_2_image) rand_frame_1, _ = border_frame(rand_frame_1, border_size=0, border_type='black') rand_frame_2, _ = border_frame(rand_frame_2, border_size=0, border_type='black') rand_frame_2 = imutils.rotate(rand_frame_2, 90) overlay_1 = layer_overlay(rand_frame_1, rand_frame_2) overlay_2 = layer_overlay(rand_frame_2, rand_frame_1) overlay_2_expected = cv2.imread(overlay_2_test_file) overlay_1 = overlay_1[:, :, :3] overlay_2 = overlay_2[:, :, :3] # write/read as jpg to match expected cv2.imwrite(overlay_2_test_file, overlay_2) overlay_2 = cv2.imread(overlay_2_test_file) assert np.allclose(overlay_1, overlay_1) assert np.allclose(overlay_2, overlay_2_expected)
def test_border_frame(): frame = np.zeros((10, 10)) bordered_frame, border_mode = utils.border_frame(frame, border_size=100, border_type='black') assert bordered_frame.shape == (410, 410) assert border_mode == 0 bordered_frame, border_mode = utils.border_frame(frame, border_size=100, border_type='replicate') assert bordered_frame.shape == (410, 410) assert border_mode == 1 bordered_frame, border_mode = utils.border_frame(frame, border_size=100, border_type='reflect') assert bordered_frame.shape == (410, 410) assert border_mode == 2 with pytest.raises(KeyError) as err: utils.border_frame(frame, border_size=100, border_type='fake') assert 'fake' in str(err.value)
def test_layer_overlay(): black_frame = np.zeros((100, 200, 3), dtype='uint8') rand_frame = black_frame.copy() add_random_circles(rand_frame) black_frame, _ = border_frame(black_frame, border_size=0, border_type='black') rand_frame, _ = border_frame(rand_frame, border_size=0, border_type='black') overlay_rand = layer_overlay(rand_frame, black_frame) overlay_black = layer_overlay(black_frame, rand_frame) assert np.allclose(overlay_black, black_frame) assert np.allclose(overlay_rand, rand_frame)