Ubuntu16.04 configuration OpenCV3.4.2 and basic use
Author: OpenS_Lee
1 background knowledge
OpenCV is a cross-platform computer vision library released under the BSD license (open source), which can run on Linux, Windows, Android and Mac OS operating systems. It is lightweight and efficient—consisting of a series of C functions and a small number of C++ classes, it also provides interfaces to languages such as Python, Ruby, and MATLAB, and implements many common algorithms in image processing and computer vision.
OpenCV is written in C++, and its main interface is also C++, but it still retains a large number of C language interfaces. The library also has a large number of Python, Java and MATLAB/OCTAVE (version 2.5) interfaces. The API interface functions of these languages can be obtained through online documentation. Now it also provides support for C#, Ch, Ruby, GO.
All new developments and algorithms use C++ interface. A GPU interface using CUDA was also implemented in September 2010
2 Ubuntu16.04 configuration OpenCV3.4.2
· GCC 4.4.x or later
· CMake 2.8.7 or higher
· Git
· GTK+2.x or higher, including headers (libgtk2.0-dev)
· pkg-config
· Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
· ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
· [optional] libtbb2 libtbb-dev
· [optional] libdc1394 2.x
· [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
· [optional] CUDA Toolkit 6.5 or higher
If the download is too slow, you can reply to "OpenCV" on the WeChat official account of "FPGA Open Source Studio" to get the Baidu cloud disk link.
Figure 1 OpenCV3.4.2 Sources
unzip opencv-3.4.2.zip
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install cmake
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
After executing this command, it may be a blank file, don’t worry, just add at the end of the file
/usr/local/lib
sudo ldconfig
sudo gedit /etc/bash.bashrc
Add at the end
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Save, execute the following command to make the configuration effective
source /etc/bash.bashrc
Update
sudo updatedb
OpenCV installation and configuration is complete. Next, we build a small program to test.
1 Create a display.cpp file
vi display.cpp
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
2 Create CMakeLists.txt
Vi CMakeLists.txt
cmake .
make
. /display lena.png
The result shows a lena.png picture.
OpenCV basic configuration is successful.
If you want to learn more about image processing, you can go to opencv official website or OpenCV Chinese website.
Recommended Posts