OpenCV 2.4.1 and EPD 2.7.3 x86_64 on Mac OSX 10.6.8

Background: 

Python is a powerful scripting language with cross platfrom installer. Python has so many modules and libraries, including several popular ones like NumPy, Matplotlib, PIL, Pandas, and so on. Since Python has many functionalities, engineers and scientists have used it to replace Matlab for data analysis and scientific computation.

EPD (Enthought Python Distribution) is one of scientific computation python package which provides easy installation and interactive interface called iPython. EPD includes several popular scientific modules, such as NumPy, SciPy, PIL, and more. EPD has various licenses suiting the needs of the user. In this tutorial, we will use EPD 7.3.2 x86_64 for Mac.  Why use the academic version of EPD? The free version of EPD compiles python for i386 computer architecture, which is not compatible with the architecture of MacBookPro7,1 (x86_64). If you have never seen or used EPD or iPython before, this video maybe useful for you.

OpenCV is a library for image processing, computer vision, and machine learning with more than 500 functions. OpenCV is open source library with cross platform installation, ranging from Android, iOS, Windows, Linux, and Mac. OpenCV has plenty tutorials and documentations in its official website. Also, my colleague and I have wrote a lot of computer vision tutorials. You can find some useful articles here.

Why I wrote this tutorial? 

Many people do image processing and computer vision in C/C++, since they need to run it real-time and sometime want to embed it in small computing platform (mobile computing). In the other side, we can use python as a tool for learning, analyzing data as MATLAB does. Merging OpenCV to EPD means we can do more image analysis. We can provide more useful environment to build image processing algorithm, for example to analyze features extraction result with machine learning techniques or to do some algebra on the resulted image processing data.

Since I used Mac operating system, the installation was quite difficult (considering the OS platform and the processor architecture) and I found no reference that teach how to run OpenCV and EPD on Mac. Therefore, I decided to try every possibilities, for more than 18 hours, to configure and run OpenCV and EPD side by side. I ever used the free EPD, Unix makefile, and command-line Cmake, but I had no result. Changing the version of EPD, using Cmake GUI, and XCode to generate cv2.so (OpenCV python library that can be invoked directly from iPython console) was the best way that I can find right now.

I hope this tutorial will be useful for you, who have the same problem with me.

1. Requirements:

a. EPD 7.3.2-x86_64.dmg with academic license:
You can download it from EPD Enthought Python Distribution official website or download from http://www.clear.rice.edu/comp140/downloads/epd/mac/epd-7.3-2-macosx-x86_64.dmg
b. CMAKE GUI version 2.8-10 for Mac:
download here: http://www.cmake.org/cmake/resources/software.html
c. Sphinx module (download and install using easy_install)
d. XCode Version 3.2.6
e. OpenCV 2.4.1 source (tarball file). If you would like to download the latest one, you can clone it from https://github.com/Itseez/opencv

Operating system : Mac OS X 10.6.8 Snow Leopard

2. First, install EPD, CMAKE, Sphinx, and XCode.

3. Setting path in bash profile

# Setting path in ~/.bash_profile
# Setting PATH for EPD_free-7.3-2
export EPDPATH="/Library/Frameworks/EPD64.framework/Versions/Current"
export PATH="$EPDPATH/bin:${PATH}"
export PYTHONPATH="$EPDPATH/lib/python2.7/site-packages"

4. Make a folder called “build” inside OpenCV’s root folder.
This folder will be used to save build result of CMAKE.

5. Using CMAKE, configure Cmakefile of OpenCV

a. Use XCode as default compiler. Point the result to “build” folder (see step. 4). Check option grouped and advanced in CMAKE to reveal all flags and options

b. Set the following parameters in Python’s grouped setting :

Executable Path: /Library/Frameworks/EPD64.framework/Versions/Current/bin/python

Include Path:
/Library/Frameworks/EPD64.framework/Headers

Library Path: /Library/Frameworks/EPD64.framework/Versions/Current/lib/libpython2.7.dylib

Site-Packages: /Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.7/site-packages

Numpy Path:
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numpy/core/include

Sphinx-Build Path:
/Library/Frameworks/EPD64.framework/Versions/Current/bin/sphinx-build

To point the OpenCV to EPD python installation

c. Deactivate “With CUDA” installation option

d. Make sure that BUILD_OPENCV_PYTHON is active (checked)

6. Configure and Generate Cmakefile

7. Open OpenCV.xcodeproj, and then compile all projects under OpenCV project

8. Find a file called cv2.so inside folder:

OpenCV-2.4.1/build/lib/Debug

9. Copy cv2.so to this folder :

/Library/Frameworks/EPD64.framework/Versions/Current/lib/python2.7/site-packages

10. Now, open iPython and execute this command:

>>> import cv2

to test whether the installation is correct or not

— EOF —

Be Sociable, Share!
Categories: Machine Learning

Leave a Reply