Similar function to python module 'inspect'?

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

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

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 close merge delete



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

>>> help(cv2.Canny)
    Help on built-in function 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]]]) ->

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

berak gravatar imageberak ( 2015-06-11 08:18:32 -0500 )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 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 -0500 )edit

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

(maybe also look here (shameless plug))

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