About slam-General diagram optimization (G2O) environment collocation (windows8.1 vs2013)

Source: Internet
Author: User

long time no see, all of you pro, recently in the middle of the last reply, to have a good update of the blog. Since the last Monocular AR system has been done, I've been thinking about what I'm doing and what I'm going to do next. Before the blog is written on the 3d reconstruction, later on the field of vision after the discovery no matter I do 3d reconstruction, Slam,ar, the important is the posture update. A precise and stable posture update determines the quality of the system. Bayesian Filters (EKF extended Kalman filter, pf particle filtering) and general-purpose graph Optimization (G2O) are two methods to make the attitude more accurate and stable. In recent years, G2O has gradually become the mainstream back-end optimization method in the field of visual slam. Specific visual slam processes and G2O knowledge, I will be in the module "about Slam" in the next two articles (including some of their own optimization of the code). This blog mainly talk about G2O in the Windows environment collocation. Why choose Windows, because these years have been using the VS editor (vc++6.0,vs2012,vs2013), for this familiar area of the sudden change to Ubuntu under the use of CMake is still a bit uncomfortable (though that said, I still recommend to do academic children's shoes multi-use Linux systems such as Ubuntu, the various libraries are really convenient and can learn a lot of things. Next, let's talk about the g2o of developing Win32 programs and x64 programs.

Let's start with a G2O official github steps diagram for Windows compilation and the download link to the G2O source :




Altogether 6 steps: compile Eigen, install QT, compile Libqgvliewer,cmake compile g2o,VS2013 generate G2o, Add an environment variable and start using it . No need for G2o_viewer.exe to view optimization results without QT and libqgliewer (I think most people need it). In Ubuntu you also need suitesparse but Windows does not (in fact, there are csparse in external).

1. Compiling Eigen3.2.7

This step is explained in detail in my PCL compilation .

2. Installing Qt5.5.1

Here we install the 32-bit and 64-bit versions of the 5.5.1. You can also download Qt4 and other versions of QT5, all of which are possible. Note When downloading, select the offline installation package under Windows host. One point to emphasize, to develop the Win32 program, all the Lib and DLL used in the program need to be 32-bit, to develop x64 program, all the Lib and DLL used in the program need to be 64 bits. The include doesn't matter. Why develop 64-bit programs, because 32-bit programs in the 64-bit WIN7,WIN8,WIN10 system can only use 4G memory ( Microsoft Official note , using Image_file_large_address_aware settings), The 64-bit program can use up to hundreds of g of memory. Of course there are small partners to say how can use so much memory, there must be a memory leak problem, but I still want to say, on the basis of proper memory management , the larger the memory , we can do more things. After the download is complete, it is installed separately and is named with an easily distinguishable name (you can, of course, download only the number of bits you need to install):




You can use the CMD input qmake-v to see if Qt is installed successfully.

Next, install the QT plugin for vs2013 (other downloads in Visual Studio add-in 1.2.4 for QT5 (156 MB)), and you can open QT projects in VS (like the Libqglviewer.pro in the next step):




Of course, you can also use QT creator to open the compilation, but my C disk user name is Chinese, and creator compilation process generated temporary variables in C:\Users\ firewood \appdata always can't recognize the Chinese, error, and I am not familiar with QT Creator so after trying not to solve then use the VS plug-in to open the compiled QT project. After the download is installed open vs2013, the upper left corner can see QT5, development options:




Add the name and path of the QT version you just installed. Name itself, path follows the write in:




(Note that the default version settings below are important, and the next step is to compile different versions of Libqglviewer to set up a different default version of QT here)

3. compiling libqglviewer_2.6.3

After installing QT, we download libqglviewer_2.6.3, after decompression we open with vs2013 (upper left corner of QT5, open Project):




Right-click on the build in the qglviewer, or generate it as follows:




Wait, and then see the Debug version of the successful compilation: (Note that we previously set the default to use a 64-bit QT, so here is the 64-bit libqglviewer compiled results: QGLViewerd2.lib QGLViewerd2.dll)




Select release, then compile and build again:




Also successfully compiled and got the 64-bit release version of the Libqglviewer compilation result: QGLViewer2.lib QGLViewer2.dll.

For 32-bit, we only need to change the default configuration version of the QT plugin:




When you are sure to re-use the plugin to open Libqglviewer.pro, compile and generate debug and release. After completion can be separated by different names, easy to choose the next step library:




4.Cmake Compiling G2O Source code

With Eigen,qt,libqglviewer, we can start compiling the G2O source code, which is also divided into 32-bit and 64-bit two versions. At the beginning of the article has released the G2O download link, decompression once named Win32, in the decompression once named x64:




(Take 32 bits as an example) to open the CMake, the source path and the compilation path are, prompt to build a build:




32-bit words compiler chooses visual Studio 12 2013:




Just focus on eigen,qt,libqglviewer, other such as Csparse CMake has helped us find, do not need to tube. First find the Eigen in ungrouped entries and G2O, add the path (my c:/third_party/eigen/include/eigen3, everyone's suffix should be the same x:/.../eigen/include/ EIGEN3). And then for QT, if you haven't changed the name of the QT original folder after installation, CMake can be found. But we changed it to qt_32, so we also need to manually add the path (for example), qt_qmake_executable select Qmake.exe file, Qt5_dir Select the CMake folder in the folder Qt5:




for Libqglviewer, add the Include and Lib manually (where Lib is a file, QGLViewerd2.lib is the debug version, QGLViewer2.lib is release) :




The include selects the Qglviewer folder, not the file inside:




After manually adding, click Configure, the system will find the remaining QT related information:




Click Configure again to confirm. If you click Generate without red, you can generate G2o.sln in build:




The next step is to x64 the process. CMake set the 64-bit source code path and the compilation path, prompt to create the build folder and select the visual Studio Win64 compiler (note and 32-bit not used):




Set the path of the Eigen,qt,libqglviewer:




Click Configure:




Check QT For additional information then click Configure again, no red hint after clicking Generate:



We can see the G2o.sln in both the 32-bit and 64-bit build folders:





5.vs2013 Generating G20

Open the Win32 G2o.sln with VS2013, and then generate All_build:




Wait and then get all the successful results:




Release next to generate one side:




After success you can see the generated lib,dll,exe file in the bin:






VS Open the G2o.sln in the 64-bit folder and generate the debug version of All_build:




Then the 64-bit release version of All_build:




6. Add environment variables and start using

Add environment variables, Add the folder path to the DLL in path, both 32-bit and 64-bit plus, only develop Win32 words do not need to add 64-bit:

C:\Qt_32\Qt5.5.1\5.5\msvc2013\bin; C:\Qt_64\Qt5.5.1\5.5\msvc2013\bin; C:\g2omaster_x64\bin\Release; C:\g2o-master_x64\bin\Debug; C:\g2o-master_win32\bin\Release; C:\g2o-master_win32\bin\Debug;




The compilation and environment configuration for this g2o is complete. I have successfully used G2O in my slam project, some of which will be noted in the third article about Slam (that is, the next chapter, the basic process and code for visual slam). Here are a few important: (1) Copy the C:\g2o-master_win32\build\g2o\config.h to C:\g2o-master_win32\g2o\, or the VS hint can not find config.h (2) the C: \ G2o-master_win32\external\csparse\cs.h and cs_api.h Copy to C:\g2o-master_win32\g2o\solvers\csparse\, then open the Csparse_ in this folder Helper.h file, change # include <cs.h> to # include "Cs.h" (3) Right-click Vs Engineering, properties, C/C + +, preprocessor plus _windows

The following two pictures are the G2O optimization results of the FR1_XYZ datasets (792 frames) in the TUM dataset: The first one is unprotected, and if there is no match between the new frame and the previous keyframe (the appropriate Hamming distance, the appropriate attitude transform), then many frames will be lost, Until you return to the scene near the previous Keyframe, and the second one adds a protective measure that does not match more than 6 frames in a row, it adds a new frame to the keyframe, computes the continuous attitude transformation of the previous keyframe to the keyframe and then saves it to the edge of the graph optimization.


57 Key frame nodes, 616 edges:



139 Key frame nodes, 1270 edges:



Specific Information the next blog will slowly preach. I am still learning g2o, and I will try to see if I can improve something in the future. Finally recommended a homebound of the blog, I also learned a lot of things, thank you, welcome to exchange, common progress!

About slam-General diagram optimization (G2O) environment collocation (windows8.1 vs2013)

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.