Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: support Ceres 2.0.0 #2732

Merged
merged 1 commit into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/rgbd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ set(the_description "RGBD algorithms")

find_package(Ceres QUIET)
ocv_define_module(rgbd opencv_core opencv_calib3d opencv_imgproc OPTIONAL opencv_viz WRAP python)
ocv_target_link_libraries(${the_module} ${CERES_LIBRARIES})

if(Ceres_FOUND)
ocv_target_compile_definitions(${the_module} PUBLIC CERES_FOUND)
ocv_target_link_libraries(${the_module} ${CERES_LIBRARIES})
if(Ceres_VERSION VERSION_LESS 2.0.0)
ocv_include_directories("${CERES_INCLUDE_DIRS}")
endif()
add_definitions(/DGLOG_NO_ABBREVIATED_SEVERITIES) # avoid ERROR macro conflict in glog (ceres dependency)
else()
message(STATUS "CERES support is disabled. Ceres Solver is Required for Posegraph optimization")
message(STATUS "rgbd: CERES support is disabled. Ceres Solver is Required for Posegraph optimization")
endif()
90 changes: 57 additions & 33 deletions modules/sfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,56 @@ set(the_description "SFM algorithms")


### LIBMV LIGHT EXTERNAL DEPENDENCIES ###
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Gflags QUIET)

find_package(Ceres QUIET)
if(NOT Ceres_FOUND) # Looks like Ceres find glog on the own, so separate search isn't necessary

if(NOT Gflags_FOUND) # Ceres find gflags on the own, so separate search isn't necessary
find_package(Gflags QUIET)
endif()
if(NOT Glog_FOUND) # Ceres find glog on the own, so separate search isn't necessary
find_package(Glog QUIET)
endif()

if((gflags_FOUND OR GFLAGS_FOUND OR GFLAGS_INCLUDE_DIRS) AND (glog_FOUND OR GLOG_FOUND OR GLOG_INCLUDE_DIRS))
set(_fname "${CMAKE_CURRENT_BINARY_DIR}/test_sfm_deps.cpp")
file(WRITE "${_fname}" "#include <glog/logging.h>\n#include <gflags/gflags.h>\nint main() { (void)(0); return 0; }\n")
try_compile(SFM_DEPS_OK "${CMAKE_BINARY_DIR}" "${_fname}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
OUTPUT_VARIABLE OUTPUT
)
file(REMOVE "${_fname}")
message(STATUS "Checking SFM deps... ${SFM_DEPS_OK}")
if(NOT Gflags_FOUND OR NOT Glog_FOUND)
# try local search scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(NOT Gflags_FOUND)
find_package(Gflags QUIET)
endif()
if(NOT Glog_FOUND)
find_package(Glog QUIET)
endif()
endif()

if(NOT DEFINED GFLAGS_INCLUDE_DIRS AND DEFINED GFLAGS_INCLUDE_DIR)
set(GFLAGS_INCLUDE_DIRS "${GFLAGS_INCLUDE_DIR}")
endif()
if(NOT DEFINED GLOG_INCLUDE_DIRS AND DEFINED GLOG_INCLUDE_DIR)
set(GLOG_INCLUDE_DIRS "${GLOG_INCLUDE_DIR}")
endif()

if((gflags_FOUND OR Gflags_FOUND OR GFLAGS_FOUND OR GFLAGS_INCLUDE_DIRS) AND (glog_FOUND OR Glog_FOUND OR GLOG_FOUND OR GLOG_INCLUDE_DIRS))
set(__cache_key "${GLOG_INCLUDE_DIRS} ~ ${GFLAGS_INCLUDE_DIRS} ~ ${GLOG_LIBRARIES} ~ ${GFLAGS_LIBRARIES}")
if(NOT DEFINED SFM_GLOG_GFLAGS_TEST_CACHE_KEY OR NOT (SFM_GLOG_GFLAGS_TEST_CACHE_KEY STREQUAL __cache_key))
set(__fname "${CMAKE_CURRENT_LIST_DIR}/cmake/checks/check_glog_gflags.cpp")
try_compile(
SFM_GLOG_GFLAGS_TEST "${CMAKE_BINARY_DIR}" "${__fname}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
OUTPUT_VARIABLE __output
)
if(NOT SFM_GLOG_GFLAGS_TEST)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Failed compilation check: ${__fname}\n"
"${__output}\n\n"
)
endif()
set(SFM_GLOG_GFLAGS_TEST "${SFM_GLOG_GFLAGS_TEST}" CACHE INTERNAL "")
set(SFM_GLOG_GFLAGS_TEST_CACHE_KEY "${__cache_key}" CACHE INTERNAL "")
message(STATUS "Checking SFM glog/gflags deps... ${SFM_GLOG_GFLAGS_TEST}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LaurentBerger

new.txt
-- Checking SFM deps... FALSE

Logs don't correspond to the content of this patch.
Please re-check that patch is applied properly.

Copy link
Contributor

@LaurentBerger LaurentBerger Nov 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed compilation check: G:/Lib/opencv_contrib/modules/sfm/cmake/checks/check_glog_gflags.cpp
Change Dir: G:/Lib/build/opencv/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe cmTC_32546.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=15.0 /v:m && Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 pour .NET Framework

Copyright (C) Microsoft Corporation. Tous droits réservés.



  Compilateur d'optimisation Microsoft (R) C/C++ version 19.16.27041 pour x64

  Copyright (C) Microsoft Corporation. Tous droits réservés.

  

  cl /c /IG:\Lib\install\gflags\include /Zi /W4 /WX- /diagnostics:classic /MP /Od /Ob0 /Oi /D WIN32 /D _WINDOWS /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /D GFLAGS_IS_A_DLL=1 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHa /RTC1 /MDd /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_32546.dir\Debug\\" /Fd"cmTC_32546.dir\Debug\vc141.pdb" /Gd /TP /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /errorReport:queue  /bigobj G:\Lib\opencv_contrib\modules\sfm\cmake\checks\check_glog_gflags.cpp

  check_glog_gflags.cpp

  

G:\Lib\opencv_contrib\modules\sfm\cmake\checks\check_glog_gflags.cpp(1): fatal error C1083: Impossible d'ouvrir le fichier include : 'glog/logging.h' : No such file or directory [G:\Lib\build\opencv\CMakeFiles\CMakeTmp\cmTC_32546.vcxproj]

Is it good message ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see /IG:\Lib\install\gflags\include but don't see include directory for glog from this log.

Log above requests to specify GLOG_INCLUDE_DIR:

-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h

Could you dump used CMake options?

Copy link
Contributor

@LaurentBerger LaurentBerger Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I added :

-DEigen3_DIR:PATH=${installRepo}/Eigen3/share/eigen3/cmake \
-Dglog_DIR:PATH=${installRepo}/glog/lib/cmake/glog -Dgflags_DIR:PATH=${installRepo}/gflags/lib/cmake/gflags \
-DGLOG_INCLUDE_DIR=${installRepo}/glog/include \

and sfm is true :

new.txt

But now I have got an error building sfm :

1>------ Build started: Project: opencv_sfm, Configuration: Release x64 ------
1>simple_pipeline.cpp
1>G:\lib\install\glog\include\glog/log_severity.h(51): fatal error C1189: #error:  ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
1>Done building project "opencv_sfm.vcxproj" -- FAILED.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fatal error C1189: #error: ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.

Added to handle that (not really related to Ceres 2.0.0):

add_definitions(/DGLOG_NO_ABBREVIATED_SEVERITIES)

endif()
unset(__cache_key)
set(SFM_DEPS_OK "${SFM_GLOG_GFLAGS_TEST}")
else()
set(SFM_DEPS_OK FALSE)
endif()
Expand Down Expand Up @@ -57,23 +90,14 @@ set(LIBMV_LIGHT_LIBS
if(Ceres_FOUND)
add_definitions("-DCERES_FOUND=1")
list(APPEND LIBMV_LIGHT_LIBS simple_pipeline)
list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIR}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this cause a build failure with ceres 1.14, if that is not in a default include path (assuming retaining compatibility with 1.14 is a goal)? It looks to me like ceres 2.0.0 sets the right target properties w.r.t. the include paths, but ceres 1.14 doesn't seem to do so. Otoh with ceres 2.0.0 CERES_INCLUDE_DIRS is not set at all anymore, so you would need to have a conditional to avoid adding an empty include path. In any case, it should be CERES_INCLUDE_DIRS not ..._DIR, I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed (in sfm in rgbd modules).

if(Ceres_VERSION VERSION_LESS 2.0.0)
list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIRS}")
endif()
else()
add_definitions("-DCERES_FOUND=0")
message(STATUS "CERES support is disabled. Ceres Solver for reconstruction API is required.")
endif()

### COMPILE WITH C++11 IF CERES WAS COMPILED WITH C++11

if(Ceres_FOUND)
list (FIND CERES_COMPILED_COMPONENTS "C++11" _index)
if (${_index} GREATER -1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()

### DEFINE OPENCV SFM MODULE DEPENDENCIES ###

### CREATE OPENCV SFM MODULE ###

ocv_add_module(sfm
Expand All @@ -85,6 +109,7 @@ ocv_add_module(sfm
WRAP python
)

add_definitions(/DGLOG_NO_ABBREVIATED_SEVERITIES) # avoid ERROR macro conflict in glog (ceres dependency)

ocv_warnings_disable(CMAKE_CXX_FLAGS
-Wundef
Expand All @@ -97,12 +122,6 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS
-Wsuggest-override
)

if(UNIX)
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
endif()

ocv_include_directories( ${LIBMV_LIGHT_INCLUDES} )
ocv_module_include_directories()

Expand All @@ -117,14 +136,16 @@ ocv_set_module_sources(HEADERS ${OPENCV_SFM_HDRS}

ocv_create_module()

# build libmv_light

### BUILD libmv_light ###

if(NOT CMAKE_VERSION VERSION_LESS 2.8.11) # See ocv_target_include_directories() implementation
if(TARGET ${the_module})
get_target_property(__include_dirs ${the_module} INCLUDE_DIRECTORIES)
include_directories(${__include_dirs})
endif()
endif()
include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
#include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src/libmv_light" "${CMAKE_CURRENT_BINARY_DIR}/src/libmv")

ocv_target_link_libraries(${the_module} ${LIBMV_LIGHT_LIBS})
Expand All @@ -133,6 +154,9 @@ ocv_target_link_libraries(${the_module} ${LIBMV_LIGHT_LIBS})
### CREATE OPENCV SFM TESTS ###

ocv_add_accuracy_tests()
if(Ceres_FOUND AND TARGET opencv_test_sfm)
ocv_target_link_libraries(opencv_test_sfm ${CERES_LIBRARIES})
endif ()


### CREATE OPENCV SFM SAMPLES ###
Expand Down
7 changes: 7 additions & 0 deletions modules/sfm/cmake/checks/check_glog_gflags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <glog/logging.h>
#include <gflags/gflags.h>
int main()
{
(void)(0);
return 0;
}
7 changes: 7 additions & 0 deletions modules/sfm/src/libmv_light/libmv/base/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ class vector {
void reserve(unsigned int size) {
if (size > size_) {
T *data = static_cast<T *>(allocate(size));
#if 0
memcpy(data, data_, sizeof(*data)*size_);
#else
for (int i = 0; i < size_; ++i)
new (&data[i]) T(std::move(data_[i]));
for (int i = 0; i < size_; ++i)
data_[i].~T();
#endif
allocator_.deallocate(data_, capacity_);
data_ = data;
capacity_ = size;
Expand Down
3 changes: 3 additions & 0 deletions modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ TARGET_LINK_LIBRARIES(multiview LINK_PRIVATE ${GLOG_LIBRARY} numeric)
IF(TARGET Eigen3::Eigen)
TARGET_LINK_LIBRARIES(multiview LINK_PUBLIC Eigen3::Eigen)
ENDIF()
IF(CERES_LIBRARIES)
TARGET_LINK_LIBRARIES(multiview LINK_PRIVATE ${CERES_LIBRARIES})
ENDIF()

LIBMV_INSTALL_LIB(multiview)
2 changes: 1 addition & 1 deletion modules/sfm/src/libmv_light/libmv/multiview/fundamental.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ bool EstimateFundamentalFromCorrespondences(
FundamentalSymmetricEpipolarCostFunctor,
2, // num_residuals
9>(fundamental_symmetric_epipolar_cost_function),
NULL,
nullptr,
F->data());
}

Expand Down
2 changes: 1 addition & 1 deletion modules/sfm/src/libmv_light/libmv/multiview/homography.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bool EstimateHomography2DFromCorrespondences(
HomographySymmetricGeometricCostFunctor,
4, // num_residuals
9>(homography_symmetric_geometric_cost_function),
NULL,
nullptr,
H->data());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void EuclideanBundlePointsOnly(const DistortionModelType distortion_model,
marker.x,
marker.y,
1.0)),
NULL,
nullptr,
ceres_intrinsics,
current_camera_R_t,
&point->X(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool EuclideanIntersect(const vector<Marker> &markers,
EuclideanIntersectCostFunctor,
2, /* num_residuals */
3>(new EuclideanIntersectCostFunctor(marker, camera)),
NULL,
nullptr,
&X(0));
num_residuals++;
}
Expand Down
4 changes: 0 additions & 4 deletions modules/sfm/src/libmv_light/libmv/simple_pipeline/tracks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

namespace libmv {

Tracks::Tracks(const Tracks &other) {
markers_ = other.markers_;
}

Tracks::Tracks(const vector<Marker> &markers) : markers_(markers) {}

void Tracks::Insert(int image, int track, double x, double y, double weight) {
Expand Down
2 changes: 1 addition & 1 deletion modules/sfm/src/libmv_light/libmv/simple_pipeline/tracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Tracks {
Tracks() { }

// Copy constructor for a tracks object.
Tracks(const Tracks &other);
Tracks(const Tracks &other) = default;

/// Construct a new tracks object using the given markers to start.
explicit Tracks(const vector<Marker> &markers);
Expand Down