openMVG / openMVG

open Multiple View Geometry library. Basis for 3D computer vision and Structure from Motion.
Mozilla Public License 2.0
5.72k stars 1.68k forks source link

Android support #1376

Open didi16 opened 6 years ago

didi16 commented 6 years ago

Hi everyone,

For my project I need to implement part of the functions available on openMVG on android. My goal is to cross compile the whole library to android using standalone Toolchains. I've read through some of the issues and I am aware that there is already a rep for this purpose. However, i've found it very frustrating to actually make it work and documentation is a bit scarce. I have little experience with cross compilation and after 3 days trying to cross compile i haven't succeed yet. Is there anyone familiar with this project that knows how to do this? I feel that my lack of experience is really delaying me while this should not take all this time.

pmoulon commented 6 years ago

As you see before I tried to ping some people that have used OpenMVG on android app before (#1326) but they did not provided any answer.

  1. You will have to compile OpenMVG libraries only (Please set the cmake variable OpenMVG_BUILD_SOFTWARES to OFF)
  2. Can you describe which kind of error are you hitting? You will also need to edit the file openMVG/src/CMakeLists.txt and comment this two line:

    AutodetectHostArchitecture()

    OptimizeForArchitecture()

See here the thread of people that succeeded to use OpenMVG on iPhone

donlk commented 6 years ago

Personally i would've helped happily (within my abilities) if the author of #1326 had any specific questions i could answer. Nevertheless, cross-compiling is not an Android specific issue, albeit it certainly makes it a bit more tricky. OpenMVG is cmake-based, that makes the whole process much less stressful. For quite a long time, libraries had to adopt (and still do) a certain habit of providing a cmake toolchain descriptor designed specifically for android builds, having all the variables necessary for cmake to build Android binaries. You had to specify that as a cmake parameter: cmake -DCMAKE_TOOLCHAIN_FILE=<file>. This was a necessity because cmake had no knowledge of Android as a system and the different build tools it has, so you had to tell all the directives through these descriptor files. Fortunately, it seems the guys at Kitware began to notice the ever-growing need for cmake projects to run on Android, so they decided to do the heavy lifting themselves by dealing with all the variables natively, without the need of such descriptor files. Now cmake knows what Android is when you desire to build for it, and you only need to provide the variables specific to your needs. You can read more about it here

TL;DR: The way you build for Android is the same you build for Linux. The only difference is the parameters you provide. The aformentioned link even has a cmake invocation example if you just want to experiment with it. Let me know if you hit any issues.

didi16 commented 6 years ago

Hi,

I managed to cross-compile everything, including software, using Oliver001/openMVG rep. In the end it is quite simple, despite the fact that documentation might not be that clear all the time.

Thanks

donlk commented 6 years ago

Glad it worked out!

pmoulon commented 6 years ago

@didi16 Would you like to help to upgrade the documentation with an Android section?

Thx @didi16 and @donlk for your messages.

didi16 commented 6 years ago

@pmoulon Yes, I would be quite glad to contribute!

pmoulon commented 6 years ago

@didi16 I would be happy to work with you on extending the documentation toward adding an Android section. Feel free to ping me.

PaikWai commented 5 years ago

@pmoulon @didi16 @donlk Hi all, good day, Im facing problem of the integration of openMVG with android studio, can you guys help me in solve this problem? Thanks.

pmoulon commented 5 years ago

What problem are you facing? please elaborate so we can help you.

PaikWai commented 5 years ago

@pmoulon my problem is how can i integrate openMVG in android studio? Can you provide me some step to doing so? thanks

philopkid commented 3 years ago

Hi. I couldnt configure/build openMVG. and im losing ideas. i tried to cross compile openMVG in cmake(gui) choosing ninja as generator and choosing "specify toolchain file for cross-compiling" using this path Android/Sdk/ndk/22.1.7171670/build/cmake/android.toolchain.cmake and this happened "Configuring incomplete, errors occurred!" im using though Oliver001/openMVG. what is wrong with it?

pmoulon commented 3 years ago

Any other informative error message? @philopkid

philopkid commented 3 years ago

When i put the folder openMVG in the ndk folder and uses the toolchain on the cmake(gui) Android/Sdk/ndk/22.1.7171670/build/cmake/android.toolchain.cmake it started to configure but then. when i generate the folder where there should have been an output it is empty? what is wrong with it? @pmoulon

philopkid commented 3 years ago

This what happens when i configure. The problem now it isnt generating anything when i hit generate. Note: I made one changes. I changed the find_host_package() with find_package() coz it seems that find_host_packages gets an error of unknown command. when i use ninja and android.toolchain.cmake

ANDROID_PLATFORM not set. Defaulting to minimum supported version 16. Android: Targeting API '30' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a' Android: Selected unified Clang toolchain The C compiler identification is Clang 11.0.5 The CXX compiler identification is Clang 11.0.5 Detecting C compiler ABI info Detecting C compiler ABI info - done Check for working C compiler: C:/android-ndk-r22b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped Detecting C compile features Detecting C compile features - done Detecting CXX compiler ABI info Detecting CXX compiler ABI info - done Check for working CXX compiler: C:/android-ndk-r22b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped Detecting CXX compile features Detecting CXX compile features - done Hello from Android build! Checking for C++11 compiler Checking for C++11 compiler - available Performing Test SUPPORTS_STD_CXX11 Performing Test SUPPORTS_STD_CXX11 - Success Performing Test SUPPORTS_STD_CXX01 Performing Test SUPPORTS_STD_CXX01 - Success Looking for C++ include thread Looking for C++ include thread - found Looking for C++ include chrono Looking for C++ include chrono - found Found OpenMP_C: -fopenmp=libomp (found version "5.0") Found OpenMP_CXX: -fopenmp=libomp (found version "5.0") Found OpenMP: TRUE (found version "5.0")
-- Did not find MOSEK header -- Did not find MOSEK library Could not find mosek library on this machine. Eigen 3.2.8 found (include: C:/android-ndk-r22b/openMVGo/src/third_party/eigen) Flann 1.8.4 found (include: C:/android-ndk-r22b/openMVGo/src/third_party/flann/src/cpp/flann) CoinUtils 2.9.3 found (include: C:/android-ndk-r22b/openMVGo/src/dependencies/osi_clp/CoinUtils/src) Clp 1.15.11 found (include: C:/android-ndk-r22b/openMVGo/src/dependencies/osi_clp/Clp/src) Osi 0.106.10 found (include: C:/android-ndk-r22b/openMVGo/src/dependencies/osi_clp/Osi/src/Osi) CMake Deprecation Warning at dependencies/osi_clp/CMakeLists.txt:6 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

Lemon found (include: C:/android-ndk-r22b/openMVGo/src/third_party/lemon/lemon) CMake Deprecation Warning at third_party/lemon/CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

Found PythonInterp: C:/Users/Sky/AppData/Local/Programs/Python/Python39/python.exe (found version "3.9.6") Could NOT find Wget (missing: WGET_EXECUTABLE) Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) Could NOT find Ghostscript (missing: GHOSTSCRIPT_EXECUTABLE) Could NOT find GLPK (missing: GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_PROPER_VERSION_FOUND) (Required is at least version "4.33") Could NOT find ILOG (missing: ILOG_CPLEX_LIBRARY ILOG_CPLEX_INCLUDE_DIR) Could NOT find COIN (missing: COIN_INCLUDE_DIR COIN_CBC_LIBRARY COIN_CBC_SOLVER_LIBRARY COIN_CGL_LIBRARY COIN_CLP_LIBRARY COIN_COIN_UTILS_LIBRARY COIN_OSI_LIBRARY COIN_OSI_CBC_LIBRARY COIN_OSI_CLP_LIBRARY) Could NOT find SOPLEX (missing: SOPLEX_LIBRARY SOPLEX_INCLUDE_DIR) Looking for sys/types.h Looking for sys/types.h - found Looking for stdint.h Looking for stdint.h - found Looking for stddef.h Looking for stddef.h - found Check size of long long Check size of long long - done Looking for pthread.h Looking for pthread.h - found Performing Test CMAKE_HAVE_LIBC_PTHREAD Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed Looking for pthread_create in pthreads Looking for pthread_create in pthreads - not found Looking for pthread_create in pthread Looking for pthread_create in pthread - not found Check if compiler accepts -pthread Check if compiler accepts -pthread - yes Found Threads: TRUE
CMake Deprecation Warning at third_party/jpeg/CMakeLists.txt:2 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

Looking for stdlib.h Looking for stdlib.h - found CMake Deprecation Warning at third_party/png/CMakeLists.txt:9 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

Looking for assert.h Looking for assert.h - found Looking for fcntl.h Looking for fcntl.h - found Looking for io.h Looking for io.h - not found Looking for jbg_newlen Looking for jbg_newlen - not found Looking for mmap Looking for mmap - found Looking for search.h Looking for search.h - found Looking for string.h Looking for string.h - found Looking for unistd.h Looking for unistd.h - found CMake Deprecation Warning at third_party/vectorGraphics/CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at third_party/cxsparse/CMakeLists.txt:4 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at third_party/ceres-solver/CMakeLists.txt:32 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at third_party/ceres-solver/CMakeLists.txt:33 (cmake_policy): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

=============================================================== Ceres-solver configuration.

CMake Warning (dev) at third_party/ceres-solver/CMakeLists.txt:115 (option): Policy CMP0077 is not set: option() honors normal variables. Run "cmake --help-policy CMP0077" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

For compatibility with older versions of CMake, option is clearing the normal variable 'BUILD_SHARED_LIBS'. This warning is for project developers. Use -Wno-dev to suppress it.

Eigen 3.2.8 found (include: C:/android-ndk-r22b/openMVGo/src/third_party/eigen) -- Found Eigen version 3.2.8: C:/android-ndk-r22b/openMVGo/src/third_party/eigen

=============================================================== Disabling the use of Eigen as a sparse linear algebra library. This does not affect the covariance estimation algorithm which can still use the EIGEN_SPARSE_QR algorithm.

-- Did not find LAPACK library, disabling LAPACK support. -- Did not find BLAS library, disabling LAPACK support. -- Building without SuiteSparse. -- Found CXSparse in: ../cxsparse/Include, building with CXSparse. -- Google Flags disabled; no tests or tools will be built! -- Compiling minimal glog substitute into Ceres. -- Using minimal glog substitute (include): internal/ceres/miniglog -- Compiler is Clang, disabling OpenMP. Performing Test COMPILER_HAS_CXX11_FLAG Performing Test COMPILER_HAS_CXX11_FLAG - Success Looking for C++ include unordered_map Looking for C++ include unordered_map - found Performing Test HAVE_UNORDERED_MAP_IN_STD_NAMESPACE Performing Test HAVE_UNORDERED_MAP_IN_STD_NAMESPACE - Success -- Found unordered_map/set in std namespace. Looking for C++ include memory Looking for C++ include memory - found Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE - Success -- Found shared_ptr in std namespace using header. -- Building Ceres as a static library. Performing Test HAVE_RETURN_TYPE_C_LINKAGE Performing Test HAVE_RETURN_TYPE_C_LINKAGE - Success Creating configured Ceres config.h output directory: C:/Users/Sky/Desktop/openMVGAndroid/third_party/ceres-solver/config/ceres/internal Enabling CERES_NO_LAPACK in Ceres config.h Enabling CERES_NO_SUITESPARSE in Ceres config.h Enabling CERES_NO_THREADS in Ceres config.h Enabling CERES_STD_UNORDERED_MAP in Ceres config.h -- add liblog.so for android -- Do not build any example.

Ceres-solver configuration end.

Found OpenMP_C: -fopenmp=libomp (found version "5.0") Found OpenMP_CXX: -fopenmp=libomp (found version "5.0") CMake Deprecation Warning at third_party/easyexif/CMakeLists.txt:3 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at third_party/eigen/CMakeLists.txt:2 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

Configured Eigen 3.2.8

Could NOT find Sphinx (missing: SPHINX_EXECUTABLE) Sphinx need to be installed to generate the sphinx documentation Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) Doxygen need to be installed to generate the doxygen documentation

OpenMVG version: 1.0.0 Build Shared libs: OFF Build OpenMVG tests: OFF Build OpenMVG documentation: ON Build OpenMVG samples applications: OFF Build OpenMVG openGL examples: OFF Enable code coverage generation: OFF Enable OpenMP parallelization: ON Build OpenCV+OpenMVG samples programs: OFF Use OpenCV SIFT features: OFF

EIGEN: 3.2.8 (internal) CERES: 1.11.0 (internal) FLANN: 1.8.4 (internal) LIBTIFF: (internal) LIBPNG: (internal) LIBJPEG (internal) CLP: 1.15.11 (internal) COINUTILS: 2.9.3 (internal) OSI: 0.106.10 (internal) LEMON: 1.3 (internal)

Configuring done

philopkid commented 3 years ago

I solved it. didi6 was right when he said this "In the end it is quite simple, despite the fact that documentation might not be that clear all the time.".

MohammadMDSA commented 3 years ago

@philopkid What did you do?!

MohammadMDSA commented 3 years ago

Please help me. I am not sure what exactly should I do to import this library to an Android project. I was fine when I generated project for VS. With some search I realized that I should copy src directory content into a directory in my Android project that I marked it as cmake directory in gradle.build. When I tried to build project I goth this error:

C/C++: C:\Users\PCMD\AndroidStudioProjects\Trowel\app\src\main\cpp\CMakeLists.txt debug|x86 : CMake Error at C:\Users\PCMD\AndroidStudioProjects\Trowel\app\src\main\cpp\cmakeFindModules\FindEigen.cmake:53 (MESSAGE): You are attempting to build without Eigen. Please use cmake variable -DEIGEN_INCLUDE_DIR_HINTS:STRING="PATH" or EIGEN_INCLUDE_DIR_HINTS env. variable to a valid Eigen path. Or install last Eigen version. Call Stack (most recent call first): CMakeLists.txt:257 (find_package) I did what it says and there was no progress. Then I decided to do it with Cmake GUI based on what @pmoulon said assuming this is the correct way to do it (And I'm still not sure what result should I expect and what is the next step...). It gave me some error that said 'CMAKE_MAKE_PROGRAM not specified' or something like that. Then I downloaded Ninja build and specified the variable in Cmake and then back to previous step. It gave me the one Android Studio was giving me about Eigen library... .

Please help me. This is very time sensitive for me. Thank you.

MohammadMDSA commented 3 years ago

Any help?

philopkid commented 3 years ago

@MohammadMDSA look for cmake module path on android toolchain

MohammadMDSA commented 3 years ago

@philopkid I actually solved it and it was much more complicated. I will write a complete step-by-step solution after finishing my project.

pmoulon commented 3 years ago

Thank you guys for helping each other. Appreciated this. @MohammadMDSA Feel free to add a section in the build.MD or consider add something in the wiki section.

I wish it would be easy for all platform...

andrew-m-h commented 2 years ago

@MohammadMDSA I'm trying to build on Android as well, can't quite get it working. Do you have any hints about how you got it working before I have to work out everything you've done on my own? Cheers for any help!