13
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.

Shatil Haque
  • 131
  • 1
  • 1
  • 5
  • 1
    @jlnabais The OP mentions installing OpenCV on Windows, not Ubuntu, so if it is a duplicate question, then not that one. – WhiteViking Sep 18 '15 at 23:33
  • How did you install OpenCV precisely? From binaries or source? Did you follow these installation instructions https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows ? – WhiteViking Sep 18 '15 at 23:35
  • on windows - it's often worth trying installing prebuilt wheels from Gohlke's excellent site - http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. i think that's how I got my OpenCV on windows (it's ages since I installed it - sorry I can't recall details) – J Richard Snape Sep 18 '15 at 23:39
  • Use the prebuilt windows packages [distributed by Gohlke](http://www.lfd.uci.edu/~gohlke/pythonlibs/). I have just done a clean install of Python 3.5 on Windows and installed numpy, matplotlib and OpenCV from that repository. It works out of the box - no module errors as you experience. Note that you might be trying to code according an old version of the open CV API. In particular - you might need to use `cv.ORB_create()` tather that `cv.ORB()` (see my [answer here](http://stackoverflow.com/a/31632268/838992)) and you might need other parameters for `drawKeypoints()` – J Richard Snape Sep 21 '15 at 13:44

2 Answers2

17

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

Lukasz Czerwinski
  • 13,499
  • 10
  • 55
  • 65
1

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).

101
  • 8,514
  • 6
  • 43
  • 69
  • 1
    I've also copy cv2.pyd file into site-packages, but now there occurring a new error. "ImportError: DLL load failed: The specified module could not be found." @figs – Shatil Haque Sep 19 '15 at 16:22
  • That could be related to something else, e.g. importing `numpy` or `matplotlib`. Try a much simpler script that only imports `cv2`. Also check out this related answer: http://stackoverflow.com/questions/22221427/importerror-dll-load-failed-the-specified-procedure-could-not-be-found-python – 101 Sep 19 '15 at 22:46