It is better to compile OpenCV from scratch than to use the precompiled versions in Ubuntu as most of them are not optimized.
Make sure to have these packages installed:
sudo apt-get install pkg-config ant libeigen3-dev sphinx-common libopenexr-dev libtbb-dev python-numpy
Get the OpenCV sources from here: OpenCV
Extract the archive and prepare for compilation:
tar -C ~/local/src/ -xf ~/Downloads/OpenCV-2.4.3.tar.bz2 cd ~/local/src/OpenCV-2.4.3/ mkdir build && cd build
Configure with following options:
ccmake -DCMAKE_BUILD_TYPE=Release -DWITH_GIGEAPI=OFF -DWITH_CUDA=OFF -DWITH_PVAPI=OFF -DWITH_TBB=ON ..
Hit 'c' to configure and check that there are no dependency problems. Hit 'c' again and then 'g' to generate. Now we can compile and install with:
make sudo make install
Add the pkg-config path to the end of your bashrc so that the OpenCV libraries can be found later by other programs:
gedit ~/.bashrc export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig