Opencv is an open-source computer vision Library Supported by Intel. It consists of a series of C functions and a small number of C ++ classes, implementing many common algorithms for image processing and computer vision. It does not rely on other external libraries-although some external libraries can also be used.
Opencv uses BSD license, which is free for non-commercial and commercial applications.
The main application environments of opencv are Windows and Linux. For embedded systems such as arm-Linux, there is little information to mention. Therefore, I will record the compilation process in arm-Linux and share it with you.
Preparations:
A. Install the cross-compilation chain
I am using ARM-Linux-GCC 4.3.2, decompress it to the/usr/local/ARM/4.3.2 directory, and add/usr/local/ARM/4.3.2/bin to the environment variable path.
B. Install cmake
For Versions later than opencv 2.0, you must use cmake to create makefile. The cmake version I'm using is 2.8.2, decompress it to the directory/usr/local/cmake-2.8.2-Linux-i386, then add/usr/local/cmake-2.8.2-Linux-i386/bin in the environment variable path
Compile opencv:
1. Extract opencv 2.1 to/usr/local/OpenCV-2.1.0 directory
2. Create the/usr/local/opencv-arm/directory as the working directory for cmake to compile the arm version.
3. Run cmake-Gui in the X Environment
Select the source code Directory:/usr/local/OpenCV-2.1.0
Select the build Directory:/usr/local/opencv-arm/
Click Configure, keep generator as UNIX makefiles, select specify options for cross-compiling, and click Next
Set Operating System to arm-inux.
C compilers fill in/usr/local/ARM/4.3.2/bin/ARM-Linux-gcc
C ++ compilers fill in/usr/local/ARM/4.3.2/bin/ARM-Linux-G ++
Enter/usr/local/ARM/4.3.2/as the target root of the library, and click Finish.
Modify the default configuration. The default installation directory is/usr/local, which is not suitable for cross-compiled libraries. Therefore, I changed the cmake_install_prefix variable to/usr/local/ARM/lib/opencv/
In addition, I have not installed support for Tiff images, so remove with_tiff.
Click Generate to generate makefile
4. On the terminal interface, enter the directory/usr/local/opencv-arm and run make to compile opencv.
The following errors are found during compilation:
Linking cxx executable.../../bin/opencv_createsamples
.../../Lib/libcxcore. So: Undefined reference to 'clock _ gettime'
.../../Lib/libcxcore. So: Undefined reference to 'pthread _ key_create'
.../../Lib/libcxcore. So: Undefined reference to 'pthread _ getspecific'
.../../Lib/libcxcore. So: Undefined reference to 'pthread _ setspecpacific'
The reason is that cmake does not recognize the arm-Linux system Tag I have defined, and does not include the link options for library pthread and RT.
5、modify cmakecache.txt, cmake_exe_linker_flags is empty, add-lpthread-LRT, re-compile, error elimination
6. Run make install to install the library and header file generated by opencv to the directory/usr/local/ARM/lib/opencv/
Test the opencv Library
1. First, check whether the library has been compiled correctly and its installation location.
View the header file:
[Root @ localhost opencv-arm] # ls/usr/local/ARM/lib/opencv/include/opencv/<br/> cvaux. h cvcompat. h cv. HPP cvtypes. h cvvidsurv. HPP cxcore. h cxerror. h cxmat. HPP cxoperations. HPP highgui. h ml. h <br/> cvaux. HPP cv. h cvinternal. h cvver. h cvwimage. h cxcore. HPP cxflann. h cxmisc. h cxtypes. h highgui. HPP
View library files:
[Root @ localhost opencv-arm] # ls/usr/local/ARM/lib/opencv/lib <br/> libcv. A libcvaux. A libcvaux. so libcv. so libcxcore. A libcxcore. so libhighgui. A libhighgui. so libml. A libml. so
2. Write a simple test program, open the camera, and create a window for display.
// Test. CPP </P> <p> # include <cv. h> <br/> # include <cxcore. h> <br/> # include <pighgui. h> </P> <p> int main () <br/> {<br/> cvcapture * capture = NULL; <br/> iplimage * frame = NULL; </P> <p> If (! (Capture = cvcapturefromcam (-1) <br/>{< br/> fprintf (stderr, "can not open camera. /n "); <br/> return-1; <br/>}</P> <p> cvnamedwindow (" video ", 1 ); </P> <p> while (frame = cvqueryframe (capture) <br/>{< br/> cvshowimage ("video", frame ); <br/>}</P> <p> cvdestroywindow ("video"); <br/> cvreleasecapture (& capture); <br/> return 0; <br/>}
3. Compile the link test program
Arm-Linux-G ++-I/usr/local/ARM/lib/opencv/include/opencv/-L/usr/local/ARM/lib/opencv/lib /- LCV-lcxcore-lhighgui-lpthread-LRT-O test. CPP
4. Copy the program to the embedded system and run it.
First copy the host/usr/local/ARM/lib/opencv/lib. so file to the/lib/directory of the embedded Linux system, and then copy the compiled test file to the/opt/myworks/directory of the embedded system (and ensure that the file test attribute is executable ), if test runs properly and no library file is reported to be missing, the compiled arm-Linux opencv library can be used normally.