Files
opencv/samples/python/_coverage.py
HARSH SUMAN e3e87055bd Merge pull request #28195 from harsh-suman5:fix-coverage-regex
Fix regex escape warning in _coverage.py by using raw string #2819

while i am running '_coverage.py' I noticed there is a syntax warning:"\." It is an invalid escape sequence
The regex was written as a normal string with '\.' which is not valid escape in string literals and give problems and error in a new python versions. 
To fix this switch to raw string(r'cv2?\.\w+') which can passes the backslashes directly to the regex engine. This removes the warning and keeps the code  and pattern working properly.

This is a small fix but important for future compatibilities.
2025-12-18 14:52:20 +03:00

30 lines
797 B
Python
Executable File

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