Thursday, December 13, 2012

Install Opencv 2.4.3 in Ubantu 10.10 or higher [10 steps]


1. Down Netbeans 6.9 using Ubuntu software center.
2. install netbeans-7.2.1-ml-cpp-linux.sh


3.//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:
3.1 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:

3.2 sudo apt-get install build-essential libgtk2.0-dev libjpeg62-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 texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install sphinx-common


//Time to get the OpenCV 2.4.3 source code:
3.3 cd ~
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.3/OpenCV-2.4.3.tar.bz2
tar -xvf OpenCV-2.4.3.tar.bz2
cd OpenCV-2.4.3



//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).

3.4 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.

//Now, you are ready to compile and install OpenCV 2.x.x:
3.4 make
sudo make install

//Now you have to configure OpenCV. First, open the opencv.conf file with the following code:
3.5 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:
3.6 /usr/local/lib

//Run the following code to configure the library:
3.7 sudo ldconfig

//Now you have to open another file:
3.8 sudo gedit /etc/bash.bashrc

//Add these two lines at the end of the file and save it:
3.9 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.3 installed in your computer with Python, TBB, OpenGL, video, and Qt support.

******************************************************************************************************************************************

Test....................................................

Now let’s build some samples included in OpenCV:
1 cd ~/OpenCV-2.4.3/samples/c
2 chmod +x build_all.sh
3 ./build_all.sh

Now we are ready to run the examples:
1 ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

detect face
2     ./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



set background black
3. ~/OpenCV-2.4.3/build/bin/grabcut ~/OpenCV-2.4.3/samples/cpp/lena.jpg


********************************************************************************************************************************************





No comments:

Post a Comment