_coverage.py 796 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. '''
  3. Utility for measuring python opencv API coverage by samples.
  4. '''
  5. # Python 2/3 compatibility
  6. from __future__ import print_function
  7. from glob import glob
  8. import cv2 as cv
  9. import re
  10. if __name__ == '__main__':
  11. cv2_callable = set(['cv.'+name for name in dir(cv) if callable( getattr(cv, name) )])
  12. found = set()
  13. for fn in glob('*.py'):
  14. print(' --- ', fn)
  15. code = open(fn).read()
  16. found |= set(re.findall('cv2?\.\w+', code))
  17. cv2_used = found & cv2_callable
  18. cv2_unused = cv2_callable - cv2_used
  19. with open('unused_api.txt', 'w') as f:
  20. f.write('\n'.join(sorted(cv2_unused)))
  21. r = 1.0 * len(cv2_used) / len(cv2_callable)
  22. print('\ncv api coverage: %d / %d (%.1f%%)' % ( len(cv2_used), len(cv2_callable), r*100 ))