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