Cannot import cv on Opencv2

后端 未结 2 542
梦如初夏
梦如初夏 2021-01-03 06:13

I am using a Windows 10 machine and have installed Python, numpy and OpenCV from the official link using pre built binaries. I can successfully import numpy and cv2 but get

2条回答
  •  长发绾君心
    2021-01-03 06:39

    It is somewhere in there, just need to search for it. Try running something like the following on your system:

    from types import ModuleType
    
    def search_submodules(module, identifier):
        assert isinstance(module, ModuleType)
        ret = None
        for attr in dir(module):
            if attr == identifier:
                ret = '.'.join((module.__name__, attr))
                break
            else:
                submodule = getattr(module, attr)
                if isinstance(submodule, ModuleType):
                    ret = search_submodules(submodule, identifier)
        return ret
    
    if __name__ == '__main__':
        import cv2
        print cv2.__version__
        print search_submodules(cv2, 'RNG')
    

    On my system, this prints:

    2.4.11
    cv2.cv.RNG
    

提交回复
热议问题