Ask Your Question
0

error in compiling example_sfm_trajectory_reconstruction.cpp from opencv_contrib sfm module

asked 2018-11-24 01:18:46 -0600

saptami gravatar image

I am going through this tutorial : link text

This is my CMakeLists.

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project( sfm_module )
find_package(OpenCV COMPONENTS sfm REQUIRED)
find_package( Eigen3 REQUIRED )
find_package( Ceres REQUIRED )
message(STATUS "Found OpenCV version ${OpenCV_VERSION}")
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories( /usr/local/include/Eigen )
include_directories( /usr/local/include/opencv2/sfm )
include_directories( /usr/local/include/ceres )
set(OpenCV_LIBS /usr/local/lib/)

add_executable( example_sfm_trajectory_reconstruction example_sfm_trajectory_reconstruction.cpp )
target_link_libraries( example_sfm_trajectory_reconstruction ${OpenCV_LIBS})

I am getting the following errors in make :

~/Desktop/sfm_module/build$ make

 Scanning dependencies of target example_sfm_trajectory_reconstruction
    [ 50%] Building CXX object CMakeFiles/example_sfm_trajectory_reconstruction.dir/example_sfm_trajectory_reconstruction.cpp.o
    [100%] Linking CXX executable example_sfm_trajectory_reconstruction
    CMakeFiles/example_sfm_trajectory_reconstruction.dir/example_sfm_trajectory_reconstruction.cpp.o: In function `main':
    example_sfm_trajectory_reconstruction.cpp:(.text+0xa50): undefined reference to `cv::sfm::reconstruct(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, bool)'


      example_sfm_trajectory_reconstruction.cpp:(.text+0xc27): undefined reference to `cv::viz::Viz3d::Viz3d(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
      example_sfm_trajectory_reconstruction.cpp:(.text+0xc83): undefined reference to 

`cv::viz::Viz3d::setBackgroundColor(cv::viz::Color const&, cv::viz::Color const&)'
  example_sfm_trajectory_reconstruction.cpp:(.text+0xc9c): undefined reference to `cv::viz::Viz3d::registerKeyboardCallback(void (*)(cv::viz::KeyboardEvent const&, void*), void*)'
   example_sfm_trajectory_reconstruction.cpp:(.text+0xf08): undefined reference to `cv::viz::Viz3d::wasStopped() const'
    example_sfm_trajectory_reconstruction.cpp:(.text+0xf8b): undefined reference to `cv::Mat::eye(int, int, int)'
    example_sfm_trajectory_reconstruction.cpp:(.text+0x10b0): undefined reference to `cv::viz::WCube::WCube(cv::Point3_<double> const&, cv::Point3_<double> const&, bool, cv::viz::Color const&)'

These are the headers :

#define CERES_FOUND true 
#include <opencv2/core.hpp> 
#include <opencv2/sfm.hpp>
#include <opencv2/sfm/reconstruct.hpp>
#include <opencv2/viz.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/highgui.hpp>
edit retag flag offensive close merge delete

Comments

#define CERES_FOUND true

did you add that ?

you have to make sure, cmake finds the CERES libs during the compilation of the opencv libs, NOT when building your program (it's too late, then)

berak gravatar imageberak ( 2018-11-24 01:23:16 -0600 )edit

I don't understand your cmakeLists.txt. you use find_package and you give a path in include_directories

LBerger gravatar imageLBerger ( 2018-11-24 02:58:50 -0600 )edit

@LBerger Later I commented out those include_directories, but got the same errors.

saptami gravatar imagesaptami ( 2018-11-24 03:36:34 -0600 )edit

my cmakelist is here :

PROJECT (chSfm)
find_package(glog QUIET REQUIRED)
find_package(ceres QUIET REQUIRED)
find_package(OpenCV  REQUIRED)
find_package(VTK  OPTIONAL_COMPONENTS)

file(GLOB chSfm_SRCS
    "*.h"
    "*.cpp")
ADD_EXECUTABLE (chSfm ${chSfm_SRCS})

if (OpenCV_FOUND)
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    include_directories( ${EIGEN_INCLUDE_DIRS} )
    if (VTK_FOUND)
        add_definitions(-DUSE_VTK)
        include_directories( ${VTK_INCLUDE_DIRS} )
        target_link_libraries( chSfm ${VTK_LIBRARIES} )
    endif (Vtk_FOUND)
    if(ceres_FOUND)
        add_definitions("-DCERES_FOUND=1")
    endif(ceres_FOUND)
    target_link_libraries( chSfm ${OpenCV_LIBS} )
else (OpenCV_FOUND)
message("PB->OPENCV = ${OpenCV_INCLUDE_DIRS}")
endif (OpenCV_FOUND)
LBerger gravatar imageLBerger ( 2018-11-24 03:39:29 -0600 )edit

I think you can remove glog

LBerger gravatar imageLBerger ( 2018-11-24 03:40:52 -0600 )edit

@berak Yeah, I added that line after someone suggested in github issues. I installed Ceres later when I started the tutorial, after OpenCV and contrib installation was done. So rebuilding OpenCV is the only solution?

saptami gravatar imagesaptami ( 2018-11-24 03:43:04 -0600 )edit
1

So rebuilding OpenCV is the only solution?

yes. it's the opencv_sfm library, which needs CERES support (it also depends on viz !), not your code

berak gravatar imageberak ( 2018-11-24 03:52:51 -0600 )edit

@LBerger Thanks for your upload, I tried with the CMakeLists.txt , but this is also producing the same error.

saptami gravatar imagesaptami ( 2018-11-24 03:53:09 -0600 )edit

@berak Is this enough?

 cmake -DENABLE_CXX11=1 -I/usr/local/include/ceres -DOPENCV_EXTRA_MODULES_PATH=/home/saptami/opencv_contrib-4.0.0/modules -DBUILD_EXAMPLES=ON ..

Or should I build along with the other cmake flags also as per the opencv installation tutorial?

saptami gravatar imagesaptami ( 2018-11-24 03:56:03 -0600 )edit
1

to build opencv with ceres (windows10) :

-DEIGEN_DIR:PATH="$myRepo"/eigen -DEIGEN_INCLUDE_DIR="$myRepo"/eigen -DEIGEN_INCLUDE_PATH="$myRepo"/eigen \
-DCeres_DIR=${installRepo}/ceres-solver/cmake -Dglog_DIR:PATH=${installRepo}/glog/lib/cmake/glog -Dgflags_DIR:PATH=${installRepo}/gflags/lib/cmake/gflags \

with linux cmake must be able to detect ceres

LBerger gravatar imageLBerger ( 2018-11-24 04:08:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-11-26 06:19:52 -0600

saptami gravatar image

updated 2018-11-26 08:16:45 -0600

I resolved this issue, after removing this -lgflags_nothreads_static from modules/sfm/CMakeFiles/opencv_sfm.dir/link.txt (as there was no lib file for gflags_nothreads_static from gflags) file OpenCV sfm module compiled successfully and executable for example_sfm_trajectory_reconstruction.cpp was generated. Thank you for your helps @berak and @LBerger.

edit flag offensive delete link more

Comments

Nice. On windows there is a gflags_nothreads_static.lib

LBerger gravatar imageLBerger ( 2018-11-26 06:59:41 -0600 )edit
1

Ok, I needed to set these values set for gflags static lib

~/gflags/build$ cmake  -DGFLAGS_BUILD_STATIC_LIBS=1 -DGFLAGS_BUILD_gflags_nothreads_LIB=1 -DGFLAGS_INSTALL_STATIC_LIBS=1 -DBUILD_SHARED_LIBS=ON ..

Then no need to edit opencv/build/modules/sfm/CMakeFiles/opencv_sfm.dir/link.txt file

saptami gravatar imagesaptami ( 2018-11-26 13:15:50 -0600 )edit

Question Tools

Stats

Asked: 2018-11-24 01:18:46 -0600

Seen: 629 times

Last updated: Nov 26 '18