Build OpenCV SFM on Windows

There are 4 steps to compiling OpenCV_SFM on windows.

 

  1. Building gFlags and Glog.
  2. Building Ceres-Solver
  3. Building VTK
  4. Building OpenCV_SFM.

 

Lets follow them one by one.

  1. Create a folder named ‘ceres’ at the location where you want to build ceres-solver. I created it in my Documents folder.
  2. Inside this folder download and unzip the source code for gflags and glog such that you get the document tree like ‘ceres/gflag’ and ‘ceres/glog’.
  3. Lets build gflag first. Open Cmake and select the source path as the path to the gflag folder inside the ceres folder.
  4. Create a folder inside gflag folder named build. Use the path to this build folder for the build path.
  5. Click on configure and select the installed MSVC compiler on your system. Gflags should be configured without any error. Click on generate. A solution would be generated inside the gflags/build folder.
  6. Open the solution file in Visual Studio and Build it in Debug and Release Configuration. We have successfully built gflags. Now lets move on to Glog.
  7. Inside the glog folder, create a folder named build.
  8. Open Cmake. Give the source path as the path to your glog folder and the build path as the path to the build folder inside glog.
  9. Click on configure and select the installed MSVC compiler on your system. Glog might ask for gflags after you configure. If it does then give the path to the build folder of gflag for the GFLAG_DIR variable and click on configure again. It should find the include and library path for gflag. If it doesn’t do it manually by giving the path to GFLAG_INCLUDE_DIR and GFLAG_LIBRARY_DIR. Please note we are building the Release Library for SFM. So wherever required give the path to the Release folder for the libraries. If you want to build Debug Library, simply repeat the steps again and this time give path to Debug Libraries instead of Release. This would help you build Debug Libraries as well.
  10. Once glog configure picks up everything it needs, click on generate. A solution file will be generated in the build folder just like gflag. Now, just like gflag, open this solution file in Visual Studio and build it in Release and Debug mode.  We have successfully built the glog library.
  11. Download and unzip the latest stable release of Eigen inside the ceres folder. There is no need to build eigen. So now you have 3 folders inside the ceres folder. Ceres/gflag, ceres/glog, ceres/eigen.
  12. We are ready to build the ceres-solver. Download and unzip the ceres-solver source inside the ceres folder. Make a new folder named ceres-bin for the build.
  13. Open cmake and give the path to the source folder as the path to the ceres folder. Give the path to the build folder as the path to the ceres-bin folder.
  14. Click on configure. Select the MSVC compiler. There would be errors. First one is usually the eigen error. Give the path to the ceres/eigen folder for the EIGEN_DIR variable and click on configure again.
  15. This time, there will be errors for Gflags and Glog. Give the required GFLAG_INCLUDE_DIR and GFLAG_LIBRARY and GLOG_INCLUDE_DIR and GLOG_LIBRARY path and click on configure.
  16. This should resolve all the issues. CERES will be configured to build without any SPARSE Library. Click on Generate. A solution for MSVC will be generated in the ‘ceres-bin’ folder.
  17. Open the ceres.sln file in your Visual Studio, in Administrator Mode. In the solution view tab, find the project named ceres. Right Click on the project and select Properties. On the Properties window, on the left hand side, expand the C/C++ option. Inside that list, select Compiler Optimizations and set it to “Disabled.”
  18. Now build the project in Release Mode. Ceres will be built. Once the solution will be built, find the INSTALL project. Right click on it. Project Only > Build Only this project.
  19. Ceres Solver is now installed on your system.
  20. Follow similar steps for installing VTK.
  21. Once all of this is done, try generating the SFM Module from OpenCV_NonFree modules. It should build sucessfully. If you face any issues, try dropping an email. I will try to help as and when possible.

Disclaimer: This Post assumes, you know that SFM in OpenCV is a part of its Non Free Module and that its use for any commercial purpose is defined by its license for which you might have to pay. I hold no legal responsibility for any lapses arising out of non licensing of module.

2 thoughts on “Build OpenCV SFM on Windows”

  1. Dear Agrawal
    I am sorry for disturbing but i did all instructions you gave above, and still I do not know how to generate sfm module on windows. If you give some advices, I would be grateful.
    Thank a lot.
    Best regards
    Prof.Di.Ibrahim Emiroglu
    YILDIZ TECHNICAL UNIVERSITY
    MATHEMATICAL ENGINEERING DEPT.

Leave a Reply

Your email address will not be published. Required fields are marked *