OpenCV Workshop Python distribution of keywords

From Hackerspace Brussels
Jump to: navigation, search

List of the 50 most represented OpenCV members of the Python package in the documentation examples.

This is done via

import os.path
import re

import cv

cv_vars = vars(cv)
# some patterns could be ignore, e.g. __ found in __name__
cv_vars_counters = dict()

examples_path = '/usr/share/doc/opencv-doc/examples/python/python/'
examples = os.listdir(examples_path)

for example in examples:
        if example.endswith('.py'):
                f = open(examples_path+example,'r')
                content = str(f.readlines())
                for var in cv_vars.keys():
                        # this could be limited to built-in functions instead
                        val = cv_vars_counters.setdefault(var,0)
                        occurrences = len(re.findall(var,content))
                        cv_vars_counters[var] = val + occurrences

for key, value in sorted(cv_vars_counters.iteritems(), key=lambda (k,v): (v,k)):
    print "%s: %s" % (key, value)

#The output can be processed to be shared on a wiki page, e.g.
# python | tail -50 | tac | sed "s|\(.*\): \(.*\)|* [\1 \1] \2|"

See OpenCV Workshop.