Learning the learning notes series of OpenCV (2) source code compilation and sample projects, opencv learning notes
Download and install CMake3.0.1
To compile the source code of OpenCV2.4.9 by yourself, you must first download the compilation tool. CMake is the most widely used compilation tool.
The following is an introduction to CMake:
CMake is a cross-platform installation (Compilation) tool. You can use simple statements to describe the installation (compilation process) of all platforms ). He can output a variety of makefiles or project files and test the C features supported by the compiler, similar to automake in UNIX. Only the CMake configuration file is named CmakeLists.txt. Cmake does not directly construct the final software, but generates standard construction files (such as Unix Makefile or Windows Visual C projects/workspaces), and then uses them in a general construction mode. This allows developers familiar with an integrated development environment (IDE) to construct their software in a standard way, this native system construction capability of various platforms is different from other similar systems such as CMake and SCons.
CMake can compile source code, create a program library, generate an adapter (wrapper), and construct an execution file in any order. CMake supports in-place Construction (the binary file and the source code are in the same directory tree) and out-of-place Construction (the binary file is in another directory ), therefore, it is easy to construct multiple binary files from the same source code directory tree. CMake also supports static and dynamic library construction.
"CMake" is short for "Cross Platform Make. Although the name contains "make", the common "make" systems on CMake and Unix are separated and higher.
Through the above introduction, we know that we can use the CMake tool to compile the source code into the VS2010 project file, this allows us to build multiple examples or tutorial projects in different project teams under.
We can find the latest CMake installation file on the official website of CMake: http://www.cmake.org/cmake/resources/software.html.
Select the file"CMake-3.0.1-win32-x86.exe"Download, a total of 10.78 MB, and can be completed soon.
After the download is complete, double-click the installation program to start CMake installation.
The installation is simple, basically"Next step"Until the last step"Complete".
After the installation is complete, you canStart"Find the installed CMake3.0.1 program shortcut"CMake (cmake-gui)"
After the installation, compile the OpenCV source code.
OpenCV2.4.9 source code compilation
Assume that the source code of OpenCV2.4.9 has been downloaded and installed. (If you do not know how to do this step, please refer to another tutorial "Learning OpenCV Study Notes series (1) Environment configuration".)
In the Start Menu, clickCMake (cmake-gui )",Open the CMake program. The compilation setting page is displayed. As shown in
In"Where is the source code"In the option text box, enter the directory path of the OpenCV source code. You can click"Browse Source..."Select a folder. Select a path based on the actual location of the source code installation. Here, select"H:/opencv/sources".
In"Where to build the binaries"In the option text box, enter the file directory path for the sample project and source code to be built. Here, select" H:/OpenCV/Solution "in the same folder as the source code ".
After entering the source code path and the generated path, click"Configure"Button
If this is the first configuration, a page will pop up to generate the project target environment.Visual Studio 10 2010"Option, select"Use default native compilers", And then click"Finish"Button.
If the directory to be generated does not exist, a dialog box is displayed, as shown in. Click "Yes.
Many Red options will appear in the first configuration. Leave it alone and click"Configure"Button.
This time, the red option is missing, indicating that there is no problem and the configuration is complete.
Click"Generate"Button
At the bottom of the page"Generating done", Indicating that the source code project has been compiled.
OpenCV2.4.9 source code Engineering Test
Open the folder under the generated directory path set in the previous step. You can see that there is"Solution"Folder, which is automatically generated in the previous step. Double-click the folder.
In"H:/opencv/Solution"Path, we can see that there is a compiled VS2010 project file"OpenCV. sln", Double-click the file to open the project file in VS2010.
In the open "OpenCV" project, we can see 68 projects.
Right-click the OpenCV solution and choose generate solution.
Compilation takes a long time. My PC configuration is relatively good, but it takes about 2 minutes to compile. 62 projects are generated, and 0 projects fail. All projects are compiled successfully. Congratulations!
Next, you can view and compile projects one by one. The explanations of these sample projects and source code will be added later...
OpenCV2.4.9 built-in sample source code compilation and Testing
The above section describes the source code compilation and engineering of OpenCV. The following describes how to compile the sample source code and engineering of OpenCV.
Open CMake3.0.1 and change the source code path :"H:/opencv/sources/samples"(The specific path varies with the installation location. You can find"SampleFolder ).
In one-pass configuration (Configure) And generate (Generate!), In the target directory, you can find the generated OpenCV sample project file:"Samples. sln"
Click to open"Samples. sln", The solution resource manager shows a total of 172 projects (there are many examples, so nice looking !)
Right-click solution and select"Generate a solution"
About one minute or so (different machine configurations and different compilation times). After compilation is completed, the project generates 171 projects, with 0 failures. The project passes one compilation. Click here!
After the overall compilation is correct, open a sample project. In this article, select"(EXAMPLE) lkdemo"Project. The source code of this project uses the improved Lucas-Kanade optical flow algorithm to detect video motion targets. Click the target point to track the video.
Click "run" to find a command line interface that flashed through and then exited. Why?
After one-step debugging, you can find thatLkdemo. cpp"56 rows of Files"If (! Cap. isOpened ());"In the judgment statement, the player is not enabled, and a line is displayed directly on the console."Cocould not initialize capturing.... The reason is that"Cap. open ("Megamind. avi ");"The video file in this statement"Megamind. avi"Not in the program directory. If you know the reason, you can solve it!
In theH: \ opencv \ sources \ samples \ cpp"Directory (source code file directory) Copy"Megamind. avi"File to"H: \ opencv \ sampleSolution \ cpp \ Debug"Directory (this is the program"Cpp-example-lkdemo.exeDirectory ). In other words, make sure that the"Megamind. avi"File.
After finishing the above work, click "run" again to run the program successfully. An animated video is played. After clicking the left button on the screen, there will be a green mark point, the position of the marked point changes with the movement of the surrounding object. This is the so-called video tracking. As follows:
OK. I will not introduce the principle and workflow here. I will view the source code myself. The source code of other sample projects can be viewed one by one, and then compiled and run, I believe that after understanding these examples, OpenCV will be no longer unfamiliar to you. Welcome to the OpenCV Hall and start your learning stage!
I am helpful in learning opencv. It is a routine in the OPENCV tutorial (basic): Examples 3-4 and Examples 3-5 are compiled and run correctly?
Do you mean that the two routines need to pass in the parameters of the main function to process data?
Well, you can generate an exe file, and then directly remove the image and video you want to process to the exe file.
Or use the command line,
First, use cd to locate the root directory of the exe file, and then use *. exe *. jpg
OK. *. Exe is your executable file, *. jpg is the data, images, and videos you want to input. Note that there are spaces in the middle
Primary school problems-use idioms of Three Kingdoms
In my opinion, this idiom is:
1. Take a look!
2. 7-step poetry!
Are you satisfied?
(The first idiom is from: The story of Lu Meng in the Three Kingdoms. The second idiom is from: The story of Cao Zhi being forced by Cao Yu to write poems in the Three Kingdoms era .)