Saturday, May 17, 2014

OpenCV 2.4.9 on Ubuntu 14.04

OpenCV 2.4.9 was released on April 2014. See more here.

This is another post in a series of walkthroughs that will hopefully make your life easier to configure, compile, install and test it out.

The dependencies are divided into categories. I have only tested it with GTK.

If you don't need the latest OpenCV then you can easily install version 2.4 using apt:
sudo apt-get install libopencv-dev
If you wanna use the latest version, then follow the steps above:

Install Dependencies


Essentials
These are libraries and tools required by OpenCV.
sudo apt-get install build-essential checkinstall cmake pkg-config yasm

Image I/O
Libraries for reading and writing various image types. If you do not install then the versions supplied by OpenCV will be used.
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev


Video I/O
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev

Python
Packages needed to build the Python wrappers.
sudo apt-get install python-dev python-numpy

Other third-party libraries
Install Intel TBB to enable parallel code in OpenCV.
sudo apt-get install libtbb-dev

GUI
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section) but I haven't tested it with QT on Ubuntu 14.04 yet. 
sudo apt-get install libqt4-dev libgtk2.0-dev

Download Compile & Install

Get a copy of the source code here, extract and create a build directory:
unzip opencv-2.4.9.zip
cd opencv-2.4.9/
mkdir build
cd build
Configure using CMake. You have a lot of options in this step. This is what I use:
cmake -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
If you add -D WITH_QT=ON, the highgui module will use QT instead of GTK. For more information on the options, look at the CMakeLists.txt file. When you are happy with the configuration you have, you can start compiling:
make
If compilation finishes without errors, you can install by saying:
sudo make install
Finally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/lib
And then configure dynamic linker run-time bindings:
sudo ldconfig

Testing

An easy way to test that the compilation went well is to use the OpenCV tests and samples. For example, go to opencv-2.4.9/build/bin and run:
./cpp-example-opencv_version
You should get the correct version.

If you run other tests notice that some failures come from missing image files. To correctly run these tests or samples you should move the corresponding image files from opencv-2.4.9/samples to OpenCV-2.4.9/build/bin.

For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
make
This should compile and run with a test image, so you should see something like this:


Tuesday, July 2, 2013

Command line tips


The intention of this post is to collect a list of my favorite command line tips. Feel free to leave yours in the comment section.

  • Instead of using clear you can just press ctrl-r.
  • The command units can be used for any unit conversion you can imagine. See man page.
  • You can use multitail to monitor multiple log files on a terminal.

Sources:

Saturday, June 22, 2013

Extract decimals from text using grep

Let's say you have a log file that looks like this:
I/Profiling: TimeInterval1:  3271.72 ms
I/Profiling: TimeInterval1:  3379.15 ms
I/Profiling: TimeInterval1:  3645.32 ms
...
and you want to extract all decimal numbers so that you can get the average, or plot them. Here's how you would use grep to do this:
grep -o ' [0-9]\+\.[0-9]\+' mylogfile.log
The -o option is for just printing the matching text and not the whole line.

Friday, April 5, 2013

Simple HTTP Server in Python

A very easy way to setup a simple HTTP server is by using this built-in Python capability. This will turn any directory into a web server directory. The only thing you have to do is run:
python -m SimpleHTTPServer
on the directory you want to host the files from and that's it. You can drop an index.html file in there, for example, and hit
http://127.0.0.1:8000
in your browser and voila!

Thursday, December 13, 2012

Ogre3D Object Placement Utility


I wrote an open source object placement utility that allows for placing objects (trees) on a terrain using the mouse.


It consists of a terrain and a water surface (pond). The user can select from 3 different models of trees and place them on the terrain. You enter edit mode by pressing space and a toolbar with all available models appears on the left side of the screen. The toolbar can easily be extended with more models.

I hope people will find it useful for object placement in scenes or using it as a base for terrain editors and such.

The build system is currently for Linux only (cmake and make) but it should be easy to compile in Windows or MacOS. The code is not perfect so any comments and suggestions are welcome.


Here is a demo:


Links
Souce code on GitHub
Object Placement Utility at Ogre3D Forums

Thursday, October 11, 2012

Icon Action Sheet for iOS 6

One of the new features of iOS 6 is the replacement of the button based action sheet with the new icon  action sheet. If you tap the options for a library photo for example you get icons for emailing the photo, posting it on Facebook, tweeting it, etc. But how can you integrate this feature on your app?

Github user jgrana recently posted an open source reusable class that does exactly this; it allows you to easily reproduce this control in your app.


Links: IconActionSheet on GitHub

Wednesday, May 16, 2012

OpenCV 2.4 on Ubuntu 12.04

Edit (August 2013): Just used these steps to install OpenCV 2.4.6.1 on Ubuntu 12.10 without problems.

OpenCV 2.4.0 was released on May 2012 providing, a lot of improvements and bug fixes. For a complete change log see here.

This post will hopefully make your life easier to configure, compile, install and test it out.

This time I tried to categorize and explain the dependencies, so that it is easier to configure it for your needs. As always, comments and suggestions are welcome.

Ubuntu 12.04 provides a package of OpenCV 2.3.1 that you can easily install by typing:
sudo apt-get install libopencv-dev
If you do not care about having the latest version you could skip the rest of the post.

Install Dependencies


Essentials
These are libraries and tools required by OpenCV.
sudo apt-get install build-essential checkinstall cmake pkg-config yasm

Image I/O
Libraries for reading and writing various image types. If you do not install then the versions supplied by OpenCV will be used.
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev


Video I/O
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev

Python
Packages needed to build the Python wrappers.
sudo apt-get install python-dev python-numpy

Other third-party libraries
Install Intel TBB to enable parallel code in OpenCV.
sudo apt-get install libtbb-dev

GUI
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section). 
sudo apt-get install libqt4-dev libgtk2.0-dev

Compile and Install

Get a copy of the source code here, extract and create a build directory:
tar -xvf OpenCV-2.4.0.tar.bz2
cd OpenCV-2.4.0/
mkdir build
cd build
Configure using CMake. You have a lot of options in this step. This is what I use:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
Notice, that by adding the -D WITH_QT=ON, the highgui module will use QT instead of GTK. If you want to go with GTK just remove this. For more information on the options, look at the CMakeLists.txt file. When you are happy with the configuration you have, you can start compiling:
make
If compilation finishes without errors, you can install by saying:
sudo make install
Finally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/lib
And then configure dynamic linker run-time bindings:
sudo ldconfig

Testing

An easy way to test that the compilation went well is to use the OpenCV test utilities. For example, to test the core module go to OpenCV-2.4.0/build/bin and run:
 ./opencv_test_core
You should see something like that:


Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.0/samples to OpenCV-2.4.0/build/bin.

For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
make
This should compile and run with a test image, so you should see something like this: