import cv2 works but import cv2.cv as cv not working

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

I think the sys path is correct, cv.pyd and cv.pyd reside in c:\OpenCV2.3\build\Python\2.7\Lib\site-packages.

>>> import sys >>> sys.path ['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Python27\\lib\\site-packages\\pil-1.1.7-py2.7-win32.egg',     'C:\\Python27\\lib\\site-packages\\cython-0.17-py2.7-win32.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.2-py2.7.egg', 'c:\\OpenCV2.3\\build\\Python\\2.7\\Lib\\site-packages', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\IPython\\extensions'] 

And import cv or cv2 seems to be ok but import cv2.cv not

>>> import cv >>> import cv2.cv as cv  Traceback (most recent call last):   File "<pyshell#4>", line 1, in <module>     import cv2.cv as cv ImportError: No module named cv >>> import cv2 >>> cv.NamedWindow("camera", 1) 

...

What could be the reason of the ImportError?

回答1:

I had the same issue.This was an issue with OpenCV Engine.Download OpenCV engine from https://github.com/thumbor/opencv-engine/releases/tag/1.0.1 and save it as engine.py in \Python27\Lib\site-packages.use cv2.cv instead of cv2.cv as cv.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!