OpenCV 3.0.0 + Python 3.4 + Win7 + Numpy + Scipy + Mingw

Hi there, I have a simple dream. Making these work together:

  • Windows 7 [64bit]
  • OpenCV 3.0.0 [32bit] builded from source
    • features2d
    • ffmpeg
  • Python 3.4.X [32bit]
    • tkinter openCV window app
    • .. maybe wxWidget
    • .. maybe PyQt
  • Numpy [32bit] (maybe as a start as it does not have a 64bit prebuilt)

This will be a working tutorial. I’m on it.

People from OpenCV have done a new tutorial here which is nice 🙂 [Last updated on Nov 10, 2015.]

Firstly I do some research…

Research

These combination won’t wocrk:

  • OpenCV 2.4.X and Python 3.0

These combination works:

  • OpenCV 3.0.0 and Python 2.7.10 – works tested 22-10-2015
  • OpenCV 3.0.0 and Python 3.4.X – works tested 22-10-2015

Downloads

  • git client
    Cloning of git repositories to get latest sourcefiles safely.
    • TortoiseGIT
      • has „explorer context menus“
    • SourceTree
      • good log and git tree show
  • MinGW
    g++ compiler for windows
  • CMake
    Manages the build process in an OS and in a compiler-independent manner.
    • download setup
      • https://cmake.org/download/
  • OpenCV
    Libraries for Computer Vision
  • Python
    Programming language SDK
  • pyCharm
    Python IDE
    • download Community Free setup
      • https://www.jetbrains.com/pycharm/download/

It is important which versions of python modules (numpy etc.) you install. We need 32bit version, not amd64! Also we need a version compatible with our Python 3.4.3

Installation

Based primarily on [1]

  • Install MinGW
    • win32 setup
    • I had 0.6.2-beta-20131004-1 into default
      C:\MinGW
    • After install run it and check these two:
      • mingw32-base
      • mingw32-gcc-g++
    • Then
      • Installation -> Apply Changes … Apply
  • Install CMake
  • Python
    • install Python 3.4.3 from exe installer (win32 not amd64)
      C:\PROG\dev\Python34\
      • [x] Precompile standard library
      • [x] Add Python 3.4.3 to PATH
    • Install modules
    • pip install
      • matplotlib – for graph / image plotting as it is used in many Python openCV manuals has dependencies on other modules
      • We can use a pip package manager to download the dependencies and install them
        • in cmd.exe:
           $ pip3.4 install matplotlib
        • will install dependencies of matplotlib
          • Successfully installed pyparsing-2.0.5 python-dateutil-2.4.2 pytz-2015.7 six-1.10.0
  • OpenCV
    • clone repo into:
      • C:\PROG\dev\openCV\[opencv]
    • In folder opencv, create a new folder [build] to build from source within it.
    • Run CMake
      • CMake settings
        • To make the buildable items appear in groups
          • check [x] Grouped
        • Suppress development warnings – you are not OpenCV developer
          • Options -> Suppress dev Warnings
      • select opencv
        • c:/PROG/dev/opencv/opencv/
      • select opencv/build
        • c:/PROG/dev/opencv/opencv/build/
      • click Configure
        • if libgmp-10.dll missing
          • add MinGW to your system path
            c:/MinGW/bin
      • set compilator
        • Visual Studio 11 – had some issues so i tried minGW
        • mingw – np – ok – must be in path
      • checkbox what you want to compile
        • as in the pics or in the manual in reference [1]
        • or in screenshots under this list
        • the changes are mainly in groups BUILD and WITH
      • check that the paths in PYTHON3 groups are correct
        • don’t mind the PYTHON3_LIBRARY_DEBUG
      • click Configure again
        • more times and fiddle with checkboxes if needed
          • unselect build OpenCV for Python 2
      • click Generate
      • If there are no warnings
        • do the make and build from selected compiler
          • run make from cmd
            $ mingw32-make.exe
            • cv2.pyd not found
              • uncheck BUILD_opencv_python2
              • reconfigure and regenerate!
          • make install from cmd afterwards (if no problems)
            $ mingw32-make.exe install
      • If you selected BUILD_DOCS

Screenshots of mingw CMAKE settings – groups WITH and BUILD
_mingw_cmake_with_mingw_cmake_build

 + additional parts

  • add to CMake configuration
  • WITH
    • [x] 1394
      [..] GIGEAPI – no
      [x] PTHREADS_PF
  • INSTALL
    [x] INSTALL_PYTHON_EXAMPLES
  • BUILD
    [x] DOCS – ?? how to include with sphinx?
    [x] EXAMPLES – cxx executable – bin\cpp-tutorial … takes very long (1.5GB)

 

[] Python 3.5
KB2999226 – error

[] add lib path Preferences
C:\PROG\dev\openCV\opencv\build\lib\Release

build

[] Add PATH variables of bin folders
I also added path to the system „Path“ variable to the „bin“ directories of OpenCV, MinGW and CMake.

 Try that it works

The tkinter is a part of Python 3.4 install if you didn’t uncheck it, as well as pip module package manager btw. So to try out if you have installed everything correctly you may try the gr4gallery demo application.

Convert Python 2 to Python 3

If you happen to have some project written in Python 2.X, and you want to convert to Python 3.X, you can use the following regular expression to convert at least the print function semantics:

%s:print \(.*\):print(\1):gc

I run it through gvim one file at a time, as my projects are small. It will just find all the prints in the Python 2 format:

print "something " + str(number)

and enclose it with round brackets as in Python 3:

print("something " + str(number))

Easy but it can work if it is the only thing which you use that changed during conversion from Python 2 to 3.

Another thing is the xrange vs range. xrange is more memory friendly and faster for bigger fields allocated in Python 2.X. In Python 3 there is no such thing as xrange function as the normal range takes its place and possibilities so regex:

%s:xrange:range:gc

Tutorials

 

 

Snippets

How to find out of cv2 version installed in Python?

>>> from cv2 import __version__
>>> __version__
'$Rev: 4557 $'
# ... or
'3.0.0-dev'

 Another things to install

usefull modules

  • pywin32
    http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/pywin32-219.win32-py3.4.exe/download

usefull libraries

 

Used references [x]

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *