Ubuntu16.04 configuration OpenCV3.4.2 and basic use

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

**OpenCV requirements package: **

· 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

  1. Download OpenCV3.4.2 Sources on the Opencv official website URL link: https://opencv.org/releases.html

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

  1. Copy the downloaded compressed package to the Ubuntu system and unzip it.

unzip opencv-3.4.2.zip

  1. Enter the decompressed file package and install the dependent library.

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

  1. Install cmake

sudo apt-get install cmake

  1. After installing cmake, create a compilation folder build

mkdir build

cd build

  1. Execute cmake

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

  1. Wait for the cmake command to complete and then execute make

sudo make

sudo make install

  1. After sudo make install is executed, the OpenCV compilation process is over. Next, you need to configure some OpenCV compilation environment. First add the OpenCV library to the path, so that the system can find

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

  1. Execute the following command to make the configuration path just now effective

sudo ldconfig

  1. Configure bash

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

include <stdio.h>

include <opencv2/opencv.hpp>

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

  1. Run cmake.

cmake .

  1. Run make

make

  1. Run./display lena.png

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

Ubuntu16.04 configuration OpenCV3.4.2 and basic use
The basic configuration and interface beautification of Ubuntu
Basic configuration and common software installation after ubuntu 18.04 installation
Ubuntu16.04 installation and simple configuration
GitLab installation and basic use
Ubuntu16.04 install SVN and configuration
Ubuntu PostgreSQL installation and configuration
CentOS 8 install Git and basic configuration
Ubuntu environment variables and ADB configuration
Enterprise self-built GitLab code warehouse installation and basic configuration use
Ubuntu 19.1 installation and configuration Chinese environment
Configuration and beautification after Ubuntu installation (1)
Nginx installation and configuration load (ubuntu12.04)
Ubuntu configuration source and installation software
Ubuntu basic settings: introduction to the installation and use of openssh-server
Install docker on ubuntu and basic usage
Ubuntu18.04 Server version installation and use (graphic)
Installation and use of Win10 subsystem Ubuntu
Ubuntu install PHP and PHP Nginx configuration method
DLNA/UPnP Server installation and configuration under Ubuntu 12.04
ubuntu 18.04 early configuration
Ubuntu use notes
CentOS7 basic configuration
Ubuntu nfs configuration
Ubuntu20.04 configuration notes
Ubuntu 14.04 configuration record
ubuntu zip/unzip use
Debian and Ubuntu installation source configuration file description
Install and use Git and GitHub on Ubuntu Linux
How to install and use Docker on Ubuntu 20.04
Virtual machine installation and configuration ubuntu shared folder_
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
Use Ubuntu and windows system in virtual machine
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
Kaldi installation and configuration graphic tutorials under Ubuntu
Installation, configuration and uninstallation of GitLab in Ubuntu19.1
Installation and use of SSH in Ubuntu environment
How to install and use Docker on Ubuntu 16.04
Ubuntu16.04 mirror complete installation and configuration tutorial under VMware
[Linux] ubuntu install configuration vsftpd and lock the directory
Summary: Ubuntu Python2.x and
ubuntu configuration python, Red
How to create and use MongoDB backups on Ubuntu 14.04
Ubuntu Opencv image smoothing
Ubuntu18.04 install opencv 3.2.0 solution
OpenMPI-Ubuntu installation and configuration
Ubuntu configuration development environment
Installation and use of GDAL in Python under Ubuntu
Use supervisor in ubuntu
Ubuntu introduction and installation
[python] python2 and python3 under ubuntu
Ubuntu development environment configuration
Network configuration under Ubuntu
023. Ubuntu common personalized configuration
Ubuntu12 step-by-step installation and configuration (system, FTP, TELNET.. settings)
Cpp web (1) Install and use Crow service under Ubuntu
ubuntu 14.04 16.04 18.04 use Alibaba source