Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/python/_coverage.py
16337 views
1
#!/usr/bin/env python
2
3
'''
4
Utility for measuring python opencv API coverage by samples.
5
'''
6
7
# Python 2/3 compatibility
8
from __future__ import print_function
9
10
from glob import glob
11
import cv2 as cv
12
import re
13
14
if __name__ == '__main__':
15
cv2_callable = set(['cv.'+name for name in dir(cv) if callable( getattr(cv, name) )])
16
17
found = set()
18
for fn in glob('*.py'):
19
print(' --- ', fn)
20
code = open(fn).read()
21
found |= set(re.findall('cv2?\.\w+', code))
22
23
cv2_used = found & cv2_callable
24
cv2_unused = cv2_callable - cv2_used
25
with open('unused_api.txt', 'w') as f:
26
f.write('\n'.join(sorted(cv2_unused)))
27
28
r = 1.0 * len(cv2_used) / len(cv2_callable)
29
print('\ncv api coverage: %d / %d (%.1f%%)' % ( len(cv2_used), len(cv2_callable), r*100 ))
30
31