Similar function to python module 'inspect'? [closed]

asked 2015-06-11 08:12:37 -0600

Hey There, python provides a module called 'inspect' which gives possibilities to retrieve function information, like number of arguments, type of arguments, and more. Unfortunately this doesn't cover imported modules implemeted in C. Parameters of a to-be-parsed C module can't be read. See python issues like http://bugs.python.org/issue1748064

My question is: Does OpenCV itself provide a similar function? I need to read arguments, eg. of cv2.Canny(...), to generate a GUI for user-friendly setting it's parameters.

Thank You

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-15 11:05:37.470863

Comments

1

you could use the __doc__ string, either from help():

>>> help(cv2.Canny)
    Help on built-in function Canny:

    Canny(...)
        Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]])
    -> edges

or, (from within a program), access it directly:

>>> cv2.Canny.__doc__
'Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) ->
edges'

(besides that, the python wrappers are all generated. you could exploit modules/python/src/gen2.py to generate your own doc/api/gui bindings in the very same way)

berak gravatar imageberak ( 2015-06-11 08:18:32 -0600 )edit

Thanks for your answer. The __doc__ or help function only return a single string providing me parameter names. What I need are the types of the input arguments. For example, I want to build a QSpinBox with PyQt if the type is integer to embed this in my widget. For this cause gen2.py seems quite promising, as it builds python lists containing the needed information. If I get to catch those lists, I will post my solution.

MisterZylinder gravatar imageMisterZylinder ( 2015-06-16 04:04:20 -0600 )edit

if you go that way, also look here . it preprocesses the raw hdr_parser.py output to some nice AST/DOM thing.

(maybe also look here (shameless plug))

berak gravatar imageberak ( 2015-06-16 04:21:54 -0600 )edit