Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named cv2

import numpy as np

import cv2
from matplotlib import pyplot as plt

img = cv2.imread('1.jpg',0)

orb = cv2.ORB()

kp = orb.detect(img,None)

kp, des = orb.compute(img, kp)


img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()

In here, I have installed numpy and opencv in my windows operating system. But i can't find out the proper way to add cv2 module.

like image 717
Shatil Haque Avatar asked Sep 18 '15 23:09

Shatil Haque


People also ask

How do I fix No module named cv2?

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.

Where is cv2 in Python?

The file cv2.so is stored in /usr/local/lib/python2.7/site-packages/... There are also folders in /usr/local/lib called python3.2 and python2.6, which could be a problem but I'm not sure.


2 Answers

The fastest and cleanest way is to run pip. It's a clean convenient tool for Python packages.

Just run:

pip install opencv-python or C:\Python27\Scripts\pip.exe install opencv-python

like image 173
Lukasz Czerwinski Avatar answered Oct 14 '22 22:10

Lukasz Czerwinski


The easiest way to install OpenCV on Windows is to simply copy the cv2.pyd file into Python's site-packages directory (e.g. C:\python27\Lib\site-packages).

To get the cv2.pyd file, download and extract the latest version of the OpenCV installation executable from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/ and browse the extracted folder to find the file in the relevant build directory (e.g. build\python\x86\2.7).

like image 21
101 Avatar answered Oct 14 '22 22:10

101