Add CMake support and SWIG bindings for RapidPoseTriangulation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
rpt_wrap.*
|
rpt_wrap.*
|
||||||
|
rptPYTHON_wrap.*
|
||||||
rpt.py
|
rpt.py
|
||||||
*.bin
|
*.bin
|
||||||
|
|
||||||
|
|||||||
16
CMakeLists.txt
Normal file
16
CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.18)
|
||||||
|
|
||||||
|
project(RapidPoseTriangulation
|
||||||
|
VERSION 0.1.0
|
||||||
|
LANGUAGES CXX
|
||||||
|
DESCRIPTION "Rapid Pose Triangulation library with Python bindings"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Global settings
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Add the SWIG subdirectory
|
||||||
|
add_subdirectory(swig)
|
||||||
@ -32,9 +32,9 @@ RUN cat /onnxruntime/cmake/deps.txt && \
|
|||||||
ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/cmake-3.30.1-linux-x86_64/bin:${PATH}
|
ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/cmake-3.30.1-linux-x86_64/bin:${PATH}
|
||||||
ARG CMAKE_CUDA_ARCHITECTURES=75;80;90
|
ARG CMAKE_CUDA_ARCHITECTURES=75;80;90
|
||||||
ENV TRT_VERSION=10.5.0.18
|
ENV TRT_VERSION=10.5.0.18
|
||||||
RUN /bin/sh onnxruntime/dockerfiles/scripts/install_common_deps.sh
|
RUN /bin/sh onnxruntime/dockerfiles/scripts/install_common_deps.sh \
|
||||||
RUN /bin/sh onnxruntime/dockerfiles/scripts/checkout_submodules.sh ${trt_version}
|
&& /bin/sh onnxruntime/dockerfiles/scripts/checkout_submodules.sh ${trt_version}
|
||||||
RUN ls
|
|
||||||
RUN cd onnxruntime && \
|
RUN cd onnxruntime && \
|
||||||
/bin/sh build.sh --allow_running_as_root --parallel --build_shared_lib \
|
/bin/sh build.sh --allow_running_as_root --parallel --build_shared_lib \
|
||||||
--cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt \
|
--cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt \
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
|
|
||||||
@ -208,7 +209,7 @@ void CameraInternal::undistort_point_fisheye(std::array<float, 3> &p, const std:
|
|||||||
// https://github.com/opencv/opencv/blob/4.x/modules/calib3d/src/fisheye.cpp#L429
|
// https://github.com/opencv/opencv/blob/4.x/modules/calib3d/src/fisheye.cpp#L429
|
||||||
|
|
||||||
float theta_d = std::sqrt(p[0] * p[0] + p[1] * p[1]);
|
float theta_d = std::sqrt(p[0] * p[0] + p[1] * p[1]);
|
||||||
float pi_half = std::numbers::pi * 0.5;
|
float pi_half = M_PI * 0.5;
|
||||||
theta_d = std::min(std::max(-pi_half, theta_d), pi_half);
|
theta_d = std::min(std::max(-pi_half, theta_d), pi_half);
|
||||||
|
|
||||||
if (theta_d < 1e-6)
|
if (theta_d < 1e-6)
|
||||||
|
|||||||
52
swig/CMakeLists.txt
Normal file
52
swig/CMakeLists.txt
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# SWIG Python bindings for RapidPoseTriangulation
|
||||||
|
|
||||||
|
# Find required packages
|
||||||
|
find_package(SWIG REQUIRED COMPONENTS python)
|
||||||
|
find_package(Python3 REQUIRED COMPONENTS Development)
|
||||||
|
|
||||||
|
# Include SWIG macros
|
||||||
|
include(UseSWIG)
|
||||||
|
|
||||||
|
# Compiler flags (matching original Makefile)
|
||||||
|
set(RPT_COMPILE_FLAGS -fPIC -O3 -march=native -Wall -flto=auto)
|
||||||
|
|
||||||
|
# Create static library from rpt sources
|
||||||
|
set(RPT_SOURCES
|
||||||
|
${CMAKE_SOURCE_DIR}/rpt/camera.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/rpt/interface.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/rpt/triangulator.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(rpt_core STATIC ${RPT_SOURCES})
|
||||||
|
target_include_directories(rpt_core PUBLIC ${CMAKE_SOURCE_DIR}/rpt)
|
||||||
|
target_compile_options(rpt_core PRIVATE ${RPT_COMPILE_FLAGS})
|
||||||
|
|
||||||
|
# SWIG interface
|
||||||
|
set_property(SOURCE rpt.i PROPERTY CPLUSPLUS ON)
|
||||||
|
set_property(SOURCE rpt.i PROPERTY SWIG_MODULE_NAME rpt)
|
||||||
|
|
||||||
|
# Set output directory for generated files to match original Makefile behavior
|
||||||
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
swig_add_library(rpt
|
||||||
|
TYPE MODULE
|
||||||
|
LANGUAGE python
|
||||||
|
OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTFILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
SOURCES rpt.i
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link the SWIG module
|
||||||
|
target_link_libraries(rpt PRIVATE rpt_core Python3::Module)
|
||||||
|
target_compile_options(rpt PRIVATE ${RPT_COMPILE_FLAGS})
|
||||||
|
|
||||||
|
# Set the output directory
|
||||||
|
set_target_properties(rpt PROPERTIES
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure SWIG can find headers
|
||||||
|
target_include_directories(rpt PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/rpt
|
||||||
|
${Python3_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
@ -1,14 +0,0 @@
|
|||||||
# Standard compile options for the C++ executable
|
|
||||||
FLAGS = -fPIC -O3 -march=native -Wall -Werror -flto=auto
|
|
||||||
|
|
||||||
# The Python interface through SWIG
|
|
||||||
PYTHON_VERSION = $(shell python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}");')
|
|
||||||
PYTHONI = -I/usr/include/python$(PYTHON_VERSION)/
|
|
||||||
PYTHONL = -Xlinker -export-dynamic
|
|
||||||
|
|
||||||
# Default super-target
|
|
||||||
all:
|
|
||||||
cd ../rpt/ && g++ $(FLAGS) -std=c++2a -c *.cpp ; cd ../swig/
|
|
||||||
swig -c++ -python -keyword -o rpt_wrap.cxx rpt.i
|
|
||||||
g++ $(FLAGS) $(PYTHONI) -c rpt_wrap.cxx -o rpt_wrap.o
|
|
||||||
g++ $(FLAGS) $(PYTHONL) -shared ../rpt/*.o rpt_wrap.o -o _rpt.so
|
|
||||||
Reference in New Issue
Block a user