Python - Install OpenCV 2.3.1 for Window

OpenCV is a Open source Computer Vision library.

This is provide some guide on installing OpenCV 2.3.1 for Window

1. Download and install Python 2.7
2. Download and install NumPy and SciPy. Installing them is as simple as double clicking the downloaded installer. It will install the extension to your Python site-package folder
3. Download OpenCV 2.3.1 for Window Pre-build version
4. Double click on the OpenCV installer. It will extract OpenCV to your selected folder. For me, I extract it to C:\opencv and I will use that path for the rest of this blog
5. OpenCV 2.3.1 folder structure is different from OpenCV 2.2. The pre-build library and Python package are located at C:\opencv\build.
5. Add C:\opencv\build\x86\vc10\bin to PATH system environment variable for OpenCV.
6. Open Python IDLE
7. Add the following. Note: Having \\ for path is important. If not, Python interpretor may think some of the path as character encoding. For example, \b is consider as character encoding in Python

import sys
sys.path.append("C:\\opencv\\build\\python\\2.7")

8. Now, you are ready to import OpenCV with

import cv

See http://opencv.willowgarage.com/wiki/Welcome

Comments

  1. Thanks a lot for point me to the right direction.

    Cheers!

    ReplyDelete
  2. Sir, i'm trying to make it work with Dev C++, but in vain, so far.
    Please have a look and help me out if you would like

    here's what i've done:
    [commands when calling the compiler] :-
    -L"C:\opencv\build\x86\mingw\lib" -lcxcore231 -lcv231 -lcvaux231 -lhighgui231 -lml231

    [commands to linker commandline] :-
    -lcxcore231 -lcv231 -lcvaux231 -lhighgui231 -lml231

    [binaries path]:
    C:\opencv\build\x86\mingw\bin

    [libraries path]:
    C:\opencv\build\x86\mingw\lib

    [include]:
    C:\opencv\build\include

    and the error, actually the linker error i'm getting after compiling a simple console project with the above configured opencv compiler is:

    cannot find -lcxcore231

    [compiler log]:
    Compiler: OpenCV
    Building Makefile: "C:\Users\ronnieaka\Desktop\PROJ\openCV\Makefile.win"
    Executing make...
    make.exe -f "C:\Users\ronnieaka\Desktop\PROJ\openCV\Makefile.win" all
    g++.exe main.o -o "FirstCVproj.exe" -L"lib" -L"C:/opencv/build/x86/mingw/lib" -lcxcore231 -lcv231 -lcvaux231 -lhighgui231 -lml231

    C:\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcxcore231
    collect2: ld returned 1 exit status

    make.exe: *** [FirstCVproj.exe] Error 1

    please help me out. The first step itself is becoming a so hard

    ReplyDelete
  3. i've done the installation of opencv as you said.
    i already had python 2.7

    so i appended in the user environment variable "path" which you asked to

    then i exectuted shell instructions for python as told

    and then i got this:

    ImportError: No module named cv

    I don't think not having numpy and scipy would've affected it. I mean in just importing a module that's already sitting in opencv\build\python\2.7 shouldn't be dependent on that.

    What could be the problem

    ReplyDelete
  4. problem solved.. i added the PATH to system variable

    but now i'm having problems with numpy, it asks for python 2.6
    i've got 2.7, and in your instructions also you've mentioned 2.7..


    i'm using the rc versions of both numpy and scipy to make them work with python 2.7

    ReplyDelete
  5. Glad that you had already solved part of the issue.

    As for numpy, did you get the installer version or build your own?

    Check your C:\Python27\Lib\site-packages and see if numpy and scipy installed at that location.

    ReplyDelete
  6. Thank you for this short explanation. I was trying for hours to run opencv in python. The documentation - also on the official site - is not very good.

    I could only run it by copying the cv.py, cv.pyc and the cv2.pyd into the "site-packages" folder from python. Do you know if there is any difference. I was not shure, if all functions from opencv where available.

    One hint: I added "C:\opencv\build\python\2.7"in the "PYTHONPATH" variable. So I don't need to set this path in every script.

    ReplyDelete
  7. should be import cv2 otherwise wil return an error

    ReplyDelete

Post a Comment

Popular Posts