check.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import glob
  3. import os
  4. from PIL import Image
  5. from strategy import State
  6. def saved_idents():
  7. return sorted(int(path[13:-4]) for path in glob.glob('screens/board*.png'))
  8. if __name__ == '__main__':
  9. ok = fail = notfound = 0
  10. for ident in saved_idents():
  11. truth_path = 'screens/true%d.txt' % ident
  12. if os.path.exists(truth_path):
  13. board = Image.open('screens/board%d.png' % ident).convert('HSV')
  14. state = State.detect(board, pad=0)
  15. detected = state.tostring()
  16. with open(truth_path) as f:
  17. expected = f.read()
  18. if detected != expected:
  19. print('=' * 20)
  20. print('board', ident, 'FAIL')
  21. print('expected:')
  22. print(expected)
  23. print('detected:')
  24. print(detected, end='')
  25. print('=' * 20)
  26. fail += 1
  27. else:
  28. print('board', ident, 'OK')
  29. ok += 1
  30. else:
  31. print(truth_path, 'does not exist')
  32. notfound += 1
  33. print('%d boards, %d ok, %d fail' %(ok + fail, ok, fail))