Install OpenCV on Centos
To get familiar with C ++ in linux, we are going to first configure the environment by porting the previously written project from windows to linux. This is tedious and has many errors. Record it now.
System: Centos 6.5
Last Version: OpenCV 2.4.3
1. Install the dependency package (important)
Yum install cmake gcc-c ++ gtk +-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel gstreamer- devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm
If the preceding dependency package is not installed, an error occurs when opencv is called at the end, as shown below:
OpenCV Error: Unspecified error (The function is not implemented. rebuild the library with Windows, GTK + 2.x or Carbon support. if you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow ,...................
In this case, only the compiled opencv files can be deleted and then re-compiled to delete/usr/local/lib and/usr/local/include /.
Mv/usr/local/lib/libopencv *
Mv-fr/usr/local/include/opencv
Mv-fr/usr/local/include/opencv2
Then re-compile opencv.
2. Install/update CMake
Why do you want to install or update cmake? The following describes the ch-producer problem:
(1) download
Download the required version at http://sourceforge.net/projects/opencvlibrary/files /.
Copy to/usr/local/path
(2)tar-xvfOpenCV-2.4.8.tar.bz2 unzip
(3) cdOpenCV-2.4.8 into the Directory
(4) yuminstallcmake directly installs cmake from the Internet
(5)cmakeCMakeLists.txt
If there is no error in this step, opencv has been installed;
This step has an error
You need to install the new cmake version.
Download the latest cmake file for compilation
Http://www.cmake.org/cmake/resources/software.html
Copy it to/usr/local/path
Decompress:
R-zxv-f cmake-2.8.10.2.tar.gz // decompress the package
Rm-rf cmake-2.8.10.2.tar.gz // Delete package
Cd cmake-2.8.10.2
./Configure
Make
Make install
// Modify the folder name
Music cmake-2.8.10.2 cmake
Modify environment variables:
Vim/etc/profile
Add at the end:
[Html] view plaincopy
- PATH =/usr/local/cmake/bin: $ PATH
- ExportPATH
Note: Do not write the colon as a semicolon. Otherwise, all command lines cannot be used and the system cannot be started after restart.
// Make the modification take effect
Source/etc/profile
// Check whether the PATH has been added.
Echo $ PATH
// Verify the version
Cmake -- version
After cmake is installed successfully, continue to install opencv.
3. Install Opencv
Continued cmakecmakelists.txt
Error:
System is unknown to cmake, create:
Incorrect opencv version
Download Opencv again, this time Select Download opencv-2.4.3, put in the/usr/local/directory
Repeat the steps for installing opencv in the previous step.
Tar-xvf OpenCV-2.4.3.tar.bz2 Decompression
CdOpenCV-2.4.3. Go to the directory
Yuminstallcmake directly installs cmake from the Internet
CmakeCMakeLists.txt
Make
Make install
Successful
4. Add a path
If you do not add a path to the environment variable, the following error occurs when you run the test program:
./Drawing: error while loading shared libraries: libopencv_calib3d.so.2.4: cannot open shared object file: No such file or directory
Solution:
(1) Use ln to link the required so file to the/usr/lib or/lib default directories.
Ln-s/where/you/install/lib/*. so/usr/lib
Sudoldconfig
(2) Modify LD_LIBRARY_PATH
ExportLD_LIBRARY_PATH =/where/you/install/lib: $ LD_LIBRARY_PATH
Sudoldconfig
(3) Modify/etc/ld. so. conf (I used this method)
Vim/etc/ld. so. conf
Add/where/you/install/lib
Sudoldconfig
An error occurred when entering ldconfig: libstdc ++. so.6.0.18-gdb. py is not an ELF file-the initial magic number is incorrect.
Solution: rm libstdc ++. so.6.0.18-gdb. py is deleted.
Ldconfig again, no error
5. test:
The test code displays an image:
[Cpp] view plaincopy
- 1 # include "cv. h"
- 2 # include "highgui. h"
- 3
- 4 intmain ()
- 5 {
- 6IplImage * pImg = NULL;
- 7
- 8if (pImg = cvLoadImage ("1.jpg", 1 )))
- 9 {
- 10 cvNamedWindow ("Image", 1); // create a window
- 11 cvShowImage ("Image", pImg); // display the Image
- 12 cvWaitKey (0); // wait for the key
- 13 cvDestroyWindow ("Image"); // destroy the window
- 14 cvReleaseImage (& pImg); // release the image
- 15return0;
- 16}
- 17return-1;
- 18}
You can use the following command to compile
G ++ 'pkg-config -- cflags -- libsopencv 'code. cpp-odrawing
Note that the above is ~ The key symbol, instead of the quotation marks, will lead to an error: -- libs opencv: No file or directory fatal error: cv. h: No file or directory
I use makefile to write this ch example:
Write makefile as follows:
Make
./Drawing
Displayed successfully
If the errors mentioned in step 1 occur, install the dependent library and compile opencv again.