I spent quite a lot of time to get it running. I am sharing here so somebody else would have less pain. Maybe copy this to the main project page later on?
I am on win 10, Intel 64bit, Nvidia GPU is available.
I recommend to use virtual environments in python!
I do not use conda.
You need:
- Visual Studio 2019 with C++ package installed. Could work with VS 2017, I did not try.
- python 3.7 (because torch 1.2.0 does not support higher version) python 3.7.9 is the last available for installation
pip install opencv-contrib-python==3.4.2.17 because opencv-python does not contain SIFT algo. old story, no solution Beware! OpenCV 4 is NOT compatible with the code. See other people here asking questions regrading wrong numpy array dimensions.
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html could also work for 1.2.0+cpu or 1.2.0. I did not try. Torch install
- download and un-pack pre-compiled opencv package from here - direct exe
- change in ngransac/setup.py file:
opencv_inc_dir = 'C:/my path to/opencv/build/include' # directory containing OpenCV header files
opencv_lib_dir = 'C:/my path to/opencv/build/x64/vc15/lib' # directory containing OpenCV library files
and also libraries=['opencv_world342'] because opencv by default is compiled as one 'world' library, not core, gui, etc...
setup(
name='ngransac',
ext_modules=[CppExtension(
name='ngransac',
sources=['ngransac.cpp','thread_rand.cpp'],
include_dirs=[opencv_inc_dir],
library_dirs=[opencv_lib_dir],
libraries=['opencv_world342'],
extra_compile_args=['-fopenmp']
)],
cmdclass={'build_ext': BuildExtension})
openmp flag will be ignored
I have used Visual Studio 2019 for compilation.
you say inside python virtual environment cd ngransac; python setup.py install
Setuptools of python by using cmake will take care of finding torch header and lib files (they are installed as part of python torch package, nothing to do extra), find available C++ compiler on your system and all default C++ environment paths as Visual Studio itself does. It should just work. In the end file similar to ngransac.cp37-win_amd64.pyd will be created and moved to Lib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg.
Almost done.
*.pyd is like a dll file. It has dependencies and you have to take care of them manually.
- copy
opencv_world342.dll from C:/my path to/opencv/build/x64/vc15/bin to Lib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg\
- copy all dlls from
Lib\site-packages\torch\lib\ to Lib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg\
Hint: use dependency walker on *.pyd file when in doubt. It will show which dll is missing.
Ready!
call import ngransac inside python. Should give no errors.
call ngransac_demo.py as a start point for investigating the project
I spent quite a lot of time to get it running. I am sharing here so somebody else would have less pain. Maybe copy this to the main project page later on?
I am on win 10, Intel 64bit, Nvidia GPU is available.
I recommend to use virtual environments in python!
I do not use conda.
You need:
pip install opencv-contrib-python==3.4.2.17because opencv-python does not contain SIFT algo. old story, no solution Beware! OpenCV 4 is NOT compatible with the code. See other people here asking questions regrading wrong numpy array dimensions.pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.htmlcould also work for1.2.0+cpuor1.2.0. I did not try. Torch installand also
libraries=['opencv_world342']because opencv by default is compiled as one 'world' library, not core, gui, etc...openmp flag will be ignored
I have used Visual Studio 2019 for compilation.
you say inside python virtual environment
cd ngransac; python setup.py installSetuptools of python by using cmake will take care of finding torch header and lib files (they are installed as part of python torch package, nothing to do extra), find available C++ compiler on your system and all default C++ environment paths as Visual Studio itself does. It should just work. In the end file similar to
ngransac.cp37-win_amd64.pydwill be created and moved toLib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg.Almost done.
*.pyd is like a dll file. It has dependencies and you have to take care of them manually.
opencv_world342.dllfromC:/my path to/opencv/build/x64/vc15/bintoLib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg\Lib\site-packages\torch\lib\toLib\site-packages\ngransac-0.0.0-py3.7-win-amd64.egg\Hint: use dependency walker on *.pyd file when in doubt. It will show which dll is missing.
Ready!
call
import ngransacinside python. Should give no errors.call
ngransac_demo.pyas a start point for investigating the project