Installing OpenCV on Mac OS X Snow Leopard

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. Version 2 ships with Python bindings and simply you can “import cv” module in Python after you’ve installed it.

The easiest way to install OpenCV on Mac is to use package management systems like port, fink or homebrew. They will automatically download, compile and install needed packages for you.

In this tutorial I’ll use brew, how ever you can use your preferred package manager.

Here is the short explanation of the installation process (every thing will be done on Terminal.app)

1. Install brew package manager. (instructions here)
2. Update brew formulas:

brew install git
brew update

3. Install opencv:

brew install opencv

and brew will automatically installs CMake and checks out opencv repository, Builds and installs it.

Note that you should edit your PYTHONPATH to make opencv working with Python. I wrote a simple script to do this automatically for Python 2.6 (Also brew should be installed on it’s default location).

RND=/tmp/$RANDOM
PYTHONPATH=`echo $PYTHONPATH | sed -e 's/\/usr\/local\/lib\/python2.6\/site-packages\/://g'`
cat ~/.bash_profile | grep -Ev "PYTHONPATH" > $RND
echo export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:"'$PYTHONPATH' >> $RND
mv $RND ~/.bash_profile

Just copy the script above and type:

pbpaste | sh

Close the Terminal and reopen it.

Now you can simply open your Python interpreter and type “import cv”.

Done. :)

Installing Eric5 on Mac

Eric IDE is a Cross-Platform Python and Ruby IDE, written in Python based on Qt toolkit. It looks really nice and powerful.

Recently I tried to install it on my Mac and had some troubles. Finally I managed to make it running and now I’d like to make a step-by-step installation tutorial:

1. Install Python 3:

Download and install Python 3.

2. Install GCC Compilers:

You will need GCC compilers to compile some source packages. The easiest way to install them is to Install XCode. You can download it here or install it from your OS X installation DVD.

3. Install Qt SDK:

Download Qt SDK for Mac. The installation process is pretty simple and straightforward.

4. Install SIP, PyQt4 and QScintilla2:

First, Grab SIP Linux, UNIX, MacOS/X source, PyQt4 MacOS/X source and QScintilla2 Linux, UNIX, MacOS/X source and extract them all in a directory. It’s also a good idea to rename the directories to something more comfortable:

Then open a terminal window and navigate into the path you’ve extracted source packages before, and execute the following commands:

cd sip-4.12
python3 configure.py --arch i386
make
sudo make install

cd ../PyQt-4.8.2
python3 configure.py --use-arch i386
make
sudo make install

cd ../QScintilla-2.4.6/Qt4
qmake --spec macx-g++ qscintilla.pro
make
sudo make install

cd ../Python
python3 configure.py
make
sudo make install

5. Install Eric5:

Download Eric5 and extract it somewhere.
Open the Terminal and navigate into the directory you’ve extracted Eric5 before and execute the following command:

sudo python3 install.py

Congratulations :) Now you can open Eric5 IDE by executing eric5 (ex. in the Terminal).

Hope it helps.

VPN Auto Connect Script for Mac

One good thing about OS X is the AppleScript. It’s simple, powerful and useful. You can simply automate your tasks with it and make your life easier. A few month ago I wrote a VPN Auto Connect Script to keep my VPN connection alive and now I would like to share it :)

Open your desired Editor or use OS X AppleScript Editor(Application/Utilities/AppleScript Editor) and Paste the following code (note that you should change “VPN” to your connection name at line 4):

on idle
	tell application “System Events”
		tell current location of network preferences
			set myConnection to the service “VPN”
			if myConnection is not null then
				if current configuration of myConnection is not connected then
					connect myConnection
				end if
			end if
		end tell
		return 120
	end tell
end idle

Save the script as Application and check Stay Open:

Save Script as Application

And now, when you open VPN Auto Connect, It automatically dials the connection every 120 sec.

When you open the Application, it’s icon will be appeared on the dock which is a bit annoying. To solve this problem we’ll make it an agent:

Right-Click on the Application Icon and click Show Package Contents.

Open Contents/Info.plist (you will need XCode or another PList Editor to edit Info.plist file). Click Add Item, select “Application is agent (UIElement)” and check it:

Application is agent (UIElement)

Save the file and now your Application package should be ran with no icons on the dock.

You may want to add it to Login Items to make it open automatically at login. There are a few ways to do that but the most simple way is to drag the application into the dock, Right-Click on it and select Options/Open at Login, and finally Drag it off to remove it from the dock.

You can also download my script here. (Note that it only works if your connection name is VPN so you should edit vpn-auto-connect.app/Contents/Resources/Scripts/main.scpt to set the connection name).

That’s all folks :) hope you liked it.

Follow

Get every new post delivered to your Inbox.