Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 917
xdan Avatar asked Sep 06 '12 02:09

xdan


People also ask

Why import cv2 is not working?

The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

Is cv2 same as CV?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

Why is OpenCV not working?

You can try the following: Download and install the latest version of python. Restart your terminal. Create a new virtualEnv and install dependencies, check the script below.


1 Answers

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.

like image 170
SivamNatesan Avatar answered Sep 28 '22 02:09

SivamNatesan