To install OpenCV on your system run the following commands in terminal. You should have Ubuntu/Server 12 or 14 LTS to install it.
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install libtiff5-dev
- sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff5-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-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 default-jdk ant libvtk5-qt4-dev
- cd~
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.11/opencv-2.4.11.zip
unzip opencv-2.4.11.zip
cd opencv-2.4.11 - 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 -D WITH_VTK=ON ..
- make
- sudo make install
- sudo gedit /etc/ld.so.conf.d/opencv.conf
- sudo nano /etc/ld.so.conf.d/opencv.conf
- /usr/local/lib
Run the following command to configure the library
- sudo ldconfig
Now you have to open another file:
- if you are using Ubuntu Desktop then use this command
- sudo gedit /etc/bash.bashrc
- if you are using Ubuntu Server then use this command
- sudo nano /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 terminal and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
To see where opencv installed use following command
- pkg-config --cflags opencv
To see lib files directory use following command
- pkg-config --libs opencv
Let run simple c++ code with opencv code using g++ compiler. Create new file and named it as test.cpp and add following code in it
- #include "stdfix.h"#include <iostream>
#include <opencv/cv.h>#include <opencv/highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image;
image = cv::imread("/home/test.png");
namedWindow("Display window", 1);
imshow("Display window",image);
waitKey(0);
return 0;
}
- g++ `pkg-config --cflags opencv` text.cpp `pkg-config --libs opencv` -o test
- ./test
0 comments:
Post a Comment
Any suggesstion or issue please comment here