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

SFM module example error (reconstruct not declared in this scope ) #476

Closed
Wababa opened this issue Dec 18, 2015 · 38 comments
Closed

SFM module example error (reconstruct not declared in this scope ) #476

Wababa opened this issue Dec 18, 2015 · 38 comments
Labels

Comments

@Wababa
Copy link

Wababa commented Dec 18, 2015

Hi,
I followed the steps from the opencv docs to install the dependencies and the Ceres solver for the SFM module and everything seemed to have worked. Afterwards I tried compiling the example code and I get the following error:
structure.cpp:118:77: error: ‘reconstruct’ was not declared in this scope
reconstruct(points2d, Rs_est, ts_est, K, points3d_estimated, is_projective);

The full code can be found here: http://docs.opencv.org/master/d4/d18/tutorial_sfm_scene_reconstruction.html#gsc.tab=0

Im running Ubuntu 14.04.

I hope someone can help me. Thank you!

@mshabunin
Copy link
Contributor

Probably you have not provided enough dependencies for the build. This example is checked on buildbot and the build is fine. How do you build it? Please provide more details.

@Wababa
Copy link
Author

Wababa commented Dec 18, 2015

Sorry for my ignorance, but I'm pretty new at this. Here is what I've done.
Before installing OpenCV I installed the dependencies as shown here: http://docs.opencv.org/master/db/db8/tutorial_sfm_installation.html#gsc.tab=0

To install OpenCV:

  1. Download OpenCV
  2. Download OpenCV_contrib
    3.Go to OpenCV folder and create build folder.
  3. execute "cmake -D OPENCV_EXTRA_MODULES_PATH=opencv_contribpath .. " in build folder
  4. make -j4
  5. sudo make install
    Until here everything seems to be OK.

To compile the example code I did:

  1. Create a folder where I place the reconstruct.cpp with the example code.
  2. Create the following CMakeLists.txt
    cmake_minimum_required(VERSION 2.8)
    project( Reconstruct )
    find_package( OpenCV REQUIRED)
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    add_executable( Reconstruct structure.cpp )
    target_link_libraries( Reconstruct ${OpenCV_LIBS} )
  3. cmake ..
  4. make

And the error pops up. Have I done something wrong? Am I missing something?
I apreciate every help.
Thank you!

@mshabunin
Copy link
Contributor

Add message(STATUS "Found OpenCV version ${OpenCV_VERSION}") after find_package in your CMakeLists.txt

@mshabunin
Copy link
Contributor

Also, it could be better to build this example by adding -DBUILD_EXAMPLES=ON cmake option before OpenCV build. Then the example will be automatically compiled with all dependencies and put into <build-dir>/bin folder (build/bin/example_sfm_scene_reconstruction).

@Wababa
Copy link
Author

Wababa commented Dec 18, 2015

Seems that OpenCV is found, I got the following: -- Found OpenCV version 3.0.0
If I build the example like the way you say, won't I get the same error in case I write my own code using the module?

@Wababa
Copy link
Author

Wababa commented Dec 18, 2015

With the -DBUILD_EXAMPLES=ON it does work. :/

@edgarriba
Copy link
Contributor

@Wababa could you check that after installing you got the sfm module headers copied into your filesystem? This smacks to me that there's an issue in the installation part.

@manishaluthra
Copy link

@edgarriba @mshabunin I have the same problem, but mine did not go away with -DBUILD_EXAMPLES=ON flag. Indeed the sfm module headers are there in my filesystem, so i do not get errors including the headers and the namespace cv::sfm. But only on reconstruct method :| thats strange! I can call other methods of sfm including homogeneousToEuclidean but not reconstruct. Though i get the executable of the example (sfm_scene_recontruction) in bin directory successfully, as the build was successful.

@Debize
Copy link

Debize commented Jan 11, 2016

I have exactly the same issue as @Wababa, cv::sfm::reconstruct() is not recognized.
The strange thing is that others functions of the cv::sfm namespace are well recognised (cv::sfm::projectionFromKRt() for exemple).

I have:

  • /usr/locate/include/opencv2/sfm/
    • conditioning.hpp
    • fundamental.hpp
    • numeric.hpp
    • projection.hpp
    • reconstruct.hpp
    • robust.hpp
    • simple_pipeline.hpp
    • triangulation.hpp

I don't really know what to do.
Thank you for your help!

Edit: $ ./example_sfm_scene_reconstruction works for me... So, there is something different between the compilation of my example and the OpenCV one, but what?

@Wababa
Copy link
Author

Wababa commented Jan 11, 2016

@manishaluthra Actually It didn't work with the DBUILD_EXAMPLES=ON, sorry for expressing myself wrong. I meant that the compiled example worked. @edgarriba I have the same headers as @Debize.

@edgarriba
Copy link
Contributor

hey wait, do you guys have Ceres installed? For reconstruction and build samples is needed.

There's a note explaining that plus a tutorial about Ceres installation:
http://docs.opencv.org/master/d7/de2/group__simple__pipeline.html#gsc.tab=0
http://docs.opencv.org/master/db/db8/tutorial_sfm_installation.html#gsc.tab=0

Check as well that in case you don't have Ceres then examples are not built:
https://github.com/Itseez/opencv_contrib/blob/master/modules/sfm/CMakeLists.txt#L130

@manishaluthra
Copy link

yes i have the same issue too @Debize, i have the sfm module headers as well in /usr/local/include/opencv2/sfm including reconstruct.hpp. example_sfm_scene_reconstruction works for me too, there indeed are some differences in compilation of example. Just when I write my own example, cv::sfm::reconstruct() do not get recognized. @edgarriba i did install Ceres, here are the libraries installed in my file system: /usr/local/include/ceres.

I wonder how to solve this.
It would be great if someone could help. Thanks!

@leetenthu
Copy link

Hello all, I have the same issue. Any suggestion would be great!

@BorgesJVT
Copy link

Hey guys! I had these same problems. I knew that i had installed ceres and it was visible, so i just opened the files 'reconstruct.hpp' and 'sfm.hpp' and commented the directive 'if CERES NOT FOUND'.
After that, i could compile and run the sfm samples.

PS: Virtual machine may cause some problems.

@raderic raderic mentioned this issue Mar 3, 2016
@jiaojingguoguo
Copy link

@BorgesJVT very good! 你说的对!

@ntthuy11
Copy link

@BorgesJVT I had the same issue. Thanks a lot for that. I commented 'if CERES NOT FOUND' and the code could be built, but no Visualization view was showed after executing this command:

./example_sfm_scene_reconstruction image_paths_file.txt 350 240 360

I wonder if you had the point cloud as in here: https://github.com/Itseez/opencv_contrib/tree/master/modules/sfm
I guess the issue was from Ceres Solver, but I don't know how to fix it.

I really appreciate your help.

@ntthuy11
Copy link

This command:

./example_sfm_trajectory_reconstruction tracks_file.txt 1914 640 360

worked well for me (display as same as in https://github.com/Itseez/opencv_contrib/tree/master/modules/sfm). It means that I had no problem with building OpenCV 3.1 + opencv_contrib (with VTK, opencv_viz). Ceres did not show anything wrong.

@BorgesJVT
Copy link

Hi @ntthuy11 I have the same configuration (opencv + ceres) in two virtual machines. In both machines i can compile and execute all sample files, but one of the machines i have the same issue (i can't visualize too). I suppose that it could be some graphical issue, perhaps because of virtual machine or visual graphics limitation. Try use another machine configuration!

@ntthuy11
Copy link

ntthuy11 commented Apr 4, 2016

Hi @BorgesJVT. Thank you very much. I tried to clean everything and install again but I still had the same problem with visualization. But it is fine, as long as the recontruct() function works.

@alibatiste
Copy link

Hello,
I have the same problem with reconstruct "not found". It's like it can't find Ceres. The example has compile correctly. But i can't find the source of example. Do i need to add option to build with Ceres?
I'm a little lost with this library...

@miguelriemoliveira
Copy link

Hello,

I had the same problem: I can run the example from opencv, but cannot compile and link my own code. Compiler says reconstruct is undefined. Following the answer from @BorgesJVT I propose an alternative procedure:

I added in my code

#define CERES_FOUND true

This line must be before the include instructions to the sfm modules, e.g.,

#include <opencv2/sfm.hpp>
#include <opencv2/viz.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/core.hpp> 

An it now compiles. In my opinion, its better than changing the source code from opencv_contrib.

Of course this assumes that you do have CERES installed, but I think that if it is not installed a linking error should appear.

I have also have the problem of not seeing anything in the visualizer ...

@BorgesJVT
Copy link

I agree with @miguelriemoliveira. It's better than change the source code.

@miguelriemoliveira
Copy link

miguelriemoliveira commented May 3, 2016

@gunshi, why don't you do as I suggested above? As a matter of fact, you could also use @BorgesJVT suggestion as well.

@gunshi
Copy link
Contributor

gunshi commented May 3, 2016

Hi, I was able to resolve the error, which was due to a version mismatch between eigen and ceres, as described in the config cmake file for ceres, and that was quietly setting both the ceres_found flags to false, despite ceres being installed.
Now I don't have the errors reported here at all, except that there is no visualisation.

@miguelriemoliveira
Copy link

Hi @gunshi could you explain how you solved it?

@gunshi
Copy link
Contributor

gunshi commented May 4, 2016

I changed find_package(CERES QUIET) to find_package(CERES REQUIRED), and thus got an error during cmake, which gave a message about eigen version being 3.2.8 and the requested eigen version for ceres being 3.2.7 (as listed in the cmake config file for ceres under /usr/local/share/Ceres).
Ceres reuqests the exact eigen version and not just any version greater than the requested one.
So I downgraded from eigen 3.2.8 to 3.2.7, and then the problem was resolved.

@botverse
Copy link

Hi, I was having the same problems for compiling and the trick was to use eigen 3.2.7 as mentioned by @gunshi. I also needed the #define CERES_FOUND true directive at the top of the example.

To see the visualisation, I added waitKey(0); just below window.spin().

waitKey is in the "opencv/highgui.hpp" header.

@miguelriemoliveira
Copy link

Hi @botverse if you are using the "#define CERES_FOUND true directive at the top of the example" I do not think you need to bother about downgrading Eigen.

Thanks for the waitkey(0) tip, I will try it.

@gunshi
Copy link
Contributor

gunshi commented May 10, 2016

waitkey(0) didn't work for me, unfortunately.
Is there an alternate way to visualise that anyone would recommend?
I was thinking of reading points into PCL's data structure and then saving as a .ply file.

@soheilard
Copy link

I could also run sfm sample but I have problem with visualizing! actually no visualization!! I tried waitkey() as well but it doesn work...help please..

@snakehaihai
Copy link

snakehaihai commented Jul 26, 2016

I`m also using my own project cmake file
cmake_minimum_required(VERSION 2.8)
project( test )

find_package(Ceres QUIET)
find_package( OpenCV 3.0 REQUIRED )
find_package(Eigen3 REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
include_directories(${EIGEN3_INCLUDE_DIR})

file(GLOB test_project
"src/.h"
"src/
.cpp"
)
add_executable( test_project ${test_project } )
target_link_libraries( test_project ${OpenCV_LIBS} ${EIGEN3_LIBS})

by using cmake .. and make. I end up haveing the same error as yours.

Problem is that if you have multiple version of opencv eg one at /opt/ros/indigoXXXXXXXXXX another is at /usr local it will automatically lock in ros one.
if you use auto config, only first 4 will be filled in leave the other 2 open. which also wont work.

I solve the problem by link manually, there are 6 tab in the opencv group that you need to fill in
/usr/local/share/OpenCV/3rdparty/lib
/usr/local/share/OpenCV/3rdparty/lib
/usr/local/share/OpenCV
/usr/local/share/OpenCV
/usr/local/lib
/usr/local/lib

Then it works for me. You might want to give it a try.
also when you building sfm in opencv, you need to take care about the cmake warning, it will tells you whether sfm is built or not. Early game, i had mismatch of solver and eigen verion as well which simliar to what @gunshi said

@Wababa

@bcWorkAccount
Copy link

Hi, I was having the same problems for compiling,I do
#define CERES_FOUND true at the top of the example
find_package(OpenCV 3.3.1 REQUIRED) at cmake file
it works for me.

@lucasjinreal
Copy link

lucasjinreal commented Dec 5, 2017

I think uncomment the sfm.hpp and reconstruct #if CERES_FOUND is not a good idea, I got this error:

Users/jintian/opencv/opencv_contrib/modules/sfm/src/reconstruct.cpp:131:9: error: no matching
      function for call to 'reconstruct'
        reconstruct(points2d, Rs, Ts, Ka, points3d, is_projective);

Anyone have suggestions? To be more clear, those file are being commented:

  • sfm.hpp
  • src/reconstruct.cc
  • include/reconstruct.hpp

but it still gets some error as above.

@lucasjinreal
Copy link

lucasjinreal commented Dec 5, 2017

Ok, things not simple as I know, I succeed build the sfm module by uncomment both CERES and DOXYGEN, I can load reconstruct now, but when I build my program, it says:

/usr/local/include/opencv2/core/traits.hpp:366:31: error: no member named 'type' in
      'cv::DataType<std::__1::basic_string<char> >'
{ enum { value = DataType<T>::type }; };
                 ~~~~~~~~~~~~~^
/usr/local/include/opencv2/core/mat.inl.hpp:85:42: note: in instantiation of template class
      'cv::traits::Type<std::__1::basic_string<char> >' requested here
{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
                                         ^
/Volumes/xs/CodeSpace/CppSpace/reconstructor/main.cpp:81:30: note: in instantiation of function
      template specialization 'cv::_InputArray::_InputArray<std::__1::basic_string<char> >'
      requested here
        cv::sfm::reconstruct(sequence_files, Rs_est, ts_est, K, points3d_estimated, is_p...
                             ^
In file included from /Volumes/xs/CodeSpace/CppSpace/reconstructor/main.cpp:28:
In file included from /usr/local/include/opencv/cv.hpp:50:
In file included from /usr/local/include/opencv/cv.h:63:
In file included from /usr/local/include/opencv2/core/core_c.h:48:
In file included from /usr/local/include/opencv2/core/types_c.h:101:
In file included from /usr/local/include/opencv2/core.hpp:59:
In file included from /usr/local/include/opencv2/core/mat.hpp:3642:
/usr/local/include/opencv2/core/mat.inl.hpp:85:51: error: incomplete definition of type
      'cv::traits::Type<std::__1::basic_string<char> >'
{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
                                 ~~~~~~~~~~~~~~~~~^~
/Volumes/xs/CodeSpace/CppSpace/reconstructor/main.cpp:81:30: note: in instantiation of function
      template specialization 'cv::_InputArray::_InputArray<std::__1::basic_string<char> >'
      requested here
        cv::sfm::reconstruct(sequence_files, Rs_est, ts_est, K, points3d_estimated, is_p...
                             ^
1 warning and 2 errors generated.

Compeletely have now idea what is going on??

@alalek
Copy link
Member

alalek commented Dec 5, 2017

/Volumes/xs/CodeSpace/CppSpace/reconstructor/main.cpp

This code tries to work with cv::Mat with std::string elements. This is not supported and forbidden.

@lucasjinreal
Copy link

@alalek I am just token the tutorial code from https://docs.opencv.org/3.1.0/d4/d18/tutorial_sfm_scene_reconstruction.html , and I am just using the original usage of sfm::recontrcut:

vector<Mat> Rs_est, ts_est, points3d_estimated;
  reconstruct(images_paths, Rs_est, ts_est, K, points3d_estimated, is_projective);

I think there is nothing to do with your addressed issue.

@alalek
Copy link
Member

alalek commented Dec 9, 2017

@jinfagang You should open a new issue about invalid types in sfm samples. It is not related to original issue.

@samhartlebury
Copy link

I know this is an old post now, but for anybody else who is trying to build the extra opencv modules from source (on windows); I found that if you use cmake to build and install Ceres-solver from source, it doesnt install correctly. You need to make sure you have gflags and glog build from Visual Studio, then build Ceres in debug mode, the release mode, in Visual Studio. THEN build the "INSTALL" project in release and it should install correctly.

Make sure to close cmake and re-open then when you configure opencv it "should" pick up the new install location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests