In Ubuntu 16.04, install the dependencies first
sudo apt-get install --assume-yes build-essential cmake git sudo apt-get install --assume-yes pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy sudo apt-get install --assume-yes libopencv-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev sudo apt-get install --assume-yes libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev sudo apt-get install --assume-yes libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev sudo apt-get install --assume-yes libvorbis-dev libxvidcore-dev v4l-utils python-vtk sudo apt-get install --assume-yes liblapacke-dev libopenblas-dev checkinstall sudo apt-get install --assume-yes libgdal-dev
Download opencv 3.3.0 from
http://opencv.org/releases.html
Build opencv using cmake
Unzip opencv-3.3.0 and rename the generated file as opencv
cd ~/opencv mkdir build cd build
Configue
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_IPP=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
Build
make -j7 # runs 7 jobs in parallel
Install
sudo make install
##Note:
If you want to uninstall opencv-3.3.0, you can simply enter ~/opencv/build and run the command below
sudo make uninstall
We can have a try
mkdir ~/cmk_learning gedit main.cpp
Paste the codes below into main.cpp
#include <stdio.h> #include <opencv2/opencv.hpp> #include <unistd.h> using namespace cv; int main(int argc, char** argv ) { if ( argc != 2 ) { printf("usage: DisplayImage.out <Image_Path> "); return -1; } Mat image; image = imread( argv[1], 1 ); if ( !image.data ) { printf("No image data "); return -1; } namedWindow("Display Image", WINDOW_AUTOSIZE ); imshow("Display Image", image); waitKey(0); return 0; }
Create CMakeLists.txt and edit it:
cmake_minimum_required(VERSION 2.8) project( DisplayImage ) find_package( OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) add_executable( DisplayImage main.cpp ) target_link_libraries( DisplayImage ${OpenCV_LIBS} )
Build this project:
cd ~/cmk_learning cmake . make
After running the commands above, we have an executable file DisplayImage in ~/cmk_learning
Result
./DisplayImage emt.jpg