Because of project requirements, we need to port the previous work to CentOS. Since I have never really started to use Linux, this is a good practice.
1. Environment deployment
1.1 install VMWare9
1.2 create a VM and install CentOS6.4-x86_64
The virtual machine configuration is configured according to the computer hardware and requirements, and the network is set to bridge. If a VT-x error occurs during installation, you must enable VT-x in the BIOS. The AMD platform is not tested.
1.3 install OpenCV2.3.1
Reference
Blog.csdn.net/xiaohouzuoxin/article/details/9831263
The files to be downloaded separately are stored in/home/xx/Downloads by default.
1.3.1 deploy yum Source
Obtain the CentOS repo file in pai.163.com to overwrite the local file.
/Etc/yum. repo. d/CentOS-Base.repo
1.3.2 prepare the environment
Su
Yum install gcc-c ++
Yum install gtk +-devel. i686
Yum install gimp-devel.i686
Yum install gimp-devel-tools.i686
Yum install gimp-help-browser.i686
Yum install zlib-devel.i686
Yum install libtiff-devel.i686
Yum install libjpeg-devel.i686
Yum install libpng-devel.i686
Yum install gstreamer-devel.i686
Yum install libavc1394-devel.i686
Yum install libraw1394-devel.i686
Yum install libdc1394-devel.i686
Yum install jasper-devel.i686
Yum install jasper-utils.i686
Yum install cmake
Yum install swig
Yum install python
Yum-y install libtool
Yum install nasm. i686
Replace *. i686 with *. x86_64. If the yum software package does not exist, use the yum search software package name to search for the software package name found in yum install.
1.3.3ffmpeg
Reference
Blog.csdn.net/xygl2009/article/details/12998497
Find ffmpeg-0.8 stable version on the official website, download unzip, Open in Terminal
./Configure-enable-shared-enable-gpl-enable-swscale-disable-yasm
Make
Make install
All libraries are installed under/usr/local/lib, and all header files are installed under/usr/local/include.
Test ffplay, but an error is reported. Find the config. mak file and open it. Find CONFIG_FFPLAY = yes and remove the previous one !, Make again. The error message "SDL" is missing. Install SDL
Yum install SDL
Install several missing library SDL_mixer-2.0.0, SDL_image-2.0.0 and SDL_rtf-0.1.0. But make errors occur, the error is that the SDL version is too old, download the latest SDL2-2.0.3 and install, the problem solved.
Make
Make install
1.3.4pkg-config
See blog.csdn.net/firefoxbug/article/details/7554409
Pkg-config identifies information of installed library files through the. pc files in each library file. These. pc files are generated by the installation programs of each database. Use PKG_CONFIG_PATH to set pkg-config for update.
1.3.5cmake
Yum install cmake
1.3.6OpenCV2.3.1
After decompression, Open in Terminal,
Mkdir release
Cd release
Cmake ../
Locate row 44th in cmakelists.txt. Simply comment out this line. Again
Cmake ../
In the generated list, ffmpeg is related to no. Run
Export PKG_CONFIG_PATH = $ PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
Execute again
Cmake ../
All ffmpeg related items in the generated list are yes.
Make
Make install
All libraries are installed in/usr/local/lib, and all header files are installed in/usr/local/include. Update the path before testing OpenCV and ffmpeg.
Vi/etc/ld. so. conf
Add/usr/local/lib
Ldconfig
1.4CodeBlocks-12.11
Reference
Www.ienter.org/html/2013/07/117.html
Download the codeblocks-12.11 and install it. You also need to install wxGTK and xterm
2. Routine debugging
Reference
Http://www.07net01.com/program/123599.html
Http://digitus.itk.ppke.hu /~ Losda/anyagok/OpenCV/CodeBlocks_OpenCV.pdf
Default path:/home/xx/Codes/test/test_opencv
Open Code: blocks
Create a new project. The type is Console application. Use the Language C ++ and the project name test_opencv. Just click next.
Double-click main. cpp in sources
Enter code
# Include <stdio. h> # include <opencv2/imgproc. hpp> # include <opencv2/highgui. hpp> # include <opencv2/core. hpp> using namespace cv; using namespace std; int main (int argc, char ** argv) {if (argc = 2) {Mat img; img = imread (argv [1]); imshow ("test", img); waitKey (0); return 0;} return-1 ;}
Configure Project Environment Variables
Right-click test_opencv on the left-hand side, select Build options, select test_opencv on the left-hand side of the dialog box, select Linker settings, and add the used lib to Linklibraries.
/Usr/local/lib/libopencv_highgui.so.2.3.1
/Usr/local/lib/libopencv_imgproc.so.2.3.1
/Usr/local/lib/libopencv_core.so.2.3.1
Select Search directories and add the include location to Compiler.
/Usr/local/include/opencv2
/Usr/local/include
Location for adding lib to Linker
/Usr/local/lib
Click OK to compile the file. The generated file is in ../bin/Release.
Enter this path in Terminal and run
./Test_opencv xx. xx
The image display shows that OpenCV can be used normally. The following is a test of the video playback function.
# Include <stdio. h> # include <opencv2/imgproc. hpp> # include <opencv2/highgui. hpp> # include <opencv2/core. hpp> # include <opencv2/video. hpp> using namespace cv; using namespace std; int main (int argc, char ** argv) {Matimg; VideoCapturepCap; if (! PCap. isOpened () return-1; while (1) {pCap> img; imshow ("test", img); if (waitKey (10) = 27) break ;} return-1 ;}
Add Linker settings and Link libraries
/Usr/local/lib/libopencv_video.so.2.3.1
Compile
Enter this path in Terminal and run
./Test_opencv xx. xx
Play the video and Press ESC to exit.