首页 > 解决方案 > Pydoc 忽略 opencv 函数,只考虑使用 def 关键字定义的 python 函数

问题描述

我想为我的 OpenCV 项目开发 API 文档。

但是当我pydoc - w在我的模块上运行命令时,它只为那些用 def 关键字声明的函数创建了文档。

Pydoc 忽略 OpenCV 函数,例如cv2.videocaputure(). 它们不包含在文档中。

def initState(A, B, C, D, E, P1, P2, P3, P4, P5):
    """if all blocks are there and good recognized, if not shows message.
        :param: The number of objects
        :type: int
         :putText()
         :return: intial state top or initial state reconized with all objects,
                  show text on window Sorry , objects not recognized(Text)
     """
    if (A == 1 and B == 1 and C == 1 and D == 1 and E == 1 and P1 == 1 and P2 == 1 and P3 == 1 and P4 == 1 and P5 == 1):

        cv2.putText(frame, "initial state top",
                    (100, 100), font, 1, (0, 0, 255))
    else:
        cv2.putText(frame, "Sorry, not recognized",
                    (100, 100), font, 1, (0, 0, 255))
# knowing if final state is completed, must be recognized in the moment, if not recognized nothing will be shown


def finalState(A, B, C, D, E, P1, P2, P3, P4, P5):
    """knowing if final state is completed, must be recognized in the moment, if not recognized nothing will be shown.
    :param: The number of objects
    :type: int
    :putText()
    :return: Final state reconized with all objects(Text),
    """
    if (A == 1 and B == 1 and C == 1 and D == 1 and E == 1 and P1 == 1 and P2 == 1 and P3 == 1 and P4 == 1 and P5 == 1):

        cv2.putText(frame, "final state top", (100, 100), font, 1, (0, 0, 255))
        return 1


# capturing video, if want to change file or do it with a web cam just change the value
cap = cv2.VideoCapture('exp11111.mp4')
"""
    This will simply create the object
    for the camera and using this object we can control the
    video capturing and other functions related to the web cam.
    :param: can be either the device index or the name of a video file
"""

# starting while loop to recognize every frame.
while True:
    ret, frame = cap.read()
    if(
            ret == False):
        break

    """
     Capture frame-by-frame
    :return: bool (True,False)
    
    
    """

在此处输入图像描述

标签: pythonopencv-contourpydoc

解决方案


我无法重现。

我拿走了你的代码并伪造了cv.py

class VideoCapture:
    def __init__(self, *args, **kwargs):
        pass

    def read(self):
        pass

def putText(*args, **kwargs):
    pass

然后跑:

python -m pydoc -w your_code

我进入cap = <cv2.VideoCapture object>了输出。

如果您还想为 cv2 生成文档,您将需要:

python -m pydoc -w cv2

如果不分叉它或切换到许多更好的替代方案之一,例如 pdoc3、pydoctor 或 pycco,就很难让 pydoc 做你想做的事。


推荐阅读