Skip to content

Commit a35c1e3

Browse files
committed
Merge pull request #2732 from alalek:support_ceres_2.0.0
2 parents c5390b2 + 23ee62a commit a35c1e3

File tree

11 files changed

+85
-44
lines changed

11 files changed

+85
-44
lines changed

modules/rgbd/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ set(the_description "RGBD algorithms")
22

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

76
if(Ceres_FOUND)
87
ocv_target_compile_definitions(${the_module} PUBLIC CERES_FOUND)
8+
ocv_target_link_libraries(${the_module} ${CERES_LIBRARIES})
9+
if(Ceres_VERSION VERSION_LESS 2.0.0)
10+
ocv_include_directories("${CERES_INCLUDE_DIRS}")
11+
endif()
12+
add_definitions(/DGLOG_NO_ABBREVIATED_SEVERITIES) # avoid ERROR macro conflict in glog (ceres dependency)
913
else()
10-
message(STATUS "CERES support is disabled. Ceres Solver is Required for Posegraph optimization")
14+
message(STATUS "rgbd: CERES support is disabled. Ceres Solver is Required for Posegraph optimization")
1115
endif()

modules/sfm/CMakeLists.txt

+57-33
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,56 @@ set(the_description "SFM algorithms")
33

44

55
### LIBMV LIGHT EXTERNAL DEPENDENCIES ###
6-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
7-
find_package(Gflags QUIET)
6+
87
find_package(Ceres QUIET)
9-
if(NOT Ceres_FOUND) # Looks like Ceres find glog on the own, so separate search isn't necessary
8+
9+
if(NOT Gflags_FOUND) # Ceres find gflags on the own, so separate search isn't necessary
10+
find_package(Gflags QUIET)
11+
endif()
12+
if(NOT Glog_FOUND) # Ceres find glog on the own, so separate search isn't necessary
1013
find_package(Glog QUIET)
1114
endif()
1215

13-
if((gflags_FOUND OR GFLAGS_FOUND OR GFLAGS_INCLUDE_DIRS) AND (glog_FOUND OR GLOG_FOUND OR GLOG_INCLUDE_DIRS))
14-
set(_fname "${CMAKE_CURRENT_BINARY_DIR}/test_sfm_deps.cpp")
15-
file(WRITE "${_fname}" "#include <glog/logging.h>\n#include <gflags/gflags.h>\nint main() { (void)(0); return 0; }\n")
16-
try_compile(SFM_DEPS_OK "${CMAKE_BINARY_DIR}" "${_fname}"
17-
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
18-
LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
19-
OUTPUT_VARIABLE OUTPUT
20-
)
21-
file(REMOVE "${_fname}")
22-
message(STATUS "Checking SFM deps... ${SFM_DEPS_OK}")
16+
if(NOT Gflags_FOUND OR NOT Glog_FOUND)
17+
# try local search scripts
18+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
19+
if(NOT Gflags_FOUND)
20+
find_package(Gflags QUIET)
21+
endif()
22+
if(NOT Glog_FOUND)
23+
find_package(Glog QUIET)
24+
endif()
25+
endif()
26+
27+
if(NOT DEFINED GFLAGS_INCLUDE_DIRS AND DEFINED GFLAGS_INCLUDE_DIR)
28+
set(GFLAGS_INCLUDE_DIRS "${GFLAGS_INCLUDE_DIR}")
29+
endif()
30+
if(NOT DEFINED GLOG_INCLUDE_DIRS AND DEFINED GLOG_INCLUDE_DIR)
31+
set(GLOG_INCLUDE_DIRS "${GLOG_INCLUDE_DIR}")
32+
endif()
33+
34+
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))
35+
set(__cache_key "${GLOG_INCLUDE_DIRS} ~ ${GFLAGS_INCLUDE_DIRS} ~ ${GLOG_LIBRARIES} ~ ${GFLAGS_LIBRARIES}")
36+
if(NOT DEFINED SFM_GLOG_GFLAGS_TEST_CACHE_KEY OR NOT (SFM_GLOG_GFLAGS_TEST_CACHE_KEY STREQUAL __cache_key))
37+
set(__fname "${CMAKE_CURRENT_LIST_DIR}/cmake/checks/check_glog_gflags.cpp")
38+
try_compile(
39+
SFM_GLOG_GFLAGS_TEST "${CMAKE_BINARY_DIR}" "${__fname}"
40+
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${GLOG_INCLUDE_DIRS};${GFLAGS_INCLUDE_DIRS}"
41+
LINK_LIBRARIES ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES}
42+
OUTPUT_VARIABLE __output
43+
)
44+
if(NOT SFM_GLOG_GFLAGS_TEST)
45+
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
46+
"Failed compilation check: ${__fname}\n"
47+
"${__output}\n\n"
48+
)
49+
endif()
50+
set(SFM_GLOG_GFLAGS_TEST "${SFM_GLOG_GFLAGS_TEST}" CACHE INTERNAL "")
51+
set(SFM_GLOG_GFLAGS_TEST_CACHE_KEY "${__cache_key}" CACHE INTERNAL "")
52+
message(STATUS "Checking SFM glog/gflags deps... ${SFM_GLOG_GFLAGS_TEST}")
53+
endif()
54+
unset(__cache_key)
55+
set(SFM_DEPS_OK "${SFM_GLOG_GFLAGS_TEST}")
2356
else()
2457
set(SFM_DEPS_OK FALSE)
2558
endif()
@@ -57,23 +90,14 @@ set(LIBMV_LIGHT_LIBS
5790
if(Ceres_FOUND)
5891
add_definitions("-DCERES_FOUND=1")
5992
list(APPEND LIBMV_LIGHT_LIBS simple_pipeline)
60-
list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIR}")
93+
if(Ceres_VERSION VERSION_LESS 2.0.0)
94+
list(APPEND LIBMV_LIGHT_INCLUDES "${CERES_INCLUDE_DIRS}")
95+
endif()
6196
else()
6297
add_definitions("-DCERES_FOUND=0")
6398
message(STATUS "CERES support is disabled. Ceres Solver for reconstruction API is required.")
6499
endif()
65100

66-
### COMPILE WITH C++11 IF CERES WAS COMPILED WITH C++11
67-
68-
if(Ceres_FOUND)
69-
list (FIND CERES_COMPILED_COMPONENTS "C++11" _index)
70-
if (${_index} GREATER -1)
71-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
72-
endif()
73-
endif()
74-
75-
### DEFINE OPENCV SFM MODULE DEPENDENCIES ###
76-
77101
### CREATE OPENCV SFM MODULE ###
78102

79103
ocv_add_module(sfm
@@ -85,6 +109,7 @@ ocv_add_module(sfm
85109
WRAP python
86110
)
87111

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

89114
ocv_warnings_disable(CMAKE_CXX_FLAGS
90115
-Wundef
@@ -97,12 +122,6 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS
97122
-Wsuggest-override
98123
)
99124

100-
if(UNIX)
101-
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
102-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
103-
endif()
104-
endif()
105-
106125
ocv_include_directories( ${LIBMV_LIGHT_INCLUDES} )
107126
ocv_module_include_directories()
108127

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

118137
ocv_create_module()
119138

120-
# build libmv_light
139+
140+
### BUILD libmv_light ###
141+
121142
if(NOT CMAKE_VERSION VERSION_LESS 2.8.11) # See ocv_target_include_directories() implementation
122143
if(TARGET ${the_module})
123144
get_target_property(__include_dirs ${the_module} INCLUDE_DIRECTORIES)
124145
include_directories(${__include_dirs})
125146
endif()
126147
endif()
127-
include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
148+
#include_directories(${OCV_TARGET_INCLUDE_DIRS_${the_module}})
128149
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src/libmv_light" "${CMAKE_CURRENT_BINARY_DIR}/src/libmv")
129150

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

135156
ocv_add_accuracy_tests()
157+
if(Ceres_FOUND AND TARGET opencv_test_sfm)
158+
ocv_target_link_libraries(opencv_test_sfm ${CERES_LIBRARIES})
159+
endif ()
136160

137161

138162
### CREATE OPENCV SFM SAMPLES ###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <glog/logging.h>
2+
#include <gflags/gflags.h>
3+
int main()
4+
{
5+
(void)(0);
6+
return 0;
7+
}

modules/sfm/src/libmv_light/libmv/base/vector.h

+7
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ class vector {
121121
void reserve(unsigned int size) {
122122
if (size > size_) {
123123
T *data = static_cast<T *>(allocate(size));
124+
#if 0
124125
memcpy(data, data_, sizeof(*data)*size_);
126+
#else
127+
for (int i = 0; i < size_; ++i)
128+
new (&data[i]) T(std::move(data_[i]));
129+
for (int i = 0; i < size_; ++i)
130+
data_[i].~T();
131+
#endif
125132
allocator_.deallocate(data_, capacity_);
126133
data_ = data;
127134
capacity_ = size;

modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ TARGET_LINK_LIBRARIES(multiview LINK_PRIVATE ${GLOG_LIBRARY} numeric)
2121
IF(TARGET Eigen3::Eigen)
2222
TARGET_LINK_LIBRARIES(multiview LINK_PUBLIC Eigen3::Eigen)
2323
ENDIF()
24+
IF(CERES_LIBRARIES)
25+
TARGET_LINK_LIBRARIES(multiview LINK_PRIVATE ${CERES_LIBRARIES})
26+
ENDIF()
2427

2528
LIBMV_INSTALL_LIB(multiview)

modules/sfm/src/libmv_light/libmv/multiview/fundamental.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ bool EstimateFundamentalFromCorrespondences(
521521
FundamentalSymmetricEpipolarCostFunctor,
522522
2, // num_residuals
523523
9>(fundamental_symmetric_epipolar_cost_function),
524-
NULL,
524+
nullptr,
525525
F->data());
526526
}
527527

modules/sfm/src/libmv_light/libmv/multiview/homography.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ bool EstimateHomography2DFromCorrespondences(
318318
HomographySymmetricGeometricCostFunctor,
319319
4, // num_residuals
320320
9>(homography_symmetric_geometric_cost_function),
321-
NULL,
321+
nullptr,
322322
H->data());
323323
}
324324

modules/sfm/src/libmv_light/libmv/simple_pipeline/bundle.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void EuclideanBundlePointsOnly(const DistortionModelType distortion_model,
402402
marker.x,
403403
marker.y,
404404
1.0)),
405-
NULL,
405+
nullptr,
406406
ceres_intrinsics,
407407
current_camera_R_t,
408408
&point->X(0));

modules/sfm/src/libmv_light/libmv/simple_pipeline/intersect.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool EuclideanIntersect(const vector<Marker> &markers,
113113
EuclideanIntersectCostFunctor,
114114
2, /* num_residuals */
115115
3>(new EuclideanIntersectCostFunctor(marker, camera)),
116-
NULL,
116+
nullptr,
117117
&X(0));
118118
num_residuals++;
119119
}

modules/sfm/src/libmv_light/libmv/simple_pipeline/tracks.cc

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
namespace libmv {
3030

31-
Tracks::Tracks(const Tracks &other) {
32-
markers_ = other.markers_;
33-
}
34-
3531
Tracks::Tracks(const vector<Marker> &markers) : markers_(markers) {}
3632

3733
void Tracks::Insert(int image, int track, double x, double y, double weight) {

modules/sfm/src/libmv_light/libmv/simple_pipeline/tracks.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Tracks {
6565
Tracks() { }
6666

6767
// Copy constructor for a tracks object.
68-
Tracks(const Tracks &other);
68+
Tracks(const Tracks &other) = default;
6969

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

0 commit comments

Comments
 (0)