test_image.py 571 B

123456789101112131415
  1. import cv2
  2. import numpy as np
  3. from module.atom.image import RuleImage
  4. def test_empty_mask_file_falls_back_to_plain_matching(tmp_path):
  5. pixels = np.random.default_rng(7).integers(0, 256, (20, 20, 3), dtype=np.uint8)
  6. path = tmp_path / 'template.png'
  7. path.write_bytes(cv2.imencode('.png', pixels)[1].tobytes())
  8. path.with_name('template_mask.png').write_bytes(b'')
  9. rule = RuleImage((0, 0, 20, 20), (0, 0, 20, 20), 'Masked template matching', 0.99, str(path))
  10. assert rule.match(cv2.cvtColor(pixels, cv2.COLOR_BGR2RGB))
  11. assert rule.mask is None