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

ch8 opencv 3.2.0 parallel_for_ doesn't support std::bind function #32

Closed
rancheng opened this issue Oct 18, 2019 · 4 comments
Closed

ch8 opencv 3.2.0 parallel_for_ doesn't support std::bind function #32

rancheng opened this issue Oct 18, 2019 · 4 comments

Comments

@rancheng
Copy link

compiling error looks like this:

/home/ran/Documents/Playground/slambook2/ch8/direct_method.cpp: In function ‘void DirectPoseEstimationSingleLayer(const cv::Mat&, const cv::Mat&, const VecVector2d&, std::vector<double, std::allocator<double> >, Sophus::SE3d&)’:
/home/ran/Documents/Playground/slambook2/ch8/direct_method.cpp:172:36: error: invalid initialization of reference of type ‘const cv::ParallelLoopBody&’ from expression of type ‘std::_Bind_helper<false, void (JacobianAccumulator::*)(const cv::Range&), JacobianAccumulator*, const std::_Placeholder<1>&>::type {aka std::_Bind<void (JacobianAccumulator::*(JacobianAccumulator*, std::_Placeholder<1>))(const cv::Range&)>}’
                           std::bind(&JacobianAccumulator::accumulate_jacobian, &jaco_accu, std::placeholders::_1));
                           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/opencv2/core.hpp:3216:0,
                 from /usr/include/opencv2/opencv.hpp:52,
                 from /home/ran/Documents/Playground/slambook2/ch8/direct_method.cpp:1:
/usr/include/opencv2/core/utility.hpp:478:17: note: in passing argument 2 of ‘void cv::parallel_for_(const cv::Range&, const cv::ParallelLoopBody&, double)’
 CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);

go to opencv utility.hpp and found that the definition of parallel_for_ is like this:

CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);

so, we have to modify the class JacobianAccumulator, extend it from cv::ParallelLoopBody and change accumulate_jacobian function to it's operator override: virtual void operator()(const cv::Range& range) const

I have updated the source in my folk, you can download from here

@rancheng
Copy link
Author

and if you are using CLion, please note that the source file's data reference was in current directory like this:

string left_file = "./left.png";
string disparity_file = "./disparity.png";

this is dirty, please make sure you parameterize your file path, since the executive file will be compiled in cmake-build-debug directory

@rancheng
Copy link
Author

The experiments are conducted in 4 scales:
1s
2s
3s
4s

@gaoxiang12
Copy link
Owner

Thanks for commit. Looks like since opencv 4 the parallel_for_ has an overloaded form that supports std::function as the second input param: here.
For the second comment, I agree with that using params or gflags would be more elegant, but it's ok to use simple global variables in small demos like this one.

@rancheng
Copy link
Author

Thanks for your kind reply, I really appreciate your contributions!
Just ignore my jibber jabber on the second comment, yes, I compiled opencv4 and tested your code last night, that passed.
I'll close this issue, since the problem was solved, again, thanks for your great work on SLAMBOOK!

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

No branches or pull requests

2 participants