Reproduced, please specify the source: Http://blog.csdn.net/tina_ttl
Directory (?) [+]
tags (space delimited): Linux learning OpenCV
- Install OpenCV under Ubuntu 1404 using the Apt-get method
- Objective
- Installation method
- Where is the OPENCV installed?
- 1 OpenCV of installation source files
- 2 OpenCV The installation location of the associated header file
- 3 Installation location of related dynamic link libraries for OPENCV
- 4 Linux under OpenCV and Windows OpenCV files
- Test code
- 2 Make
- 3 Test procedure
1. Preface
Compared to the source code mode installation OPENCV, the installation process via apt is simpler and consumes less time. Installation via apt does not automatically generate OPENCV.PC files, so you cannot use the Pkg-config tool directly when writing makefile files, but you need to specify Opencv_core, Opencv_imgproc and other dynamic link libraries individually!
2. Installation method
- Update Ubtuntu system software source
sudo apt-get update
sudo apt-get install libcv-dev
-
- The installation process takes a few minutes and the installation is completed with the following results
3. Where is the OPENCV installed? 3.1 OpenCV installation source files
apt-get install **
This command will download the files in the/var/cache/apt/archives directory and install them. As you can see, OpenCV related. Deb files are in this directory, as shown in the original/var/cache/apt/archives directory only folder partial and file lock, but because at this time download the OPENCV related installation files, Discover a number of multiple Deb installation files under this folder!
In fact, after performing the above installation process, the files under these archives paths can be deleted directly! installation files are no longer required because the associated installation has ended
- Installing this apt-get install will make the
/var/cache/apt/archives
directory occupy more space.
- Fortunately, APT provides the appropriate management tools
apt-get clean
to remove /var/cache/apt/archives/
/var/cache/apt/archives/partial/
all packages (except those that are locked) in the file directory and file directory.
- Examples of implementation:
Execute the following command
It can be found that all the files about OpenCV that have just been downloaded have been deleted.
3.2 OpenCV The installation location of the associated header file
OpenCV related header files are installed in the/usr/lib directory, which is the Linux default header file lookup path.
Installation location of related dynamic link libraries for 3.3 OpenCV
The dynamic link library file under Linux is the. so file
OPENCV related dynamic Link libraries are installed in the /usr/lib
directory. These dynamic link libraries include:
"Opencv_calib3d"--camera calibration and three-dimensional reconstruction
"Opencv_core"--core modules, drawings and other accessibility functions
"Opencv_features2d"--two-dimensional feature detection
"Opencv_flann"--quick Nearest nearest search
"Opencv_highgui"--gui user interface
"Opencv_imgproc"--image processing
"Opencv_legacy"--Discarded parts
"OPENCV_ML"--Machine learning module
"Opencv_objdetect"--target detection module
"Opencv_ocl"--a computer Vision component module using OPENCL acceleration
"Opencv_video"--Video analysis component
is a /usr/lib
file in the folder related to OpenCV, for example, the first and second files are the static state link library file (LIBOPENCV_ML.A) and the dynamic link library file (libopencv_ml.so) corresponding to the machine learning module respectively.
3.4 Linux under OpenCV and Windows OpenCV files
In fact, whenever we need to use OPENCV's related libraries under any operating system, we use only its dynamic-link libraries and static-link libraries.
4. Test Code 4.1 Source
- Create a C + + file called Test.cpp, which reads as follows
#include <opencv2/core/core.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/highgui/highgui.hpp>#include <iostream>Usingnamespace CV;UsingNamespaceStdint main (int argc, char **argv) {Mat image, Image_gray; image = Imread (argv[1], cv_load_image_color);
if (argc! =
2 | |!image.data) { cout << "No image data\n"; return-1;} cvtcolor (Image, Image_gray, Cv_rgb2gray); Namedwindow ("image", cv_window_autosize); Namedwindow ("image Gray", cv_window_autosize); Imshow ("image", image); Imshow ("Image Gray", Image_gray ); Waitkey (0); return 0;}
- Create a file called Makefile, and enter the following:
CC = g++# executable FileTARGET = Test# c FileSRCs = Test.cpp# destination FileOBJS =$(SRCs:. CPP=.O)# library fileDlibs =-lopencv_core-lopencv_imgproc-lopencv_highgui# Link to executable file$ (TARGET): $(objs) $ (CC) -o [email protected] $^ $ (dlibs) clean:rm- RF $ (target) $ (objs)# compilation rule [email protected] represents the first dependent file% on behalf of the target file $<. O:%.cpp $ (CC)-o [email protected]-C $<
1
xxxxxx
Note 1:
12 rows, 14 rows, and 17 lines preceded by tab, not a space, “makefile:12: *** 遗漏分隔符 。 停止。”
this error will occur
NOTE 2:
Because the core part of OpenCV (Opencv_core), the Image Processing Section (OPENCV_IMGPROC), and the GUI part (Opencv_highgui) are used in the example, add Opencv_core, opencv_ Imgproc, Opencv_highgui dynamic link library.
Which is DLIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui
implemented by the statement
4.2 Make
cd 文档 # 进入程序所在目录make
Generated two files: Test file and TEST.O file
4.3 Test procedure
./test lena.bmp
Run results
The function of the above program test is to convert the input image into a grayscale image, you can see that the program implemented the function, it proves that the OPENCV installation is successful
Of course, the makefile file here is very important, the specific use of the method has not been understood, to learn
In addition, what is the difference between cmake and make? Found most of the use of cmake tools, need to write CMakeLists.txt files, specifically to learn
Reference documents
[1] Raspberry Pi Learning note--apt Way installation OpenCV
[2] apt-get downloaded files in which directory
Install OpenCV under Ubuntu 14.04 using the Apt-get method