Skip to content


Using OpenCV in Sage

OpenCV is an awesome free open source library for computer vision, image processing, and even some machine learning.
Sage is an awesome free open source mathematical software system that integrates many other libraries and software into a single, easy to use interface for all your math needs.

I really like both projects, and have been using them separately, but in this post I will show you how you can use OpenCV in the Sage environment. This means that you will be able to use all the power of the Sage Notebook Server, NumPy, SciPy, Matplotlib, PIL (Python Imaging Library), R, and almost a hundred other open source packages for all your image processing needs.

sage0

The first step is to install the latest version of OpenCV in your system with the new Python bindings. You must have the Python bindings working correctly for this to work. The easiest way of doing this is to follow my own tutorial for installing OpenCV. You can easily change the version for installing the latest OpenCV version that is out there, the tutorial should still work. I used it to install OpenCV 2.4.3 in Ubuntu 12.10, and it worked perfectly.

To make sure that OpenCV is installed correctly, go to the console and start Python by running this command:

python

You should see the python console waiting for you. There, write the following:

import cv2

Importing OpenCV cv2 module into python
If no error appeared, everything is great, you can continue. If there are some errors, you need to fix them first. You can exit with Control-D, or by typing exit().

By the way, currently there are two OpenCV Python modules, cv and cv2. The legacy C version API of OpenCV can be accessed via cv, and the new C++ interface of OpenCV is available via cv2. Therefore, you are encouraged to use cv2 because that’s where the good stuff is.

Now that we have OpenCV with Python correctly installed, we need to install Sage.
First, check if you are running a 32 or 64 bit system by using this command:

uname -m

You will see x86_64, which means 64 bits or something like i686 or i386, which means 32 bits.

Now we need to download Sage from here. You can pick where to download from, as well as if you want the 32 or 64 bits version. I usually download it from the University of Washington which is where the lead developer of Sage, William Stein, teaches math but you can choose any other location that you like. You are looking for a file that has a name similar to this one: sage-5.4.1-linux-32bit-ubuntu_12.04.1_lts-i686-Linux.tar.lzma. For the next steps, I will be using that file. Remember that you may need to change the file or folder names for your specific situation.

After you download the file, you will need to extract it. On the console, change your directory to where you downloaded the file and extract it:

cd ~/Downloads
tar --lzma -xf sage-*

Now you will have to wait for a few minutes for it to decompress a lot of files. Notice how I did not use the verbose option for extracting (I used -xf instead of -xvf). This is because it takes a lot longer to decompress when it has to output every file name. Since nothing is being printed on the screen, it is faster but you may think that nothing is happening. Don’t worry, everything is fine. Just leave it alone until it finishes decompressing.

Now we are going to configure it so that we can call it from anywhere.

mv sage-5.4.1-linux-32bit-ubuntu_12.04.1_lts-i686-Linux sage-5.4.1
sudo mv sage-5.4.1 /opt/
sudo cp /opt/sage-5.4.1/sage /usr/local/bin/
sudo gedit /usr/local/bin/sage
  1. Copy the line that says #SAGE_ROOT=/path/to/sage-version.
  2. Remove the comment character (#) in the line you just copied.
  3. Change the path to /opt/sage-5.4.1 (or the version you are installing).
  4. Save the file and close the editor.

sage_root

And now you can start Sage by using this command anywhere:

sage

You will have to wait for a few moments this first time you run it. You should then see the command prompt of Sage waiting for your input. Exit for now by running this command:

exit

If everything is fine, you can now delete the downloaded file to save some space:

rm ~/Downloads/sage-5.4.1-linux-32bit-ubuntu_12.04.1_lts-i686-Linux.tar.lzma

OK, so now we also have Sage correctly installed in the system.

Let’s install OpenCV into Sage:

cd /usr/local/lib/python2.7/dist-packages/
cp cv2.so /opt/sage-5.4.1/local/lib/python2.7/site-packages/
cp cv.py /opt/sage-5.4.1/local/lib/python2.7/site-packages/
cd ~

To make sure that OpenCV is correctly installed in Sage, go to the console and start Sage by running this command:

sage

You should see the Sage console waiting for you. There, write the following:

import cv2

If no error appeared, everything is great, you can continue. If there are some errors, you need to fix them first. At this point, it should report the following error:

RuntimeError: module compiled against API version 6 but this version of numpy is 4.

This happens because Sage(as of v5.4.1) still comes with an older version of NumPy(v1.5.1). You can tell which is the included version of NumPy by doing this in Sage:

import numpy
numpy.version.version
exit

So, if you have a newer version of Sage (this fix is scheduled for v5.6), and did not get the error, you can skip the next step.

Let’s update Sage’s NumPy to v1.7.0b2 so that we can use OpenCV with it:

cd ~
wget https://spkg-upload.googlecode.com/files/numpy-1.7.0b2.spkg
sage -f numpy-1.7.0b2.spkg

Now you should be able to run OpenCV functions in Sage.

Let’s use the Sage Notebook interface with OpenCV.
Start sage, run notebook(), and follow the instructions for using the notebook interface. For more advanced options for the notebook server, you can check here.

Once you have a new worksheet open, define some functions to convert arrays between NumPy, OpenCV and PIL:

import cv2, numpy, Image, ImageDraw

def cv2np(image):    
    rgbimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    return rgbimage/255.
    
def pil2np(image):
    rgbimage = numpy.array(image)
    return rgbimage/255.
    
def cv2pil(image):
    rgbimage = cv2.cvtColor(lenna, cv2.COLOR_BGR2RGB)
    pilimage = Image.fromarray(rgbimage)
    return pilimage

Now, in another cell let’s load an image and find a face using the trained frontal face model. (Make sure that you change the path to your image):

image_path = "/home/username/OpenCV-2.4.3/samples/c/lena.jpg"
lenna = cv2.imread(image_path, cv2.CV_LOAD_IMAGE_COLOR)
cascade_fn = "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"
cascade = cv2.CascadeClassifier(cascade_fn)
gray = cv2.cvtColor(lenna, cv2.COLOR_BGR2GRAY)
rects = cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=4, minSize=(30,30))
for x1, y1, width, height in rects:    
    faces_rectangle = [x1, y1, x1 + width, y1 + height]
faces_rectangle

If you use lena.jpg, you should see the following result:

[217, 203, 386, 372]

Which is the location of the bounding box of the detected face of Lenna.
Now, let’s use PIL to draw the detection:

lenna_pil = cv2pil(lenna)
draw = ImageDraw.Draw(lenna_pil)
draw.ellipse((x1, y1, x1+width, y1+height), outline="green")
draw.ellipse((x1+1, y1+1, x1+width-1, y1+height-1), outline="green")
draw.ellipse((x1+2, y1+2, x1+width-2, y1+height-2), outline="green")

To be able of changing the thickness of the ellipse in PIL, you need to install the aggdraw module, so I just drew three ellipses instead.

Finally, it is time to show the detection:

matrix_plot(pil2np(lenna_pil)).show( axes=True, frame=True, figsize=8, aspect_ratio=1)

sage_opencv
And that’s it. This is just a simple example of object detection in OpenCV using the Sage environment. Feel free to explore Sage and OpenCV now that you can use them in the same interface.

Posted in Image Processing, Open Source.


Installing OpenCV in the Nokia N900 (maemo)

In this post, I will describe the entire procedure needed to install OpenCV and compile your computer vision applications in the Nokia N900 from scratch. This means that you can make advanced computer vision processing on the go.

First of all make sure that you back up all your N900 data. No kidding. We are going to make some changes that could possibly brick your phone. This means that you may need to re flash your firmware if anything goes wrong. If you are not OK with this, stop reading. I will not be held responsible for any problems you may encounter. You have been warned.

The N900 is an awesome device, it is a Linux computer in the form of a smartphone. Because of that, you can do pretty much anything you could do on a regular Linux computer and more, since you have all the extra features of a smartphone like sensors and a battery. One of the things a regular Linux computer can do is to use an advanced computer vision library (OpenCV), which is the library we are going to install on the N900.

The first step is to configure the repositories. A repository is a place where programs are stored. You can have different repositories available on your system. Each repository that you have enabled in your system allows you to install different sets of programs. Note that on the N900, repositories are called catalogs.

To manage your repositories on your N900, go to the App. Manager and click on the menu on top (where it says Application manager). There, select Application Catalogs.

Here (maybe after waiting a little) you will see the current list of enabled and disabled catalogs. Disabled catalogs are not considered by the system, so all the applications you can install come from the enabled catalogs. Write down which catalogs are enabled and which ones are disabled as this is your original configuration and you may want to go back to it after we are finished.

Now, let’s add some catalogs. Click on the New button and fill in the information provided for the three following catalogs:

Maemo SDK: This catalog provides core system utilities that we will need to build programs.

Catalog Name: Maemo SDK
Web address: http://repository.maemo.org/
Distribution: fremantle/sdk
Components: free non-free
Disabled: Unchecked

Maemo tools: This catalog provides tools that are very useful, like nano or wget.

Catalog Name: Maemo tools
Web address: http://repository.maemo.org/
Distribution: fremantle/tools
Components: free non-free
Disabled: Unchecked

Maemo extras-testing: This catalog provides more applications than the ones in the default Maemo catalog (extras), although they are not as thoroughly tested.

Catalog Name: Maemo extras-testing
Web address: http://repository.maemo.org/extras-testing/
Distribution: fremantle
Components: free non-free
Disabled: Unchecked

These catalogs provide different applications that we will need later. Enable all of them.

Now exit the Application Catalogs screen. The N900 will automatically update the list of applications after you changed the repositories. If you didn’t see any update, click on the Update button just to be sure. Now click on Download->All to see the list of applications available to install. You should install the following apps:

openssh client and server
rootsh
sudser
Personal IP Address

When you install OpenSSH, you will be asked for a password. This is the root password, so keep it safe.

Now close the application manager and open the console (X Terminal). In there, you will setup a password for the default user, which is user. Write this:

sudo passwd user

And write a password for the user user, which is the default user (non root privileges). Close the console or write exit to exit.

OK, on the N900 desktop you now should be able to see your current IP address. You can use that IP to connect via SSH or FTP to your N900 with either root or user using the passwords you just set for them. If you don’t have Linux installed on your computer, you can use Filezilla for FTP and PuTTy for SSH. Make sure that you can connect to your N900 with the user account.

Now we will be working with the command line only, so I suggest you to connect from your computer via SSH (as user) for easier writing (or copy pasting). Make sure that the App. Manager is closed before continuing.

On the console, write the following:

sudo apt-get install build-essential wget grep-gnu libglibmm-2.4-dev nano libpng12-dev libjpeg62-dev libtiff4-dev libgtk2.0-dev unzip

It should install all these packages without a problem. If it asks “Install these packages without verification?” Answer yes.

OK, your N900 is ready to compile software. We are now going to get and install OpenCV by writing the following:

sudo apt-get install libcv4 libhighgui4 libcvaux4 opencv-doc libcv-dev libhighgui-dev libcvaux-dev

Once it is finished installing the packages, go to the App. Manager and disable all of the three repositories we used (Maemo SDK, Maemo Tools, Maemo extras-testing).

Now let’s check that everything is correctly installed. Run this command:

pkg-config --libs --cflags opencv

You should see something similar to:

-I/usr/include/opencv  -lcv -lhighgui -lcvaux -lml -lcxcore

Now you have OpenCV correctly installed in your N900. Great!, now what?.

Let’s compile something. First, download this example that I prepared:

wget http://www.samontab.com/web/files/opencv-n900-test.zip
unzip opencv-n900-test.zip

Compile the project with this line:

g++ -o test main.c `pkg-config --libs --cflags opencv`

And now you can run it with this command:

./test lena.jpg

It will read an image (lena.jpg by default if none is given in the command line), invert the value of the pixels, and save the processed image as processedImage.png.

You should see something like this:

And that’s it. Now you can use OpenCV in your Nokia N900!

Posted in Image Processing, Open Source, Programming.


How I went from obese to normal weight by changing my behavior to lose 20kg (44 pounds)

I was fat, and I was getting fatter every day. On the day that I found out that I was literally obese, I decided to change my behavior so that I could live with a normal weight.
Being the nerd that I am, I started searching for scientific articles that I could use to lose weight and change my behavior. One of the best and simple suggestions that I found about which type of food I should be eating was the healthy eating plate, and since it comes from a respectable source, I decided to test it. Here is the result after basing my food intake on that advice.

Success!. I got into the normal weight range by losing 20kg (44 pounds), and I continue losing weight. By looking at the graph, you may notice that my weight actually increased around May, September, and November. I was traveling abroad those days. That means that it was harder to weigh myself as well as controlling what I was eating. The result of those two things combined?, weight increase. When I got back home, I could weigh myself every day, and control what I was eating, which instantly made me start decreasing my weight again.

After researching on these topics, applying the concepts and actually getting to my goal, I think that these are some of the most important ideas that I learned:

Keep your goal on focus to motivate yourself

It has been reported that focusing on a specific goal gives you better results compared to focusing on accomplishments or not having a goal at all.
Your goal should be something that you can measure, like losing X kg, or staying inside the normal weight BMI range, etc. It is important that your goal can be measured so that every time you weigh yourself you know how close or far away you are from your goal. Also, it allows you to test how good or bad specific behavior changes are for your goal. For example, you could quit drinking alcohol, eat more vegetables, or do more exercises, and see how they affect your specific goal. That way, you will be more motivated to keep the positive behavior changes, and discard the negative ones because you can actually see how they affect your goal.

Weigh yourself everyday, roughly at the same time

You should not be afraid to look at the numbers the scale is showing to you. Those numbers help you to reach your goal, so make sure that you weigh yourself every day and keep a log of it. You can use pen and paper, or a worksheet, or Google Docs, or anything else that you prefer, but make it as simple as possible because otherwise you will not use it.
Your weight changes constantly through the day, so it is best to always measure it at the same time every day. To keep you motivated, I recommend you to weigh yourself in the mornings because that is when you are the lightest. If you are wondering why, take a look at this cool video by Derek from veritasium.

You can eat whatever you like, as long as it is an exception

You should only feed yourself with healthy food on a daily basis. That’s the key. If you have that lifestyle, you can also eat anything you want on certain special occasions, as long as you keep those occasions as exceptions and not as your main food source. Think about it, it doesn’t really matter if you eat a couple slices of pizza and soda once or twice a month, but if you eat it almost every day, you will get fat. Simple. Just keep your daily food intake healthy, and you can eat anything you want on certain occasions. Some examples of this idea are the “cheat day” from the slow-carb diet of Tim Ferris, as well as the concept behind the BBC documentary Eat, fast, & live longer where they suggest very low calorie intake days followed by days where you can eat whatever you want. Remember to check your weight data log to see how those special days affect your goal, so that you can set their frequency correctly.

Posted in General.


Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS

EDIT: I published a new guide using Ubuntu 14.04 LTS and OpenCV 2.4.9 here.

The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.1.

We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces, and Intel Threading Building Blocks (TBB).

OK, so the first step is to make sure that everything in the system is updated and upgraded:

sudo apt-get update
sudo apt-get upgrade

Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal:

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

Time to get the OpenCV 2.4.1 source code:

cd ~
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2
tar -xvf OpenCV-2.4.1.tar.bz2
cd OpenCV-2.4.1

Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python, TBB, OpenGL, Qt, work with videos, etc, here is where we need to set that. Just execute the following line at the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory, which is its parent).

mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

Check that the above command produces no error and that in particular it reports FFMPEG as YES. If this is not the case you will not be able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt are detected.

If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:

Now, you are ready to compile and install OpenCV 2.4.1:

make
sudo make install

Now you have to configure OpenCV. First, open the opencv.conf file with the following code:

sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib


Run the following code to configure the library:

sudo ldconfig

Now you have to open another file:

sudo gedit /etc/bash.bashrc

Add these two lines at the end of the file and save it:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

Now you have OpenCV 2.4.1 installed in your computer with Python, TBB, OpenGL, video, and Qt support.

Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.

If you zoom in enough, you can see the RGB (or intensity) values for each pixel.

Now let’s build some samples included in OpenCV:

cd ~/OpenCV-2.4.1/samples/c
chmod +x build_all.sh
./build_all.sh

Now we are ready to run the examples:

./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg

~/OpenCV-2.4.1/build/bin/grabcut ~/OpenCV-2.4.1/samples/cpp/lena.jpg

~/OpenCV-2.4.1/build/bin/calibration_artificial

python ~/OpenCV-2.4.1/samples/python2/turing.py

Posted in Image Processing, Open Source, Programming.


MPD on the N900 or how to use your Nokia N900 as a Wireless Home Music System

In a previous post, I showed you how to listen on any device the music you have stored on a Symbian phone. In this post, I will teach you to do the opposite: control the music being played on your N900 with any device. The nice thing about this is that you can connect your N900 to your main speakers. That way, you will be using your Nokia N900 as a wireless home music system that is small, quiet and portable. After finishing this tutorial, you will also be able to connect to your N900 via SSH and FTP, manage your software repositories, compile applications, and setup scripts to be run at boot time.

First of all make sure that you back up all your N900 data. No kidding. We are going to make some changes that could possibly brick your phone. This means that you may need to re flash your firmware if anything goes wrong. If you are not OK with this, stop reading. I will not be held responsible for any problems you may encounter. You have been warned.

The N900 is an awesome device, it is a Linux computer in the form of a smartphone. Because of that, you can do pretty much anything you could do on a regular Linux computer and more, since you have all the extra features of a smartphone like sensors and a battery. One of the things a regular Linux computer can do is to play music with a great program called Music Player Daemon (MPD), which is the program we are going to install on the N900.

The first step is to configure the repositories. A repository is a place where programs are stored. You can have different repositories available on your system. Each repository that you have enabled in your system allows you to install different sets of programs. Note that on the N900, repositories are called catalogs.

To manage your repositories on your N900, go to the App. Manager and click on the menu on top. There, select Application Catalogs.

Here (maybe after waiting a little) you will see the current list of enabled and disabled catalogs. Disabled catalogs are not considered by the system, so all the applications you can install come from the enabled catalogs. Write down which catalogs are enabled and which ones are disabled as this is your original configuration and you may want to go back to it after we are finished.

Now, let’s add some catalogs. Click on the New button and fill in the information provided for the four following catalogs:

Maemo SDK: This catalog provides core system utilities that  we will need to build programs.

Catalog Name: Maemo SDK
Web address: http://repository.maemo.org/
Distribution: fremantle/sdk
Components: free non-free
Disabled: Unchecked

Maemo tools: This catalog provides tools that are very useful, like nano or wget.

Catalog Name: Maemo tools
Web address: http://repository.maemo.org/
Distribution: fremantle/tools
Components: free non-free
Disabled: Unchecked

Maemo extras-testing: This catalog provides more applications than the ones in the default Maemo catalog (extras), although they are not as thoroughly tested.

Catalog Name: Maemo extras-testing
Web address: http://repository.maemo.org/extras-testing/
Distribution: fremantle
Components: free non-free
Disabled: Unchecked

Maemo extras-devel: This catalog contains many useful applications but some of them are in heavy development. This catalog should be disabled by default and enabled only temporarily to install specific applications. Make sure that you disable Maemo extras-devel when you add it.

Catalog Name: Maemo extras-devel
Web address: http://repository.maemo.org/extras-devel/
Distribution: fremantle
Components: free non-free
Disabled: Checked

These catalogs provide different applications that we will need later. Disable Maemo extras-devel and enable the other three.

Now exit the Application Catalogs screen. The N900 will automatically update the list of applications after you changed the repositories. If you didn’t see any update, click on the Update button just to be sure. Now click on Download->All to see the list of applications available to install. You should install the following apps:

openssh client and server
rootsh
sudser
Personal IP Address

When you install OpenSSH, you will be asked for a password. This is the root password, so keep it safe.

Now close the application manager and open the console (X Terminal). In there, you will setup a password for the default user, which is user. Write this:

sudo passwd user

And write a password for the user user, which is the default user (non root privileges). Close the console or write exit to exit.

OK, on the desktop you now should be able to see your current IP address. You can use that IP to connect via SSH or FTP to your N900 with either root or user using the passwords you just set for them. If you don’t have Linux installed on your computer, you can use Filezilla for FTP and PuTTy for SSH. Make sure that you can connect to your N900 with the user account.

Now we will be working with the command line only, so I suggest you to connect from your computer via SSH (as user) for easier writing (or copy pasting). Make sure that the App. Manager is closed before continuing.

On the console, write the following:

sudo apt-get install build-essential wget grep-gnu libglibmm-2.4-dev nano mpc libao0 libaudiofile-dev libaudiofile0 libcurl3-dev libcurl3 libpulse-dev pulseaudio libavcodec-dev

It should install all these packages without a problem. When it is finished, go to the App. Manager, enable Maemo extras-devel and then close the App. Manager. Ignore any updates that are offered by your phone at this point.

Now go back to the console, and write the following (make sure that the App. Manager is closed before you do so):

sudo apt-get install libasound2-dev libmad0-dev libid3tag0-dev libflac-dev libflac++-dev

If  it asks “Install these packages without verification?” Answer yes.

Once it is finished installing the packages, go to the App. Manager and disable all of the four repositories we used (Maemo SDK, Maemo Tools, Maemo extras-testing, Maemo extras-devel).

OK, now your N900 is ready to compile software. We are now going to get and compile Music Player Daemon (MPD).

Open the console (X Terminal) and write the following:

cd
mkdir tempdelme
cd tempdelme
wget http://downloads.sourceforge.net/project/musicpd/mpd/0.16.6/mpd-0.16.6.tar.gz
tar -xvzf mpd-0.16.6.tar.gz
cd mpd-0.16.6/
./configure
make
sudo make install

After some time, it should be ready. Now MPD is installed in /usr/local/bin/mpd. Check that everything is OK with this command (Thanks Martin for suggesting the –no-daemon option):

/usr/local/bin/mpd --version --no-daemon

It should display the formats it is able to play (i.e. mp3, flac, wav, etc). If you need more functionality than what is presented, install the extra needed libraries and then run ./configure; make; sudo make install again. Most people should be OK with the current settings.

Now that we have MPD installed, we need to configure it. Write this:

nano /home/user/.mpdconf

This will open a text editor. Write the following in there:

port                    "6600"
music_directory         "/home/user/MyDocs/music"
playlist_directory      "/home/user/.mpd/playlists"
db_file                 "/home/user/.mpd/mpd.db"
log_file                "/home/user/.mpd/mpd.log"

user "user"

bind_to_address "any"

audio_output {
        type            "alsa"
        name            "MPD ALSA"
        mixer_type      "software"
}

Make sure that all your music files and folders are inside the defined music_directory.

Now let’s create those directories

mkdir -p /home/user/.mpd/playlists
mkdir -p /home/user/MyDocs/music

And now put some music files in the music_directory that you defined previously. You can use FTP to easily transfer music from your PC to that folder in the N900. After you put some music,  generate the MPD database:

sudo /usr/local/bin/mpd --create-db

Now we can start MPD with this:

sudo /usr/local/bin/mpd /home/user/.mpdconf

Test that everything is working:

mpc update
mpc add /
mpc play

If you hear music, then everything is great. You can stop the music with:

mpc stop

You can now delete the temporary files we used for the compilation:

cd
rm -r tempdelme

OK, so now MPD is installed on your N900. You can connect with any client to it. Actually, we just connected with one of them, mpc, a console client for MPD.

If you are using firefox, you can use Music Player Minion. If you have an IPod/IPhone/IPad/etc… you can use MPoD. There are many clients for MPD, virtually for any device that you may have at your house.

Enjoy playing with your cool new wireless home sound system.

The last (optional) step is to launch MPD automatically when you power up your phone. The N900 uses upstart to control the boot scripts, so let’s create an upstart script for MPD:

sudo nano /etc/event.d/mpd

In that file, write the following:

start on started hildon-desktop

script
exec /usr/local/bin/mpd /home/user/.mpdconf
end script

stop on starting shutdown

That’s it. Reboot your phone and MPD should be running. You can check it by using the same music test from before, or directly looking at the process:

ps aux | grep mpd

If it says something like this:

1630 user     46276 S    /usr/local/bin/mpd /home/user/.mpdconf
1642 user      2088 S    grep mpd

It means that MPD is running. If on the other hand only the second line appears, it means it is not running.

You can close MPD by killing the process like this:

killall mpd

Finally, note that depending on your battery saving settings your N900 may disable wifi connections initiated from outside (like your SSH or FTP connections) after some inactivity time. You can make sure that the wifi connection keeps open by just pinging the router:

sudo ping 192.168.0.1

Enjoy.

Posted in General, Open Source, Programming.


Use your old Nokia symbian phone as a music web server

If you have a Wi-Fi capable Nokia Symbian phone with a memory card and also a Wi-Fi router, you can use them to serve your music at home. This is a great way of having all your music in just one place and access it from any wireless capable device (i.e. laptops) as well as sharing it with others at your house. Also, you could still enjoy the same music on the go since it is stored on your mobile phone. This means that you can turn an old unused mobile phone into a very small and noiseless music server for free.

OK, the first step is to install PAMP. This is a web server for mobile phones. It contains Apache, MySQL and PHP, all in one nice installable sis package for your phone.
To install it, just go here and download the file named pamp_1_0_2.zip (not the SDK one).
Extract the files. Notice that there are three .sis files. First install pips_nokia_1_3_SS.sis, then install ssl.sis and finally install pamp_1_0_2.sis.
Now you should have a PAMP application on your phone. Open it. You should see something like this:

Now, click on Options and then select Start->Pamp. Answer Yes to the Start WLAN? question and select your home wireless network.

You should now see that Apache and MySQL services are running, the name of your wireless network and the assigned IP number. That number is the one you need to connect to your phone. Write it down. It should look something like this:

Let the PAMP application running on the background as is. You can do that by just pressing your Home button. Now let’s check that everything is working so far. In your laptop open up Firefox (or any other web browser) and type in the IP address from the previous step. You should see something like this:

If you see the something similar, the Apache server is working. Now follow the phpinfo.php link. It should display information about your mobile server (cool, isn’t it) like this:

The web pages that you are looking at now are stored in the phone at E:/DATA/apache/htdocs. E: represents the memory card. This is the public folder that is being served by PAMP. The index.html file is the home page being displayed, and phpinfo.php is the link you just visited.

You may edit these web pages if you wish. You can install Y-Browser to navigate your documents or create folders in your phone. Also, you can install ped for editing text files on your phone (this one requires Python for S60 to be installed first). You can also edit the files on your PC and then transfer them back to your phone.

The next step is to download whispercast which is a lightweight PHP script for music streaming, perfect for our needs (Thanks Manas Tungare for making this cool script!). On your Desktop, create a folder called music (it has to be exactly this name to make it work without configuring anything else). Extract all the files from the zip you just downloaded into this folder. Now add all the mp3 files that you want into the music folder as well. Each directory of mp3 files will be a play-list.

Now you need to transfer the entire music folder (not just the contents, the folder itself too) into the phone, inside the E:/DATA/apache/htdocs folder.

It is now time to go to your laptop and type in the IP address followed by /music. For example, if your IP is 192.168.0.100, then you need to go to 192.168.0.100/music. You should now see the text Manas Tungare’s Music Library, with the list of your mp3 files. Navigate to the folder/play-list you want to hear and click on Start Playing. It will create a play-list on the fly and ask you to select the music player that you want to use. If in doubt, just select the default player. After that, you can just save the play-list and double click on it or create a new one visiting the same page.

If you need to tweak some parameters, just edit the config.php file. For changing the format or text displayed, you can edit the other files.

That’s it, now you can listen to your music from anywhere in your house with a small and noise free music server. It should work for Linux, Windows, Mac, or even other mobile phones or tablets.

Posted in General.


Installing OpenCV 2.2 in Ubuntu 11.04

UPDATE: You can also install OpenCV 3.2.0 in Ubuntu 16.04LTS.

Many people have used my previous tutorial about installing OpenCV 2.1 in Ubuntu 9.10. In the comments of that post, I noticed great interest for using OpenCV with Python and the Intel Threading Building Blocks (TBB). Since new versions of OpenCV and Ubuntu are available, I decided to create a new post with detailed instructions for installing the latest version of OpenCV, 2.2, in the latest version of Ubuntu, 11.04, with Python and TBB support.

First, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal


sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev

Now we need to get and compile the ffmpeg source code so that video files work properly with OpenCV. This section is partially based on the method discussed here.

cd ~
wget http://ffmpeg.org/releases/ffmpeg-0.7-rc1.tar.gz
tar -xvzf ffmpeg-0.7-rc1.tar.gz
cd ffmpeg-0.7-rc1
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libxvid --enable-x11grab --enable-swscale --enable-shared
make
sudo make install

The next step is to get the OpenCV 2.2 code:

cd ~
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.2/OpenCV-2.2.0.tar.bz2
tar -xvf OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0/

Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python and TBB with OpenCV, here is where we set that. Just execute the following line at the console to create the appropriate Makefile. Note that there is a dot at the end of the line, it is an argument for the cmake program and it means current directory.

cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON .

Check that the above command produces no error and that in particular it reports FFMPEG as 1. If this is not the case you will not be able to read or write videos. Also, check that Python reports ON and Python numpy reports YES. Also, check that under Use TBB it says YES. If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:

Now, you are ready to compile and install OpenCV 2.2:

make
sudo make install

Now you have to configure OpenCV. First, open the opencv.conf file with the following code:

sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib

Run the following code to configure the library:

sudo ldconfig

Now you have to open another file:

sudo gedit /etc/bash.bashrc

Add these two lines at the end of the file and save it:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

There is a final step to configure Python with OpenCV. You need to copy the file cv.so into the correct place. You can do that by just executing the following command:

sudo cp /usr/local/lib/python2.7/site-packages/cv.so /usr/local/lib/python2.7/dist-packages/cv.so

Now you have OpenCV 2.2 installed in your computer with Python and TBB support.

Let’s check some demos included in OpenCV.
First, let’s see some C demos:

cd ~/OpenCV-2.2.0/samples/c
chmod +x build_all.sh
./build_all.sh

Some of the training data for object detection is stored in /usr/local/share/opencv/haarcascades. You need to tell OpenCV which training data to use. I will use one of the frontal face detectors available. Let’s find a face:

./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

Note the scale parameter. It allows you to increase or decrease the size of the smallest object found in the image (faces in this case). Smaller numbers allows OpenCV to find smaller faces, which may lead to increasing the number of false detections. Also, the computation time needed gets larger when searching for smaller objects.

You can also detect smaller objects that are inside larger ones. For example you can search for eyes inside any detected face. You can do that with the nested-cascade parameter:

./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/opencv/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg


Feel free to experiment with other features like mouth or nose for example using the corresponding cascades provided in the haarcascades directory.

Now let’s check some C++ demos:

cd ~/OpenCV-2.2.0/samples/cpp
make

Now all the C++ demos are built in ~/OpenCV-2.2.0/bin. Let’s see a couple of them. For example, a simulated chessboard calibration:

~/OpenCV-2.2.0/bin/calibration_artificial


In OpenCV 2.2, the grabcut algorithm is provided as a C++ sample. This is a very nice segmentation algorithm that needs very little user input to segment the objects in the image. For using the demo, you need to select a rectangle of the area you want to segment. Then, hold the Control key and left click to select the background (in Blue). After that, hold the Shift key and left click to select the foreground (in Red). Then press the n key to generate the segmentation. You can press n again to continue to the next iteration of the algorithm.

~/OpenCV-2.2.0/bin/grabcut ~/OpenCV-2.2.0/samples/cpp/lena.jpg

This image shows the initial rectangle for defining the object that I want to segment.

Now I roughly set the foreground (red) and background (blue).

When you are ready, press the n key to run the grabcut algorithm. This image shows the result of the first iteration of the algorithm.

Now let’s see some background subtraction from a video. The original video shows a hand moving in front of some trees. OpenCV allows you to separate the foreground (hand) from the background (trees).

~/OpenCV-2.2.0/bin/bgfg_segm ~/OpenCV-2.2.0/samples/c/tree.avi

And finally, let’s see Python working with OpenCV:

cd ~/OpenCV-2.2.0/samples/python/

Let’s run the kmeans.py example. This script starts with randomly generated 2D points and then uses a clustering method called k-means. Each cluster is presented in a different color.

python kmeans.py

Now let’s see the convexhull.py demo. This algorithm basically calculates the smallest convex polygon that encompasses the data points.

python convexhull.py

Python scripts can also be executed directly like the following example. This script reads a video file (../c/tree.avi) within pyhton and shows the first frame on screen:

./minidemo.py


Have fun with OpenCV in C, C++ or Python…

Posted in Image Processing, Open Source, Programming.


Create installable applications (.sis files) from your Python scripts for Symbian

Python is great. It makes everything simple. Also, it can be run almost anywhere, even on your Nokia smartphones. In this post I will show you how to create an installable application (.sis file) from your Python scripts.

The first step is to install Python 2.5 on your computer. It has to be 2.5. If you have a newer version of Python installed, either downgrade to 2.5 or create a local folder with Python 2.5 executable on it and make sure you use that version. You can install Python 2.5 from here.

If you are on Ubuntu, probably you have a newer version of Python. Just get the source and compile it locally:

cd ~
mkdir py2sis
cd py2sis
wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
tar -xvzf Python-2.5.4.tgz
rm Python-2.5.4.tgz
cd Python-2.5.4
./configure
make

OK, so now we should have a local copy of Python 2.5.4. To test that everything is fine, run the following command:

~/py2sis/Python-2.5.4/python --version

It should report Python 2.5.4. Windows or Linux users that installed Python 2.5.4 on their entire system can always substitute ~/py2sis/Python-2.5.4/python by just python. For them, the following command should report the same result:

python --version
 

Now, we need to get the utilities that will allow us to create the sis files. That software is called ensymble. We need exactly this file: ensymble_python2.5-0.27.py

 cd ~/py2sis
wget http://ensymble.googlecode.com/files/ensymble_python2.5-0.27.py
~/py2sis/Python-2.5.4/python ~/py2sis/ensymble_python2.5-0.27.py version
 

You should get this result: Ensymble v0.27 2008-06-30.

Now let’s get PythonForS60 sis file that will be installed alongside your script. We need the file PythonForS60_1_4_5_3rdEd.sis.

cd ~/py2sis
wget http://sourceforge.net/projects/pys60/files/pys60/1.4.5/PythonForS60_1_4_5_3rdEd.sis/download
mv download PythonForS60_1_4_5_3rdEd.sis

All done configuring the tools. Now we are going to create a Python script.

cd ~
mkdir myFirstScript
cd myFirstScript
gedit default.py &

Here you can put any Python code for Symbian S60. Let’s start with something simple. Write this and save the file:

import appuifw
appuifw.note(u"Hello Symbian/Python World", "info")

Time to create your first Python SIS file. Execute the following:

cd ~
~/py2sis/Python-2.5.4/python ~/py2sis/ensymble_python2.5-0.27.py py2sis myFirstScript

It should generate a file called myFirstScript_v1_0_0.sis. This is the sis file for your script. If you already have PythonForS60 sis installed in your phone, it should work. Most of the time though, users will not have it, so let’s merge the two into just one sis:

cd ~
~/py2sis/Python-2.5.4/python ~/py2sis/ensymble_python2.5-0.27.py mergesis myFirstScript_v1_0_0.sis ~/py2sis/PythonForS60_1_4_5_3rdEd.sis myFirstScript_v1_0_0_with_Python.sis

Now, you can just install myFirstScript_v1_0_0_with_Python.sis in your Nokia Symbian S60 3rd edition phone (like the E71 for example) and when you open it, you should see something like this:

Great, so now let’s automate this using a script:

sudo touch /usr/local/bin/py2sis.sh
sudo chmod +x /usr/local/bin/py2sis.sh
sudo gedit /usr/local/bin/py2sis.sh &

Write these commands on the file:

#!/bin/bash
echo "Creating script sis file..."
~/py2sis/Python-2.5.4/python ~/py2sis/ensymble_python2.5-0.27.py py2sis myFirstScript
echo "Merging script sis file with Python for S60 sis file..."
~/py2sis/Python-2.5.4/python ~/py2sis/ensymble_python2.5-0.27.py mergesis myFirstScript_v1_0_0.sis ~/py2sis/PythonForS60_1_4_5_3rdEd.sis myFirstScript_v1_0_0_with_Python.sis
echo "Done."

Now let’s test it erasing the files we just created and then generating them with the script:

cd ~
rm myFirstScript_v1_0_0*
py2sis.sh

It should create the same 2 sis files we just created before manually. Now, let’s edit the script so that we can tell it where is our source code and set other options:

sudo gedit /usr/local/bin/py2sis.sh &

Replace the existing code with this:

#!/bin/bash

#Check that only 1 parameter is passed (the directory of your script)
EXPECTED_ARGS=1
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [ScriptDirectory]"
exit -1
fi

#This is the directory where your Python for S60 Script is
PYTHON_SCRIPT_DIR=$1

#Application parameters
APP_SCRIPT_SIS_NAME="myApp.sis"
APP_SCRIPT_WITH_PYTHON_SIS_NAME="myApp_with_python.sis"
APP_NAME="My App"
APP_VERSION="1.0.0"
APP_SHORT_CAPTION="Short description."
APP_CAPTION="Here you can describe your application in more detail."
#Icon path. It should be a Tiny SVG compatible icon.
#To add an app icon, just uncomment the following line and edit the path to point to your icon
#APP_ICON=--icon="/path/to/your/icon.svg"

#Environment variables
PYTHON_PATH=~/py2sis/Python-2.5.4/python
ENSYMBLE_PATH=~/py2sis/ensymble_python2.5-0.27.py
PYTHON_FOR_S60_PATH=~/py2sis/PythonForS60_1_4_5_3rdEd.sis

echo "Creating script sis file..."
"${PYTHON_PATH}" "${ENSYMBLE_PATH}" py2sis --appname="${APP_NAME}" --version="${APP_VERSION}" --shortcaption="${APP_SHORT_CAPTION}" --caption="${APP_CAPTION}" ${APP_ICON} "${PYTHON_SCRIPT_DIR}" "${APP_SCRIPT_SIS_NAME}"
echo "Merging script sis file with Python for S60 sis file..."
${PYTHON_PATH} ${ENSYMBLE_PATH} mergesis ${APP_SIS_NAME} ${PYTHON_FOR_S60_PATH} ${APP_SCRIPT_WITH_PYTHON_SIS_NAME}
echo "Done."

There you can set many parameters for your app, like the name, icon, description, and more. Now you should be able to convert your Python scripts to a sis file by just doing this:

py2sis.sh ScriptDirectory

Remember to name the main script default.py since that is the file that ensymble is looking for inside the script folder.

Let’s test this new script, erasing the sis files and then executing this script to generate new sis files:

cd ~
rm myFirstScript_v1_0_0*
py2sis.sh myFirstScript

You should see now a myApp.sis and a myApp_with_python.sis files. Note that those were the properties set in the script. Anytime you want to change these settings, just run this and edit them directly:

sudo gedit /usr/local/bin/py2sis.sh &

OK, now go and create some cool Python apps in no time for your Nokia phone. Check out this excellent Symbian for S60 tutorial made by a fellow Nokia Forum Champion, Jurgen Scheible.

Posted in Programming.


Nokia Developers Day in Santiago, Chile

Over one hundred people attended the first Nokia Developers Day in Santiago, Chile. The event was held at the Pontificia Universidad Católica de Chile, which is the university where I have been teaching a course about development of mobile phone applications, at the computer science department.

The first part of the event was a general introduction to the current market strategy and opportunities that Nokia is providing to the local developers. One of the most important topics covered was that Nokia supports global payment via network operators. This means that people around the world can pay for your application without using their credit cards, which makes it easier to sell for the developer. Another important point is that feature phones, of which Nokia still has a large market share, are getting smarter every day. This means that feature phones now support touch UI, have capable CPUs, and new APIs are appearing for them, such as the Nokia Maps API.  On top of this data plans are getting cheaper, so many people are getting always on connectivity with these devices.  At the end of this session, key players from local development companies presented their experience developing for Nokia handsets.

In the second half, I presented the Qt framework for software development on multiple platforms with a focus on Symbian. The idea of the talk was to motivate the use of Qt for mobile phone application development, based on the fact that it is a mature framework, with more than 18 years of development. The mixture of a powerful framework, such as Qt, with integrated sensors,  Sebastian Montabonesuch as GPS, accelerometers, cameras, bluetooth, etc…, gives the developers the ability to create innovative applications easily. Some examples of these applications are mixed or augmented reality type of applications. You can use the GPS to locate yourself broadly, then you can use the accelerometer to know where the device is pointing at. After that, you can use the camera to process what the phone is looking at since the whole world is filtered to just a small area. This is just an example of which type of applications you can develop since with these tools your imagination is the limit. Also, since Qt is a multi platform SDK, you can port your application to Windows, Linux, Mac, and others simply by selecting that platform from a drop down menu and clicking the compile button.

Posted in General, Qt.


How to install Redmine 1.1.2 on Ubuntu Server 10.04

Redmine is an excellent project management tool written using Ruby on Rails. It provides everything you need to organise your workplace or personal projects. Once you see it working you definitely will want to use it on your own projects. Everything is great until you want to install it since redmine only works with very specific versions of its dependencies. There are many steps that you need to take into consideration, even if you install the outdated version in the repositories. In this guide, I will show you how to install redmine 1.1.2 (the latest version at the time of writing) on Ubuntu Server 10.04 32 bits (latest LTS version at the time of writing).

Make sure that you installed Ubuntu Server 10.04 with SSH (optional) and LAMP support. Both can be selected to be automatically installed at the end of the normal Ubuntu Server 10.04 installation. Once it is installed, remember to update and upgrade your system.

sudo apt-get update
sudo apt-get upgrade

First, let’s install some dependencies:

sudo apt-get install ruby1.8-dev rubygems1.8 libmysql-ruby libmysqlclient-dev rake libopenssl-ruby libapache2-mod-passenger imagemagick libmagickcore-dev libmagickwand-dev

Now we can install the required packages for ruby, or gems. Note that some packages will take a long time to install and provide no output, so just be patient. Also, you will see some warnings like No definition for X. Ignore those, they mean that some documentation was not installed, and we can live with that.

sudo gem install rails -v=2.3.5
sudo gem install mysql
sudo gem install ruby-openid
sudo gem install i18n -v=0.4.2
sudo gem install passenger
sudo gem install rmagick

Now we have to prepare the database. Enter the MySQL console as root:

mysql -uroot -p

Provide the root password. This is the password you set in the early LAMP installation. Now, inside the MySQL console, execute these commands:

create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'myPassword';
grant all privileges on redmine.* to 'redmine'@'localhost';
exit

Remember to change myPassword with your actual password. This is the one that will be used for the user redmine in the database redmine at localhost.

Now it is time to get the redmine code. Execute the following commands to get redmine 1.1.2.

cd ~
wget http://rubyforge.org/frs/download.php/74419/redmine-1.1.2.tar.gz
tar -xvzf redmine-1.1.2.tar.gz
cd redmine-1.1.2

Now setup the database configuration file to match our current environment:

cp config/database.yml.example config/database.yml
nano config/database.yml

Put the details of the database on the specific fields, in particular username and password. Username should be redmine and password should be myPassword or the one you provided before. Make sure that you change both, production and development sections. When you are finished, just hold Control and then press X. This is the command for exiting nano. It will ask if you want to save the changes, just press y (as in yes) and hit enter. That’s it, file saved and back to the console.

Now do the same for configuring email:

cp config/email.yml.example config/email.yml
nano config/email.yml

For this example, we are going to use gmail, but you can use any email settings that you need. Make sure that address is smtp.gmail.com, port is changed to 587, domain is set to gmail.com (or your host if you use google apps) and that the user_name and password are your credentials. Also, make sure that you add a tls: true line. And finally, the most important part, is that you change login with plain in authentication.

production:
 delivery_method: :smtp
 smtp_settings:
 address: smtp.gmail.com
 port: 587
 tls: true
 domain: gmail.com # or your domain
 authentication: :plain
 user_name: fancyUsername@gmail.com # or your domain
 password: secretPassword

For gmail to work, we need to install a script. Let’s get it:

sudo apt-get install git-core
ruby script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git

Let’s proceed with the installation:

rake generate_session_store
sudo mkdir /opt/redmine
cd /opt/redmine
sudo cp -r ~/redmine-1.1.2 .
cd redmine-1.1.2
sudo RAILS_ENV=production rake db:migrate
sudo RAILS_ENV=production rake redmine:load_default_data

Press enter to accept the default language (English) and then execute the following:

sudo chown -R www-data:www-data files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets
sudo nano /etc/apache2/mods-available/passenger.conf

Add this line inside the <IfModule mod_passenger.c> tag:

PassengerDefaultUser www-data

Now let’s configure apache:

sudo nano /etc/apache2/sites-available/default

Just before the closing tag, </VirtualHost>, add the following:

RailsEnv production
RailsBaseURI /redmine

Now we put a link to our application to be accessible from apache and restart it:

sudo ln -s /opt/redmine/redmine-1.1.2/public /var/www/redmine
sudo /etc/init.d/apache2 restart

Some clean up…

cd ~
rm -r redmine-1.1.2
rm redmine-1.1.2.tar.gz

The installation process is finished. Open a web browser in another computer and go to yourServerIP/redmine and you should see the initial page of redmine. If it does not show, then something is wrong in your installation. Go back and carefully follow the steps from the beginning. If you do not know your IP address, just run ifconfig from the server.

Click on Sign-in. Enter admin for user and password. Now you are logged in as the redmine administrator. Go to Administration and then click on Information. You should see the following:

Note that Redmine 1.1.2 stable is installed correctly with RMagick and the directories that it needs are writeable. The only thing left to do here is to change the details of the administrator account (that is why there is one error sign), and start creating users and projects and manage them with this great tool. Once you change your administrator account, you should see no errors on the information page:

And now you can enjoy all the features of this great project manager: Gantt charts, Roadmaps, wiki, file repositories, multiple project support, forums, and much more…

Posted in General, Open Source, Programming.