From 97eecdc64e7fa197454acf9ec02aea56aadadda5 Mon Sep 17 00:00:00 2001 From: Oleksandr Slovak Date: Wed, 24 Jun 2020 16:35:54 +0200 Subject: [PATCH 1/7] Python bindings and samples using Pybind11 --- .gitignore | 5 +- CMakeLists.txt | 9 ++ README.md | 1 + pysgm/CMakeLists.txt | 16 +++ pysgm/__init__.py | 1 + pysgm/pysgm.cpp | 190 +++++++++++++++++++++++++ sample/pysgm/pysgm_test_opencv_wrap.py | 32 +++++ sample/pysgm/pysgm_test_raw.py | 31 ++++ setup.py | 15 ++ 9 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 pysgm/CMakeLists.txt create mode 100644 pysgm/__init__.py create mode 100644 pysgm/pysgm.cpp create mode 100644 sample/pysgm/pysgm_test_opencv_wrap.py create mode 100644 sample/pysgm/pysgm_test_raw.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 1f636f2..4241a9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ include/libsgm_config.h -build/ \ No newline at end of file +build/ +pysgm/*.so +*__pycache__* +pysgm.egg-info/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 80cfda9..ef6b24e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(ENABLE_ZED_DEMO "Build a Demo using ZED Camera" OFF) option(ENABLE_SAMPLES "Build samples" OFF) option(ENABLE_TESTS "Test library" OFF) option(LIBSGM_SHARED "Build a shared library" OFF) +option(BUILD_PYTHON_WRAPPER "Build pybind11 wrappers" OFF) option(BUILD_OPENCV_WRAPPER "Make library compatible with cv::Mat and cv::cuda::GpuMat of OpenCV" OFF) if(WIN32) @@ -35,6 +36,14 @@ configure_file(${PROJECT_SOURCE_DIR}/include/libsgm_config.h.in add_subdirectory(src) +if(BUILD_PYTHON_WRAPPER) + if (LIBSGM_SHARED) + add_subdirectory(pysgm) + else() + message(WARNING "Python wrappers requires LIBSGM_SHARED=ON") + endif() +endif() + if(ENABLE_SAMPLES) add_subdirectory(sample/image) add_subdirectory(sample/movie) diff --git a/README.md b/README.md index 42aab71..21ad669 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ libSGM needs CUDA (compute capabilities >= 3.5) to be installed. Moreover, to build the sample, we need the following libraries: - OpenCV 3.0 or later - CMake 3.1 or later +- Pybind11 (latest) if python bindings option is enabled ## Build Instructions ``` diff --git a/pysgm/CMakeLists.txt b/pysgm/CMakeLists.txt new file mode 100644 index 0000000..3010119 --- /dev/null +++ b/pysgm/CMakeLists.txt @@ -0,0 +1,16 @@ +find_package(pybind11 REQUIRED) + +pybind11_add_module(pysgm MODULE "pysgm.cpp") +target_include_directories(pysgm PRIVATE "${PROJECT_SOURCE_DIR}/include") +target_link_libraries(pysgm PRIVATE sgm) + +if(BUILD_OPENCV_WRAPPER) + target_link_libraries(pysgm PRIVATE ${OpenCV_LIBS}) +endif() + +set_target_properties(pysgm + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" + ) diff --git a/pysgm/__init__.py b/pysgm/__init__.py new file mode 100644 index 0000000..e4fa0f8 --- /dev/null +++ b/pysgm/__init__.py @@ -0,0 +1 @@ +from .pysgm import * diff --git a/pysgm/pysgm.cpp b/pysgm/pysgm.cpp new file mode 100644 index 0000000..6a0cd4f --- /dev/null +++ b/pysgm/pysgm.cpp @@ -0,0 +1,190 @@ +#include + +#include +#include + +#ifdef BUILD_OPENCV_WRAPPER + +#include + +namespace pybind11 { +namespace detail { +template<> +struct type_caster { + public: + PYBIND11_TYPE_CASTER(cv::Mat, _("numpy.ndarray")); + + //! 1. cast numpy.ndarray to cv::Mat + bool load(handle obj, bool) { + array b = reinterpret_borrow(obj); + buffer_info info = b.request(); + + //const int ndims = (int)info.ndim; + int nh = 1; + int nw = 1; + int nc = 1; + int ndims = info.ndim; + if (ndims == 2) { + nh = info.shape[0]; + nw = info.shape[1]; + } else if (ndims == 3) { + nh = info.shape[0]; + nw = info.shape[1]; + nc = info.shape[2]; + } else { + char msg[64]; + std::sprintf(msg, "Unsupported dim %d, only support 2d, or 3-d", ndims); + throw std::logic_error(msg); + return false; + } + + int dtype; + if (info.format == format_descriptor::format()) { + dtype = CV_8UC(nc); + } else if (info.format == format_descriptor::format()) { + dtype = CV_16UC(nc); + } else if (info.format == format_descriptor::format()) { + dtype = CV_32SC(nc); + } else if (info.format == format_descriptor::format()) { + dtype = CV_32FC(nc); + } else { + throw std::logic_error("Unsupported type, only support uchar, int32, float"); + return false; + } + + value = cv::Mat(nh, nw, dtype, info.ptr); + return true; + } + + //! 2. cast cv::Mat to numpy.ndarray + static handle cast(const cv::Mat &mat, return_value_policy, handle defval) { +// UNUSED(defval); + + + std::string format = format_descriptor::format(); + size_t elemsize = sizeof(unsigned char); + int nw = mat.cols; + int nh = mat.rows; + int nc = mat.channels(); + int depth = mat.depth(); + int type = mat.type(); + int dim = (depth == type) ? 2 : 3; + + if (depth == CV_8U) { + format = format_descriptor::format(); + elemsize = sizeof(unsigned char); + } else if (depth == CV_16U) { + format = format_descriptor::format(); + elemsize = sizeof(unsigned short); + } else if (depth == CV_16S) { + format = format_descriptor::format(); + elemsize = sizeof(short); + } else if (depth == CV_32S) { + format = format_descriptor::format(); + elemsize = sizeof(int); + } else if (depth == CV_32F) { + format = format_descriptor::format(); + elemsize = sizeof(float); + } else { + throw std::logic_error("Unsupport type!"); + } + + std::vector bufferdim; + std::vector strides; + if (dim == 2) { + bufferdim = {(size_t) nh, (size_t) nw}; + strides = {elemsize * (size_t) nw, elemsize}; + } else if (dim == 3) { + bufferdim = {(size_t) nh, (size_t) nw, (size_t) nc}; + strides = {(size_t) elemsize * nw * nc, (size_t) elemsize * nc, (size_t) elemsize}; + } + return array(buffer_info(mat.data, elemsize, format, dim, bufferdim, strides)).release(); + } +}; +} +}//! end namespace pybind11::detail + +#endif // BUILD_OPENCV_WRAPPER + + +#define RW(type_name, field_name) .def_readwrite(#field_name, &type_name::field_name) +namespace py = pybind11; + +PYBIND11_MODULE(pysgm, m) { + + py::enum_(m, "EXECUTE_INOUT") + .value("EXECUTE_INOUT_HOST2HOST", sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2HOST) + .value("EXECUTE_INOUT_HOST2CUDA", sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2CUDA) + .value("EXECUTE_INOUT_CUDA2HOST", sgm::EXECUTE_INOUT::EXECUTE_INOUT_CUDA2HOST) + .value("EXECUTE_INOUT_CUDA2CUDA", sgm::EXECUTE_INOUT::EXECUTE_INOUT_CUDA2CUDA) + ; + + py::enum_(m, "PathType") + .value("SCAN_4PATH", sgm::PathType::SCAN_4PATH) + .value("SCAN_8PATH", sgm::PathType::SCAN_8PATH) + ; + + py::class_ StereoSGM(m, "StereoSGM"); + + py::class_(StereoSGM, "Parameters") + .def(py::init(), + py::arg("P1") = 10, + py::arg("P2") = 120, + py::arg("uniqueness") = 0.95f, + py::arg("subpixel") = false, + py::arg("PathType") = sgm::PathType::SCAN_8PATH, + py::arg("min_disp") = 0, + py::arg("LR_max_diff") = 1 + ) + RW(sgm::StereoSGM::Parameters, P1) + RW(sgm::StereoSGM::Parameters, P2) + RW(sgm::StereoSGM::Parameters, uniqueness) + RW(sgm::StereoSGM::Parameters, subpixel) + RW(sgm::StereoSGM::Parameters, path_type) + RW(sgm::StereoSGM::Parameters, min_disp) + RW(sgm::StereoSGM::Parameters, LR_max_diff); + + StereoSGM + .def(py::init(), + py::arg("width") = 612, + py::arg("height") = 514, + py::arg("disparity_size") = 128, + py::arg("input_depth_bits") = 8U, + py::arg("output_depth_bits") = 8U, + py::arg("inout_type") = sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2HOST, + py::arg("param") = sgm::StereoSGM::Parameters() + ) + .def(py::init()) + .def("execute", [](sgm::StereoSGM &w, unsigned long left_pixels, unsigned long right_pixels, unsigned long dst) { + w.execute((void *)left_pixels, (void *)right_pixels, (void *)dst); + }) + .def("get_invalid_disparity", &sgm::StereoSGM::get_invalid_disparity) + ; + +#ifdef BUILD_OPENCV_WRAPPER + + py::class_ LibSGMWrapper(m, "LibSGMWrapper"); + + LibSGMWrapper + .def(py::init(), + py::arg("numDisparity") = 128, + py::arg("P1") = 10, + py::arg("P2") = 120, + py::arg("uniquenessRatio") = 0.95f, + py::arg("subpixel") = false, + py::arg("pathType") = sgm::PathType::SCAN_8PATH, + py::arg("minDisparity") = 0, + py::arg("lrMaxDiff") = 1) + .def("getInvalidDisparity", &sgm::LibSGMWrapper::getInvalidDisparity) + .def("hasSubpixel", &sgm::LibSGMWrapper::hasSubpixel) + .def("execute", [](sgm::LibSGMWrapper &w, cv::Mat &left_pixels, const cv::Mat &right_pixels) { + cv::Mat disp; + w.execute(left_pixels, right_pixels, disp); + return disp; + }); + +#endif // BUILD_OPENCV_WRAPPER + + m.def("SUBPIXEL_SCALE", []() { return sgm::StereoSGM::SUBPIXEL_SCALE; }); + m.def("SUBPIXEL_SHIFT", []() { return sgm::StereoSGM::SUBPIXEL_SHIFT; }); +} diff --git a/sample/pysgm/pysgm_test_opencv_wrap.py b/sample/pysgm/pysgm_test_opencv_wrap.py new file mode 100644 index 0000000..760d3da --- /dev/null +++ b/sample/pysgm/pysgm_test_opencv_wrap.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import sys + +import cv2 +import numpy as np + +import pysgm + +sgm_opencv_wrapper = pysgm.LibSGMWrapper( + numDisparity=int(128), P1=int(10), P2=int(120), uniquenessRatio=np.float32(0.95), + subpixel=False, pathType=pysgm.PathType.SCAN_8PATH, minDisparity=int(0), + lrMaxDiff=int(1)) + + +I1 = cv2.imread(sys.argv[1], cv2.IMREAD_GRAYSCALE) +I2 = cv2.imread(sys.argv[2], cv2.IMREAD_GRAYSCALE) + +disp = sgm_opencv_wrapper.execute(I1, I2) + +if sgm_opencv_wrapper.hasSubpixel(): + disp = disp.astype('float') / pysgm.SUBPIXEL_SCALE() + +disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) + +if sgm_opencv_wrapper.hasSubpixel(): + disp_color[disp <= sgm_opencv_wrapper.getInvalidDisparity() / pysgm.SUBPIXEL_SCALE(), :] = 0 +else: + disp_color[disp <= sgm_opencv_wrapper.getInvalidDisparity(), :] = 0 + +cv2.imshow("disp_color", disp_color) +cv2.waitKey(0) diff --git a/sample/pysgm/pysgm_test_raw.py b/sample/pysgm/pysgm_test_raw.py new file mode 100644 index 0000000..bad1aa9 --- /dev/null +++ b/sample/pysgm/pysgm_test_raw.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import sys + +import cv2 +import numpy as np + +import pysgm + +I1 = cv2.imread(sys.argv[1], cv2.IMREAD_GRAYSCALE) +I2 = cv2.imread(sys.argv[2], cv2.IMREAD_GRAYSCALE) + +disp = np.zeros_like(I2) + +I1_ptr, _ = I1.__array_interface__['data'] +I2_ptr, _ = I2.__array_interface__['data'] +disp_ptr, _ = disp.__array_interface__['data'] + +params = pysgm.StereoSGM.Parameters(P1=int(10), P2=int(120), uniqueness=np.float32(0.95), subpixel=False, + PathType=pysgm.PathType.SCAN_8PATH, min_disp=int(0), LR_max_diff=int(1)) + +sgm = pysgm.StereoSGM(width=int(612), height=int(514), disparity_size=int(128), input_depth_bits=int(8), + output_depth_bits=int(8), inout_type=pysgm.EXECUTE_INOUT.EXECUTE_INOUT_HOST2HOST, + param=params) + +sgm.execute(I1_ptr, I2_ptr, disp_ptr) + +disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) + +cv2.imshow("disp_color", disp_color) +cv2.waitKey(0) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5992ae8 --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + +setup( + name='pysgm', + version='0.1.0', + description='Python pybind11 wrappers for the libSGM', + long_description="", + author='Oleksandr Slovak', + author_email='slovak194@gmail.com', + url="https://github.com/fixstars/libSGM", + license="Apache License Version 2.0, January 2004 http://www.apache.org/licenses/", + packages=find_packages(exclude=('tests', 'docs')), + package_data={}, + scripts=[] +) From a34cc5b13a6043cef712a428377f9e7c05a9e8aa Mon Sep 17 00:00:00 2001 From: Oleksandr Slovak Date: Fri, 17 Jul 2020 21:41:34 +0200 Subject: [PATCH 2/7] unsigned long to uintptr_t to support 32bit archs --- pysgm/pysgm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysgm/pysgm.cpp b/pysgm/pysgm.cpp index 6a0cd4f..4396700 100644 --- a/pysgm/pysgm.cpp +++ b/pysgm/pysgm.cpp @@ -155,7 +155,7 @@ PYBIND11_MODULE(pysgm, m) { py::arg("param") = sgm::StereoSGM::Parameters() ) .def(py::init()) - .def("execute", [](sgm::StereoSGM &w, unsigned long left_pixels, unsigned long right_pixels, unsigned long dst) { + .def("execute", [](sgm::StereoSGM &w, uintptr_t left_pixels, uintptr_t right_pixels, uintptr_t dst) { w.execute((void *)left_pixels, (void *)right_pixels, (void *)dst); }) .def("get_invalid_disparity", &sgm::StereoSGM::get_invalid_disparity) From 7d3bafc0f341d7bd861e9b4b192a353460571f49 Mon Sep 17 00:00:00 2001 From: Oleksandr Slovak Date: Fri, 17 Jul 2020 21:42:41 +0200 Subject: [PATCH 3/7] Get image size from input. Normalize disparity. --- sample/pysgm/pysgm_test_opencv_wrap.py | 14 +++++++++----- sample/pysgm/pysgm_test_raw.py | 10 +++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sample/pysgm/pysgm_test_opencv_wrap.py b/sample/pysgm/pysgm_test_opencv_wrap.py index 760d3da..52b2ed9 100644 --- a/sample/pysgm/pysgm_test_opencv_wrap.py +++ b/sample/pysgm/pysgm_test_opencv_wrap.py @@ -7,8 +7,10 @@ import pysgm +disp_size = 128 + sgm_opencv_wrapper = pysgm.LibSGMWrapper( - numDisparity=int(128), P1=int(10), P2=int(120), uniquenessRatio=np.float32(0.95), + numDisparity=int(disp_size), P1=int(10), P2=int(120), uniquenessRatio=np.float32(0.95), subpixel=False, pathType=pysgm.PathType.SCAN_8PATH, minDisparity=int(0), lrMaxDiff=int(1)) @@ -21,12 +23,14 @@ if sgm_opencv_wrapper.hasSubpixel(): disp = disp.astype('float') / pysgm.SUBPIXEL_SCALE() -disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) - if sgm_opencv_wrapper.hasSubpixel(): - disp_color[disp <= sgm_opencv_wrapper.getInvalidDisparity() / pysgm.SUBPIXEL_SCALE(), :] = 0 + mask = disp == (sgm_opencv_wrapper.getInvalidDisparity() / pysgm.SUBPIXEL_SCALE()) else: - disp_color[disp <= sgm_opencv_wrapper.getInvalidDisparity(), :] = 0 + mask = disp == sgm_opencv_wrapper.getInvalidDisparity() + +disp = (255. * disp / disp_size) +disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) +disp_color[mask, :] = 0 cv2.imshow("disp_color", disp_color) cv2.waitKey(0) diff --git a/sample/pysgm/pysgm_test_raw.py b/sample/pysgm/pysgm_test_raw.py index bad1aa9..a61b697 100644 --- a/sample/pysgm/pysgm_test_raw.py +++ b/sample/pysgm/pysgm_test_raw.py @@ -7,6 +7,8 @@ import pysgm +disp_size = 128 + I1 = cv2.imread(sys.argv[1], cv2.IMREAD_GRAYSCALE) I2 = cv2.imread(sys.argv[2], cv2.IMREAD_GRAYSCALE) @@ -16,16 +18,22 @@ I2_ptr, _ = I2.__array_interface__['data'] disp_ptr, _ = disp.__array_interface__['data'] +height, width = I1.shape + params = pysgm.StereoSGM.Parameters(P1=int(10), P2=int(120), uniqueness=np.float32(0.95), subpixel=False, PathType=pysgm.PathType.SCAN_8PATH, min_disp=int(0), LR_max_diff=int(1)) -sgm = pysgm.StereoSGM(width=int(612), height=int(514), disparity_size=int(128), input_depth_bits=int(8), +sgm = pysgm.StereoSGM(width=width, height=height, disparity_size=int(disp_size), input_depth_bits=int(8), output_depth_bits=int(8), inout_type=pysgm.EXECUTE_INOUT.EXECUTE_INOUT_HOST2HOST, param=params) sgm.execute(I1_ptr, I2_ptr, disp_ptr) +mask = disp == np.uint8(sgm.get_invalid_disparity()) +disp = (255. * disp / disp_size) + disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) +disp_color[mask] = 0 cv2.imshow("disp_color", disp_color) cv2.waitKey(0) From 23cb18b68d70d39537e68fad0fc74ce2937576e3 Mon Sep 17 00:00:00 2001 From: Christoph Liebender Date: Thu, 21 Nov 2024 16:14:07 +0100 Subject: [PATCH 4/7] add installation target for pysgm --- .gitignore | 4 +--- pysgm/CMakeLists.txt | 13 ++++++------- pysgm/__init__.py | 1 - pysgm/pysgm.cpp | 18 ++++++++++-------- sample/pysgm/pysgm_test_raw.py | 2 +- setup.py | 15 --------------- 6 files changed, 18 insertions(+), 35 deletions(-) delete mode 100644 pysgm/__init__.py delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 4241a9a..8a6f369 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ include/libsgm_config.h build/ -pysgm/*.so -*__pycache__* -pysgm.egg-info/ +.cache diff --git a/pysgm/CMakeLists.txt b/pysgm/CMakeLists.txt index 3010119..8123fc9 100644 --- a/pysgm/CMakeLists.txt +++ b/pysgm/CMakeLists.txt @@ -1,4 +1,5 @@ -find_package(pybind11 REQUIRED) +find_package(Python COMPONENTS Development Interpreter) +find_package(pybind11 CONFIG) pybind11_add_module(pysgm MODULE "pysgm.cpp") target_include_directories(pysgm PRIVATE "${PROJECT_SOURCE_DIR}/include") @@ -8,9 +9,7 @@ if(BUILD_OPENCV_WRAPPER) target_link_libraries(pysgm PRIVATE ${OpenCV_LIBS}) endif() -set_target_properties(pysgm - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/pysgm" - ) +install( + TARGETS pysgm + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages +) diff --git a/pysgm/__init__.py b/pysgm/__init__.py deleted file mode 100644 index e4fa0f8..0000000 --- a/pysgm/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .pysgm import * diff --git a/pysgm/pysgm.cpp b/pysgm/pysgm.cpp index 4396700..06f0c41 100644 --- a/pysgm/pysgm.cpp +++ b/pysgm/pysgm.cpp @@ -112,11 +112,13 @@ namespace py = pybind11; PYBIND11_MODULE(pysgm, m) { - py::enum_(m, "EXECUTE_INOUT") - .value("EXECUTE_INOUT_HOST2HOST", sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2HOST) - .value("EXECUTE_INOUT_HOST2CUDA", sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2CUDA) - .value("EXECUTE_INOUT_CUDA2HOST", sgm::EXECUTE_INOUT::EXECUTE_INOUT_CUDA2HOST) - .value("EXECUTE_INOUT_CUDA2CUDA", sgm::EXECUTE_INOUT::EXECUTE_INOUT_CUDA2CUDA) + m.doc() = "libSGM python binding"; + + py::enum_(m, "EXECUTE_INOUT") + .value("EXECUTE_INOUT_HOST2HOST", sgm::ExecuteInOut::EXECUTE_INOUT_HOST2HOST) + .value("EXECUTE_INOUT_HOST2CUDA", sgm::ExecuteInOut::EXECUTE_INOUT_HOST2CUDA) + .value("EXECUTE_INOUT_CUDA2HOST", sgm::ExecuteInOut::EXECUTE_INOUT_CUDA2HOST) + .value("EXECUTE_INOUT_CUDA2CUDA", sgm::ExecuteInOut::EXECUTE_INOUT_CUDA2CUDA) ; py::enum_(m, "PathType") @@ -145,16 +147,16 @@ PYBIND11_MODULE(pysgm, m) { RW(sgm::StereoSGM::Parameters, LR_max_diff); StereoSGM - .def(py::init(), + .def(py::init(), py::arg("width") = 612, py::arg("height") = 514, py::arg("disparity_size") = 128, py::arg("input_depth_bits") = 8U, py::arg("output_depth_bits") = 8U, - py::arg("inout_type") = sgm::EXECUTE_INOUT::EXECUTE_INOUT_HOST2HOST, + py::arg("inout_type") = sgm::ExecuteInOut::EXECUTE_INOUT_HOST2HOST, py::arg("param") = sgm::StereoSGM::Parameters() ) - .def(py::init()) + .def(py::init()) .def("execute", [](sgm::StereoSGM &w, uintptr_t left_pixels, uintptr_t right_pixels, uintptr_t dst) { w.execute((void *)left_pixels, (void *)right_pixels, (void *)dst); }) diff --git a/sample/pysgm/pysgm_test_raw.py b/sample/pysgm/pysgm_test_raw.py index a61b697..3ffce1d 100644 --- a/sample/pysgm/pysgm_test_raw.py +++ b/sample/pysgm/pysgm_test_raw.py @@ -29,7 +29,7 @@ sgm.execute(I1_ptr, I2_ptr, disp_ptr) -mask = disp == np.uint8(sgm.get_invalid_disparity()) +mask = disp == np.int16(sgm.get_invalid_disparity()) disp = (255. * disp / disp_size) disp_color = cv2.applyColorMap(disp.astype("uint8"), cv2.COLORMAP_JET) diff --git a/setup.py b/setup.py deleted file mode 100644 index 5992ae8..0000000 --- a/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import setup, find_packages - -setup( - name='pysgm', - version='0.1.0', - description='Python pybind11 wrappers for the libSGM', - long_description="", - author='Oleksandr Slovak', - author_email='slovak194@gmail.com', - url="https://github.com/fixstars/libSGM", - license="Apache License Version 2.0, January 2004 http://www.apache.org/licenses/", - packages=find_packages(exclude=('tests', 'docs')), - package_data={}, - scripts=[] -) From ab168103d389c74727b25f58c3976cff3e06a1a8 Mon Sep 17 00:00:00 2001 From: Christoph Liebender Date: Thu, 21 Nov 2024 16:37:40 +0100 Subject: [PATCH 5/7] add pyproject.toml --- .gitignore | 1 + pyproject.toml | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 8a6f369..5ae33af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ include/libsgm_config.h build/ .cache +dist diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c1aba24 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["scikit-build-core", "pybind11"] +build-backend = "scikit_build_core.build" + +[project] +name = "pysgm" +version = "3.1.0" + +[tool.scikit-build] +cmake.args = [ + "-DLIBSGM_SHARED=ON", + "-DBUILD_PYTHON_WRAPPER=ON" +] +wheel.exclude = [ + "**/*.h", + "**/*.cmake" +] From 6d061205da81c67e43e1847dda42327910d8f3b1 Mon Sep 17 00:00:00 2001 From: Christoph Liebender Date: Thu, 21 Nov 2024 16:41:04 +0100 Subject: [PATCH 6/7] populate pyproject.toml with original author to give credit --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c1aba24..b6aa9d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,11 @@ build-backend = "scikit_build_core.build" [project] name = "pysgm" +authors = [ + {name = "Oleksandr Slovak"}, + {name = "Christoph Liebender", email = "christoph.liebender@uni-wuerzburg.de"} +] +license = {file = "LICENSE"} version = "3.1.0" [tool.scikit-build] From 00a8daec9867c51051f82e180d6a900b3351c010 Mon Sep 17 00:00:00 2001 From: Christoph Liebender Date: Fri, 22 Nov 2024 10:29:19 +0100 Subject: [PATCH 7/7] pyproject.toml: add more metadata --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b6aa9d0..786f345 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,8 +9,12 @@ authors = [ {name = "Christoph Liebender", email = "christoph.liebender@uni-wuerzburg.de"} ] license = {file = "LICENSE"} +readme = "README.md" version = "3.1.0" +[project.urls] +Repository = "https://github.com/fixstars/libSGM.git" + [tool.scikit-build] cmake.args = [ "-DLIBSGM_SHARED=ON",