Installation and operation of opencv under Linux

My first blog post has already mentioned that under Windows, the codeblocks compiler uses the VC of VS2013 and integrates opencv. http://blog.csdn.net/canvachen/article/details/52549283
I also said in the previous article that I have decided to join the Linux army. This article will talk about the construction of the OpenCV development environment under Linux. In fact, it is relatively simple to develop opencv on Linux. The following uses Debian as an example.

1. Go to CodeBlocks official website to download the installation package suitable for your system, mine is codeblocks_16.01_amd64_jessie.tar.xz . After extraction, there are several .deb files in it. Use dpkg -i name.deb to install all these files in the terminal , pay attention to install the dependent files first.
2. Next install opencv. The faster way is to install directly with apt-get install .
If you want to use a newer version, such as 2.4.13 or 3.1.0, you must go to the opencv official website to download the source code for linux, and then compile it with cmake. The process is as follows:
first solve the dependency problem.
sudo apt-get install build-essential

sudo apt-get install cmake libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libjpeg-dev libpng-dev libtiff-dev libjasper-dev

Next, unzip the opencv-2.4.13.zip under the official website and enter the directory, and proceed as follows.
mkdir build
cd build
cmake ..
sudo make
sudo make install
sudo make This sentence will take at least a few hours to compile, so be mentally prepared.

3. Open codeblocks to create a new project and select console application. After the creation is complete, right click on the project, select build option, configure the Compiler and Linker of the Debug Search directories, and the Linker settings. Among them, Compiler adds the header file locations /usr/local/include/opencv and /usr/local/include/opencv2
to be imported ; Linker adds the library location /usr/local/lib ; Linker settings' Link libraries add /usr/local/ Those .so files of opencv under lib .

The sequencing procedure is as follows:

#include <opencv2/opencv.hpp>
 using namespace cv;

int main()
{
    VideoCapture cap(0);
    if (!cap.isOpened())
    {
        return -1;
    }
    Mat frame;
    while (1)
    {
        cap >> frame;
        imshow("当前视频", frame);
        waitKey(10);
    }
    return 0;
}

After talking about compiling and running codeblocks, let's talk about compiling opencv projects with make.
The Makefile is as follows:

SRC=$(shell find . -name "*.cpp")
OBJ=$(SRC:.c=.o)
OUT=test `pkg-config --libs opencv`
CC=g++

$(OUT):$(OBJ)  
    $(CC) $(OBJ) -o $(OUT)
clean:
    rm -rf $(OBJ) $(OUT)

Create a new folder, add main.cpp and Makefile, then run make in this directory , and then a test file will be generated. Then enter ./test on the command line , and the project will run. If you want to use Raspberry Pi to do opencv projects, you can consider using the make method.

Guess you like

Origin blog.csdn.net/CanvaChen/article/details/52564392