Skip to content

Commit 6174f62

Browse files
Cartuchoalalek
authored andcommitted
Sample for functions
1 parent d715bad commit 6174f62

File tree

5 files changed

+276
-206
lines changed

5 files changed

+276
-206
lines changed

doc/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ if(BUILD_DOCS AND DOXYGEN_FOUND)
205205
list(APPEND js_tutorials_assets_deps "${f}" "${opencv_tutorial_html_dir}/${fname}")
206206
endforeach()
207207

208-
set(doxygen_result "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/index.html")
208+
set(doxygen_result "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/modules.html")
209209

210210
add_custom_target(doxygen_cpp
211211
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
@@ -220,15 +220,15 @@ if(BUILD_DOCS AND DOXYGEN_FOUND)
220220

221221
if(BUILD_opencv_python2)
222222
add_custom_target(doxygen_python
223-
COMMAND ${PYTHON2_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tools/python_signatures.py" "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/" "${OPENCV_PYTHON2_SIGNATURES_FILE}"
223+
COMMAND ${PYTHON2_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tools/add_signatures.py" "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/" "${OPENCV_PYTHON2_SIGNATURES_FILE}" "python"
224224
DEPENDS "${doxygen_result}" gen_opencv_python2
225225
)
226226
add_custom_target(doxygen
227227
DEPENDS doxygen_cpp doxygen_python
228228
)
229229
elseif(BUILD_opencv_python3)
230230
add_custom_target(doxygen_python
231-
COMMAND ${PYTHON3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tools/python_signatures.py" "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/" "${OPENCV_PYTHON3_SIGNATURES_FILE}"
231+
COMMAND ${PYTHON3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tools/add_signatures.py" "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/" "${OPENCV_PYTHON3_SIGNATURES_FILE}" "python"
232232
DEPENDS "${doxygen_result}" gen_opencv_python3
233233
)
234234
add_custom_target(doxygen

doc/tools/add_signatures.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
This code adds Python/Java signatures to the docs.
3+
4+
TODO: Do the same thing for Java
5+
* using javadoc/ get all the methods/classes/constants to a json file
6+
7+
TODO:
8+
* clarify when there are several C++ signatures corresponding to a single Python function.
9+
i.e: calcHist():
10+
http://docs.opencv.org/3.2.0/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d
11+
* clarify special case:
12+
http://docs.opencv.org/3.2.0/db/de0/group__core__utils.html#ga4910d7f86336cd4eff9dd05575667e41
13+
"""
14+
from __future__ import print_function
15+
import os
16+
import re
17+
import sys
18+
import logging
19+
import html_functions
20+
import doxygen_scan
21+
22+
loglevel=os.environ.get("LOGLEVEL", None)
23+
if loglevel:
24+
logging.basicConfig(level=loglevel)
25+
26+
27+
ROOT_DIR = sys.argv[1]
28+
PYTHON_SIGNATURES_FILE = sys.argv[2]
29+
JAVA_PYTHON = sys.argv[3]
30+
31+
ADD_JAVA = False
32+
ADD_PYTHON = False
33+
if JAVA_PYTHON == "python":
34+
ADD_PYTHON = True
35+
36+
import json
37+
python_signatures = dict()
38+
with open(PYTHON_SIGNATURES_FILE, "rt") as f:
39+
python_signatures = json.load(f)
40+
print("Loaded Python signatures: %d" % len(python_signatures))
41+
42+
# only name -> class
43+
# name and ret -> constant
44+
# name, ret, arg-> function / class method
45+
46+
class Configuration():
47+
def __init__(self):
48+
self.ADD_PYTHON = ADD_PYTHON
49+
self.python_signatures = python_signatures
50+
self.ADD_JAVA = ADD_JAVA
51+
52+
config = Configuration()
53+
54+
import xml.etree.ElementTree as ET
55+
root = ET.parse(ROOT_DIR + 'opencv.tag')
56+
files_dict = dict()
57+
58+
# constants and function from opencv.tag
59+
namespaces = root.findall("./compound[@kind='namespace']")
60+
#print("Found {} namespaces".format(len(namespaces)))
61+
for ns in namespaces:
62+
ns_name = ns.find("./name").text
63+
#print('NS: {}'.format(ns_name))
64+
65+
files_dict = doxygen_scan.scan_namespace_constants(ns, ns_name, files_dict)
66+
files_dict = doxygen_scan.scan_namespace_functions(ns, ns_name, files_dict)
67+
68+
# class methods from opencv.tag
69+
classes = root.findall("./compound[@kind='class']")
70+
#print("Found {} classes".format(len(classes)))
71+
for c in classes:
72+
c_name = c.find("./name").text
73+
name = ns_name + '::' + c_name
74+
file = c.find("./filename").text
75+
#print('Class: {} => {}'.format(name, file))
76+
files_dict = doxygen_scan.scan_class_methods(c, c_name, files_dict)
77+
78+
# test
79+
for file in files_dict:
80+
soup = html_functions.load_html_file(ROOT_DIR + file)
81+
if file == "d4/d86/group__imgproc__filter.html":#"d4/d86/group__imgproc__filter.html":
82+
anchor_list = files_dict[file]
83+
counter = 0
84+
anchor_tmp_list = []
85+
for anchor in anchor_list:
86+
counter += 1
87+
# if the next anchor shares the same C++ name (= same method/function), join them together
88+
if counter < len(anchor_list) and anchor_list[counter].cppname == anchor.cppname:
89+
anchor_tmp_list.append(anchor)
90+
continue
91+
else:
92+
anchor_tmp_list.append(anchor)
93+
# check if extists a python equivalent signature
94+
for signature in python_signatures: # signature is a key with the C++ name
95+
if signature == anchor.cppname: # if available name in python
96+
# they should also have the same type
97+
soup = html_functions.append_python_signature(python_signatures[signature], anchor_tmp_list, soup)
98+
#print(signature)
99+
# reset anchor temporary list
100+
anchor_tmp_list[:] = []
101+
html_functions.update_html(ROOT_DIR + file, soup)

doc/tools/doxygen_scan.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class Anchor(object):
2+
anchor = ""
3+
type = ""
4+
cppname = ""
5+
6+
def __init__(self, anchor, type, cppname):
7+
self.anchor = anchor
8+
self.type = type
9+
self.cppname = cppname
10+
11+
def add_to_file(files_dict, file, anchor):
12+
if file in files_dict:
13+
# if that file already exists as a key in the dictionary
14+
files_dict[file].append(anchor)
15+
else:
16+
files_dict[file] = [anchor]
17+
return files_dict
18+
19+
20+
def scan_namespace_constants(ns, ns_name, files_dict):
21+
constants = ns.findall("./member[@kind='enumvalue']")
22+
for c in constants:
23+
c_name = c.find("./name").text
24+
name = ns_name + '::' + c_name
25+
file = c.find("./anchorfile").text
26+
anchor = c.find("./anchor").text
27+
#print(' CONST: {} => {}#{}'.format(name, file, anchor))
28+
files_dict = add_to_file(files_dict, file, Anchor(anchor, "const", name))
29+
return files_dict
30+
31+
def scan_namespace_functions(ns, ns_name, files_dict):
32+
functions = ns.findall("./member[@kind='function']")
33+
for f in functions:
34+
f_name = f.find("./name").text
35+
name = ns_name + '::' + f_name
36+
file = f.find("./anchorfile").text
37+
anchor = f.find("./anchor").text
38+
#print(' FN: {} => {}#{}'.format(name, file, anchor))
39+
files_dict = add_to_file(files_dict, file, Anchor(anchor, "fn", name))
40+
return files_dict
41+
42+
def scan_class_methods(c, c_name, files_dict):
43+
methods = c.findall("./member[@kind='function']")
44+
for m in methods:
45+
m_name = m.find("./name").text
46+
name = c_name + '::' + m_name
47+
file = m.find("./anchorfile").text
48+
anchor = m.find("./anchor").text
49+
#print(' Method: {} => {}#{}'.format(name, file, anchor))
50+
files_dict = add_to_file(files_dict, file, Anchor(anchor, "method", name))
51+
return files_dict

0 commit comments

Comments
 (0)