Files
DLSiteFSearch/DLSiteFSearchObsidian/Notes on python-orb-slam3.md
2025-04-05 17:08:03 +02:00

2.7 KiB

There is a unofficial binding from GitHub that allows ORB-SLAM3 ORB algorithm to be used in Python3. But the ORB algorithm is the only thing available in it, there is no SLAM functionality, which is already enough for our reverse-search purposes.

What baffles me is the integration between Python <--> C++, I know it is possible to incorporate C++ code in Python, I haven't looked into it, but I do know it is possible. But the problem lies in the fact that ORB_SLAM3 also uses OpenCV, and if I install OpenCV on Python, how on earth is Python able to receive cv.KeyPoint, List cv.Mat? So after digging a little bit, the integration here works entirely different from imsearch. For returning results, the C++ code will actually construct a new Python Object of cv.KeyPoint or Lists of cv.Mat, and in the wrapper code, it will automatically populate the created object in Python with results obtained from earlier C++ code. Which is kind of fascinating. It also requires NumPy for conversion somewhere in the process. The binding is generated using pybind11.

Also, this is available already compiled on PyPi, which you can already download the compiled ORB_SLAM3 module, and it is readily usable. In the Python Wheel (which is basically an archive file), contains the Python code, and also the DLL module used by Python (it's in .pyd format, which is just OpenCV + ORB_SLAM3 compiled on x64 arch).

Be careful if you decide to build it on your own: install pipx and pdm, also Visual Studio with C++ development tools to download the compiler. You will also need the OpenCV binary from the official OpenCV site, it won't include GPU acceleration so you will have to compile that yourself. After downloading the OpenCV files, extracted, you must locate where the .cmake file is, and note that path down. pdm build -v will actually build the wheel for Python, but you have to set OpenCV_DIR in environment variables to point that directory with .cmake files. Then the pdm will start configuring the wheel with Cmake, generating a VS Project file, compiling, and there is your Python Wheel. After installing the wheel, YOU MUST MANUALLY COPY A DLL FILE opencv_world4110.dll FOR EXAMPLE TO WHERE THE Site-Packages IS. The OpenCV World DLL should be placed next to the python-orb-slam3-py313-x64 whatever.PYD file. Otherwise if you import it in Python it will complain about not finding an DLL (that DLL is OpenCV). When the wheel was built, it was dynamically linked to OpenCV, not statically linked, so you have to manually copy that file.

Also the PyPi doesn't include binaries for Python 3.13 yet.

Test results are available in the Python Notebook file.