[OpenCV getting started tutorial 7] Go to OpenCV source code: Generate OpenCV engineering solution and OpenCV source code compilation

Source: Internet
Author: User
Tags win32 installer windows visual


This series of articles is produced by @ simple ink _ Mao yunxing. Please indicate the source for reprinting.

Article: http://blog.csdn.net/poem_qianmo/article/details/21974023

Author: Mao yunxing (light ink) mailbox: happylifemxy@163.com

The OpenCV version used to write the current blog: 2.4.8


 

 

This article discusses how to select different compiler types through the installed OpenCV to generate a solution project file for highly restored OpenCV development, see more than 0.66 million lines of exquisite source code in the new version of OpenCV. We can re-compile the source code to get the binary file, or modify the original official OpenCV code and compile it for our own use, it has taken a solid step to gain an in-depth understanding of the open source charm of OpenCV.

 

 



1. Download and install cmake




To generate the OpenCV solution on Windows, we need an open-source software named cmake.

Go to the official website of camke: http://www.cmake.org/to download the content, first go to its download page. The Source distributions on the download page can be downloaded to the Source code of the cmake software. If you are interested in this open-Source software, take a look.

 

Binary distributions can be downloaded to the cmake execution file. We only need to download it to the execution file and select Windows (Win32 Installer) for download,Click here to download: Http://www.cmake.org/files/v2.8/cmake-2.8.12.2-win32-x86.exe

 



This step is to download and install cmake, which is provided. you can install cmake. After the installation is complete,

If no desktop shortcut is generated, run the command in the installation path, such as D: \ Program Files (x86) \ CMake 2.8 \ binto cmake-gui.exe.


In addition, a cmake introduction:

CMake is short for "crossplatform make". It is a cross-platform installation (Compilation) tool and can be used to describe the installation (compilation process) of all platforms with simple statements ). 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), which are then used 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.

 


 

 

Ii. Use cmake to generate the OpenCV source code project Solution


This step is the core content of the full text. To make the explanation clear, we will introduce it step by step:
<1> RUN cmake-gui


If no desktop shortcut is generated, run the command in the installation path, such as D: \ Program Files (x86) \ CMake 2.8 \ binto cmake-gui.exe.

The following window is displayed after running:




<2> specify the installation path of OpenCV


For example, click the "Browse Source" button in the red box and specify the path for storing the Source code when OpenCV is installed in the pop-up dialog box.

Take the latest version of OpenCV 2.4.8 installed in D: \ Program Files as an example. Select path: D: \ ProgramFiles \ opencv \ sources


In fact, we can find that there will be a file named cmakelists.txt in this example.

This file is the configuration file left for cmake. cmake can generate different solutions using different compilers based on this configuration file, the Visual Studio compiler generates the Visual Studio sln solution.




<3> specify the storage path of the solution.


For example, click the "Browse Build" button in the red box and specify the path for storing the generated opencv solution in the pop-up dialog box. For example, F:/opencv.

 

 

 

<4> first Configure


Click the Configure button for the first time.



The following dialog box is displayed:


Select "Use default native compilers", and then we can find that the drop-down list provides dozens of compilers for us to choose from, because we have installed Visual Studio, the Visual Studio compiler of the corresponding version is selected by default, for example, Visual Studio 10 (that is, the sln solution corresponding to VS2010 will be generated later)

Click "finish" after confirmation.

Therefore, cmake starts the first source code configuration process:


During cmake processing, such

"Cocould not copy from: D:/Program Files (x86)/CMake 2.8/share/cmake 2.8/Templates/cmakevsm1_s2.vsmacros

To: C:/Users/Light ink/Documents/VisualStudio 2010/Projects/vsm1_s80/CMakeMacros/cmakevsm1_s2.vsmacros"

Because the System user's path name contains the Chinese character "Light Ink", because cmake does not recognize the Chinese path, however, you only need to set no Chinese characters in the generated path in step 3 above. Even if C:/Users/has a Chinese-based error, it will not affect our generation. You don't have to worry about it.

 

PS: it is a blood lesson to learn that the user name of the system is Chinese. When I was playing the Unity3D game engine for a while, I was abused by the system path as Chinese, and an error was reported in the next plug-in of the official unity store. Changing the user name in the control panel is a temporary solution. At last, the System user's Documents directory is located somewhere else. However, this may cause loss or even failure of software data stored in the Documents path ..... Therefore, the lessons of blood .... When you reinstall the system in the future, you will never use a Chinese ID as the user name.

 

At the end of the reading progress bar, the word running ing done appears. The first source code configuration is complete,





<5> second Configure



After the configuration is complete for the first time, we still need to perform the second configuration, so click "Configure" again. This configuration is very fast. In a few seconds, the "processing ing done" text will appear again, and the selected red part is normal:


 



<6> Click Generate.

 


In this way, only one Generate button is left to Generate the final solution:

 


Because there have been two configure processes before, the solution will be generated very quickly:


 

When we see the word Generating done, it means success. We can go to the previously designated F: \ opencv to find the solution we have generated.

 

 

PS: 2.4.8 OpenCV uses cmake to generate only three-point multi-M projects. Compared with OpenCV of 2.4.6, there are three multi-G projects. At the beginning, simple ink thought the generation was wrong, but click the sln project and the source code is still visible. It turns out that the source code of opencv has been directly included in the installation path of opencv since version 2.4.7. The sln project we generated is only connected to the source file under the opencv installation path, the project itself is not big.

 

 

 

3. Compile the OpenCV source code

 


We opened the just-generated "OpenCV. sln" solution with an uneasy mind and saw a huge project coming into view-this is a solution that contains 67 projects:

 

At this time, you can go to the solution Resource Management Interface and enter a project you are interested in, such as the opencv_core project in opencv_core/Src/matrix. cpp: view the source code of a file. The source code of a constructor of the Mat type that everyone is familiar with is shown below:


After a bit of appreciation for the source code, we can press [F5] or use other operations to start debugging.



Compilation process:



Compilation result:



The compilation takes about 5 minutes. The specific time has a large relationship with the machine configuration. Through the simple ink, we can find that 62 projects have been successfully compiled, and 0 has failed. That is, no compilation sub-programs have been generated. : D

In addition, the following warning is displayed after compilation is completed:


Don't be nervous. This is normal. Because the source code project of OpenCV2.4.8 sets "ALL_BUILD" as a startup Item by default, and runs it by default after compilation is successful.


"ALL_BUILD" is a Miscellaneous Item generated by a project. It is not an exe and cannot be run. Therefore, this prompt is displayed.

 

To specify a startup Item, you can click the reverse key of the project to be set as the startup Item in solution resource manager, and click [set as startup item (J) in the pop-up menu item). For example:


In fact, we compile OpenCV to obtain some binary generated files, such as DLL, Lib, and exe.

Because we compile it in debug, the dependent libraries of opencv 2.4.8 will be generated under bin \ debug in the project directory (more than 700 mb, a little large ), it can be used for future calls of opencv.



 



Iv. OpenCV code line count



In the 2.4 era of OpenCV, the src part of the source code already has more than 170 MB, and the number of lines of the source code, through the statistics of Shimo, is more than 0.68 million lines. (Here, I can't help but feel a little touched. The source code of Unreal Engine 4, which was just in the previous two days, is more than 1.44 million lines, more than twice that of OpenCV ....)

 

We can see that the accurate source code of OpenCV 2.4.8 contains 687,870 lines.

OK, the feast begins. The source code of OpenCV, a big treasure house in the computer vision field, is coming soon.

 


Well, the content in this section is probably like this. For more information, see :)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.