OpenCV Workshop Python distribution of keywords

From Hackerspace Brussels
Revision as of 13:53, 8 November 2011 by Utopiah (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
                f.close()

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 atoms_distribution.py | tail -50 | tac | sed "s|\(.*\): \(.*\)|* [http://opencv.willowgarage.com/documentation/python/search.html?q=\1 \1] \2|"

See OpenCV Workshop.