Hello
I am trying to use the sfm module from python3.
I can run the reconstruct example like this
./example_sfm_trajectory_reconstruction desktop_tracks.txt 1914 640 360
and I can compile a cpp file with that code as well after using the tips from #476
However, in python, when I import the cv2 module I cannot find the reconstruct method, e.g.,
import cv2
help(cv2.sfm)
displays the following stuff
Basically it seems all sfm functions are available except the sfm.reconstruct.
This is a very similar issue to #476 but the solution in that case for cpp does not work in python.
Any help would be appreciated.
Miguel
I found the answer so I will share it.
The reason is that the definition of the reconstruct function in the modules/sfm/include/opencv2/sfm/reconstruction.hpp file
is defined with the
CV_EXPORTS, e.g.,
CV_EXPORTS
void
reconstruct(InputArrayOfArrays points2d, OutputArray Ps, OutputArray points3d, InputOutputArray K,
bool is_projective = false);
and the CV_EXPORTS flag does not export python bindings, see here:
"All external functions and classes must use CV_EXPORTS, otherwise there will be linking errors on Windows. For functions/classes which you want to expose in Python, Java etc. you should use CV_EXPORTS_W instead of CV_EXPORTS, but please be careful with overloaded functions and methods, with non-standard parameter types etc."
So I changed from CV_EXPORTS to CV_EXPORTS_W, recompiled and reinstalled opencv and it works.
I do not know why the author of this code "decided" to not use the python bindings, perhaps because of some problem I will encounter further ahead ...
Could not add CV_EXPORTS_W to the overloaded reconstruct methods which had as arguments
const std::vectorstd::string images
@miguelriemoliveira - thankyou for posting those changes. Do you have any working python examples using these functions?
Hi @johncant . Sorry, I do not. Best of luck.
@miguelriemoliveira - thankyou for posting those changes. Do you have any working python examples using these functions?
Hi @miguelriemoliveira,
Thanks for sharing this post. I have used your instructions and It has run.
After running, Where can I find these functions in the HD? I want to know what are the functions I can use in python therefore the examples mentioned by @johncant would be important.
Most helpful comment
I found the answer so I will share it.
The reason is that the definition of the reconstruct function in the modules/sfm/include/opencv2/sfm/reconstruction.hpp file
is defined with the
CV_EXPORTS, e.g.,
and the CV_EXPORTS flag does not export python bindings, see here:
"All external functions and classes must use CV_EXPORTS, otherwise there will be linking errors on Windows. For functions/classes which you want to expose in Python, Java etc. you should use CV_EXPORTS_W instead of CV_EXPORTS, but please be careful with overloaded functions and methods, with non-standard parameter types etc."
So I changed from CV_EXPORTS to CV_EXPORTS_W, recompiled and reinstalled opencv and it works.
I do not know why the author of this code "decided" to not use the python bindings, perhaps because of some problem I will encounter further ahead ...
Could not add CV_EXPORTS_W to the overloaded reconstruct methods which had as arguments
const std::vectorstd::string images