obfuscator_test.py 963 B

12345678910111213141516171819202122
  1. import numpy as np
  2. from anonymizer.obfuscation import Obfuscator
  3. from anonymizer.utils import Box
  4. class TestObfuscator:
  5. @staticmethod
  6. def test_it_obfuscates_regions():
  7. obfuscator = Obfuscator()
  8. np.random.seed(42) # to avoid flaky tests
  9. image = np.random.rand(128, 64, 3) # height, width, channels
  10. boxes = [Box(y_min=0, x_min=10, y_max=20, x_max=30, score=0, kind=''),
  11. Box(y_min=100, x_min=10, y_max=120, x_max=30, score=0, kind='')]
  12. # copy to make sure the input image does not change
  13. obfuscated_image = obfuscator.obfuscate(np.copy(image), boxes)
  14. assert obfuscated_image.shape == (128, 64, 3)
  15. assert not np.any(np.isclose(obfuscated_image[0:20, 10:30, :], image[0:20, 10:30, :]))
  16. assert not np.any(np.isclose(obfuscated_image[100:120, 10:30, :], image[100:120, 10:30, :]))
  17. assert np.all(np.isclose(obfuscated_image[30:90, :, :], image[30:90, :, :]))