diff options
Diffstat (limited to 'pkgs/development/python-modules/opensfm')
5 files changed, 472 insertions, 0 deletions
diff --git a/pkgs/development/python-modules/opensfm/0002-cmake-find-system-distributed-gtest.patch b/pkgs/development/python-modules/opensfm/0002-cmake-find-system-distributed-gtest.patch new file mode 100644 index 0000000000000..27b87c0b2d099 --- /dev/null +++ b/pkgs/development/python-modules/opensfm/0002-cmake-find-system-distributed-gtest.patch @@ -0,0 +1,57 @@ +From 79577371be21df40f1f6d4a4fe3453be6df9e93c Mon Sep 17 00:00:00 2001 +From: Someone Serge <sergei.kozlukov@aalto.fi> +Date: Fri, 31 Dec 2021 10:03:25 +0200 +Subject: [PATCH 2/4] cmake: find system-distributed gtest + +--- + opensfm/src/CMakeLists.txt | 19 +++++++------------ + 1 file changed, 7 insertions(+), 12 deletions(-) + +diff --git a/opensfm/src/CMakeLists.txt b/opensfm/src/CMakeLists.txt +index c85aa6fb..640d47a6 100644 +--- a/opensfm/src/CMakeLists.txt ++++ b/opensfm/src/CMakeLists.txt +@@ -52,12 +52,14 @@ if (OPENMP_FOUND) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + endif() + ++find_package(gflags REQUIRED) ++ + find_package(LAPACK) + find_package(SuiteSparse) + find_package(Eigen3 REQUIRED) + find_package(Ceres) +-find_package(Gflags REQUIRED) +-find_package(Glog REQUIRED) ++find_package(glog REQUIRED) ++find_package(GTest REQUIRED) + + # Ceres2 exposes Ceres::ceres target. + # Ceres1 exposes just ceres. +@@ -100,20 +102,13 @@ option(OPENSFM_BUILD_TESTS "Build OpenSfM unit tests." on) + + if (OPENSFM_BUILD_TESTS) + enable_testing() +- include_directories(third_party/gtest) +- add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) +- +- add_library(gtest +- third_party/gtest/gmock_gtest_all.cc +- third_party/gtest/gmock_main.cc) +- target_include_directories(gtest PRIVATE ${GFLAGS_INCLUDE_DIR}) + + set(TEST_MAIN test_main) + add_library(${TEST_MAIN} testing_main.cc) + target_link_libraries(${TEST_MAIN} +- ${GFLAGS_LIBRARY} +- ${GLOG_LIBRARY} +- gtest) ++ gflags ++ glog::glog ++ GTest::gtest) + endif() + + ####### OpenSfM libraries ####### +-- +2.33.1 + diff --git a/pkgs/development/python-modules/opensfm/0003-cmake-use-system-pybind11.patch b/pkgs/development/python-modules/opensfm/0003-cmake-use-system-pybind11.patch new file mode 100644 index 0000000000000..2815886e7e18d --- /dev/null +++ b/pkgs/development/python-modules/opensfm/0003-cmake-use-system-pybind11.patch @@ -0,0 +1,161 @@ +From 36820fbab1abeeebd99f14e368093e0e3f934ca7 Mon Sep 17 00:00:00 2001 +From: Someone Serge <sergei.kozlukov@aalto.fi> +Date: Sat, 19 Feb 2022 02:37:54 +0200 +Subject: [PATCH 3/4] cmake: use system pybind11 + +--- + opensfm/src/CMakeLists.txt | 3 ++- + opensfm/src/bundle/CMakeLists.txt | 2 +- + opensfm/src/dense/CMakeLists.txt | 2 +- + opensfm/src/features/CMakeLists.txt | 1 - + opensfm/src/foundation/CMakeLists.txt | 1 - + opensfm/src/geo/CMakeLists.txt | 1 - + opensfm/src/geometry/CMakeLists.txt | 1 - + opensfm/src/map/CMakeLists.txt | 3 +-- + opensfm/src/robust/CMakeLists.txt | 1 - + opensfm/src/sfm/CMakeLists.txt | 1 - + 10 files changed, 5 insertions(+), 11 deletions(-) + +diff --git a/opensfm/src/CMakeLists.txt b/opensfm/src/CMakeLists.txt +index 640d47a6..6e391ffa 100644 +--- a/opensfm/src/CMakeLists.txt ++++ b/opensfm/src/CMakeLists.txt +@@ -54,6 +54,8 @@ endif() + + find_package(gflags REQUIRED) + ++find_package(pybind11 REQUIRED) ++ + find_package(LAPACK) + find_package(SuiteSparse) + find_package(Eigen3 REQUIRED) +@@ -82,7 +84,6 @@ else() + endif() + + ####### Third party libraries ####### +-add_subdirectory(third_party/pybind11) + add_subdirectory(third_party/akaze) + add_subdirectory(third_party/vlfeat) + +diff --git a/opensfm/src/bundle/CMakeLists.txt b/opensfm/src/bundle/CMakeLists.txt +index 7cd9cf74..307e963a 100644 +--- a/opensfm/src/bundle/CMakeLists.txt ++++ b/opensfm/src/bundle/CMakeLists.txt +@@ -52,7 +52,7 @@ target_link_libraries(pybundle PRIVATE + bundle + geometry + foundation +- pybind11) ++) + set_target_properties(pybundle PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.." + ) +diff --git a/opensfm/src/dense/CMakeLists.txt b/opensfm/src/dense/CMakeLists.txt +index cbebb5ea..2728749d 100644 +--- a/opensfm/src/dense/CMakeLists.txt ++++ b/opensfm/src/dense/CMakeLists.txt +@@ -23,7 +23,7 @@ endif() + + pybind11_add_module(pydense python/pybind.cc) + target_include_directories(pydense PRIVATE ${GLOG_INCLUDE_DIR}) +-target_link_libraries(pydense PRIVATE dense foundation pybind11) ++target_link_libraries(pydense PRIVATE dense foundation) + set_target_properties(pydense PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.." + ) +diff --git a/opensfm/src/features/CMakeLists.txt b/opensfm/src/features/CMakeLists.txt +index b131d30a..6db5b3f1 100644 +--- a/opensfm/src/features/CMakeLists.txt ++++ b/opensfm/src/features/CMakeLists.txt +@@ -22,7 +22,6 @@ target_link_libraries(pyfeatures + PRIVATE + features + foundation +- pybind11 + akaze + ) + set_target_properties(pyfeatures PROPERTIES +diff --git a/opensfm/src/foundation/CMakeLists.txt b/opensfm/src/foundation/CMakeLists.txt +index 40185227..9e0e45e7 100644 +--- a/opensfm/src/foundation/CMakeLists.txt ++++ b/opensfm/src/foundation/CMakeLists.txt +@@ -12,7 +12,6 @@ set(FOUNDATION_FILES + add_library(foundation ${FOUNDATION_FILES}) + target_link_libraries(foundation + PUBLIC +- pybind11 + ${OpenCV_LIBS} + ${OpenMP_libomp_LIBRARY} + Eigen3::Eigen +diff --git a/opensfm/src/geo/CMakeLists.txt b/opensfm/src/geo/CMakeLists.txt +index a9cbae02..75620d06 100644 +--- a/opensfm/src/geo/CMakeLists.txt ++++ b/opensfm/src/geo/CMakeLists.txt +@@ -29,7 +29,6 @@ target_link_libraries(pygeo + PRIVATE + geo + foundation +- pybind11 + ) + set_target_properties(pygeo PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.." +diff --git a/opensfm/src/geometry/CMakeLists.txt b/opensfm/src/geometry/CMakeLists.txt +index e6dda2c2..51bfd6c5 100644 +--- a/opensfm/src/geometry/CMakeLists.txt ++++ b/opensfm/src/geometry/CMakeLists.txt +@@ -48,7 +48,6 @@ target_link_libraries(pygeometry + PRIVATE + geometry + foundation +- pybind11 + ) + set_target_properties(pygeometry PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.." +diff --git a/opensfm/src/map/CMakeLists.txt b/opensfm/src/map/CMakeLists.txt +index b6f67bcd..f869aa4c 100644 +--- a/opensfm/src/map/CMakeLists.txt ++++ b/opensfm/src/map/CMakeLists.txt +@@ -20,7 +20,7 @@ set(MAP_FILES + add_library(map ${MAP_FILES}) + target_link_libraries(map + PUBLIC +- pybind11 ++ pybind11::module + Eigen3::Eigen + PRIVATE + geo +@@ -39,7 +39,6 @@ target_link_libraries(pymap + map + geometry + bundle +- pybind11 + ) + + if (OPENSFM_BUILD_TESTS) +diff --git a/opensfm/src/robust/CMakeLists.txt b/opensfm/src/robust/CMakeLists.txt +index ce70749f..40bdf7a4 100644 +--- a/opensfm/src/robust/CMakeLists.txt ++++ b/opensfm/src/robust/CMakeLists.txt +@@ -29,7 +29,6 @@ target_link_libraries(pyrobust + PRIVATE + robust + foundation +- pybind11 + ) + set_target_properties(pyrobust PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.." +diff --git a/opensfm/src/sfm/CMakeLists.txt b/opensfm/src/sfm/CMakeLists.txt +index 98c28f41..7f56b791 100644 +--- a/opensfm/src/sfm/CMakeLists.txt ++++ b/opensfm/src/sfm/CMakeLists.txt +@@ -35,7 +35,6 @@ target_include_directories(pysfm PRIVATE ${GLOG_INCLUDE_DIR}) + target_link_libraries(pysfm + PRIVATE + foundation +- pybind11 + sfm + ) + set_target_properties(pysfm PROPERTIES +-- +2.33.1 + diff --git a/pkgs/development/python-modules/opensfm/0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch b/pkgs/development/python-modules/opensfm/0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch new file mode 100644 index 0000000000000..f3cb2db00ecbc --- /dev/null +++ b/pkgs/development/python-modules/opensfm/0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch @@ -0,0 +1,86 @@ +From c35b110a83286e7413d7309eb218eb43b52f7d48 Mon Sep 17 00:00:00 2001 +From: Someone Serge <sergei.kozlukov@aalto.fi> +Date: Sat, 19 Feb 2022 14:36:12 +0200 +Subject: [PATCH 4/4] pybind_utils.h: conflicts with nixpkgs' pybind + +--- + opensfm/src/map/pybind_utils.h | 45 +++------------------------------- + 1 file changed, 3 insertions(+), 42 deletions(-) + +diff --git a/opensfm/src/map/pybind_utils.h b/opensfm/src/map/pybind_utils.h +index 817d1a16..3f98a2ab 100644 +--- a/opensfm/src/map/pybind_utils.h ++++ b/opensfm/src/map/pybind_utils.h +@@ -52,38 +52,6 @@ struct sfm_iterator_state { + }; + PYBIND11_NAMESPACE_END_(detail) + +-/// Makes an python iterator over the keys (`.first`) of a iterator over pairs +-/// from a first and past-the-end InputIterator. +-template <return_value_policy Policy = return_value_policy::reference_internal, +- typename Iterator, typename Sentinel, +- typename KeyType = decltype((*std::declval<Iterator>()).second), +- typename... Extra> +-iterator make_value_iterator(Iterator first, Sentinel last, Extra &&... extra) { +- typedef detail::sfm_iterator_state<Iterator, Sentinel, detail::RefIterator, +- Policy> +- state; +- +- if (!detail::get_type_info(typeid(state), false)) { +- class_<state>(handle(), "iterator", pybind11::module_local()) +- .def("__iter__", [](state &s) -> state & { return s; }) +- .def("__next__", +- [](state &s) -> KeyType { +- if (!s.first_or_done) +- ++s.it; +- else +- s.first_or_done = false; +- if (s.it == s.end) { +- s.first_or_done = true; +- throw stop_iteration(); +- } +- return (*s.it).second; +- }, +- std::forward<Extra>(extra)..., Policy); +- } +- +- return cast(state{first, last, true}); +-} +- + template <return_value_policy Policy = return_value_policy::reference_internal, + typename Iterator, typename Sentinel, + typename KeyType = decltype(&((*std::declval<Iterator>()).second)), +@@ -148,12 +116,13 @@ iterator make_ref_iterator(Iterator first, Sentinel last, Extra &&... extra) { + } + + /// Makes a python iterator from a first and past-the-end C++ InputIterator. +-template <return_value_policy Policy = return_value_policy::reference_internal, ++template <typename Access, ++ return_value_policy Policy = return_value_policy::reference_internal, + typename Iterator, typename Sentinel, + typename ValueType = decltype(std::declval<Iterator>()), + typename... Extra> + iterator make_ptr_iterator(Iterator first, Sentinel last, Extra &&... extra) { +- typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state; ++ typedef detail::iterator_state<Access, Policy, Iterator, Sentinel, ValueType, Extra...> state; + + if (!detail::get_type_info(typeid(state), false)) { + class_<state>(handle(), "iterator", pybind11::module_local()) +@@ -176,14 +145,6 @@ iterator make_ptr_iterator(Iterator first, Sentinel last, Extra &&... extra) { + return cast(state{first, last, true}); + } + +-/// Makes an iterator over the keys (`.first`) of a stl map-like container +-/// supporting `std::begin()`/`std::end()` +-template <return_value_policy Policy = return_value_policy::reference_internal, +- typename Type, typename... Extra> +-iterator make_value_iterator(Type &value, Extra &&... extra) { +- return make_value_iterator<Policy>(std::begin(value), std::end(value), +- extra...); +-} + template <return_value_policy Policy = return_value_policy::reference_internal, + typename Type, typename... Extra> + iterator make_unique_ptr_value_iterator(Type &value, Extra &&... extra) { +-- +2.33.1 + diff --git a/pkgs/development/python-modules/opensfm/default.nix b/pkgs/development/python-modules/opensfm/default.nix new file mode 100644 index 0000000000000..dec998f451c1b --- /dev/null +++ b/pkgs/development/python-modules/opensfm/default.nix @@ -0,0 +1,127 @@ +{ lib +, stdenv +, buildPythonPackage +, fetchFromGitHub +, fetchpatch +, cmake +, opencv4 +, ceres-solver +, suitesparse +, metis +, eigen +, pkg-config +, pybind11 +, numpy +, pyyaml +, lapack +, gtest +, gflags +, glog +, pytestCheckHook +, networkx +, pillow +, exifread +, gpxpy +, pyproj +, python-dateutil +, joblib +, repoze_lru +, xmltodict +, cloudpickle +, scipy +, sphinx +, matplotlib +, fpdf +, +}: + +let + ceresSplit = (builtins.length ceres-solver.outputs) > 1; + ceres' = + if ceresSplit + then ceres-solver.dev + else ceres-solver; +in +buildPythonPackage rec { + pname = "OpenSfM"; + version = "0.5.2"; + + src = fetchFromGitHub { + owner = "mapillary"; + repo = pname; + rev = "79aa4bdd8bd08dc0cd9e3086d170cedb29ac9760"; + sha256 = "sha256-dHBrkYwLA1OUxUSoe7DysyeEm9Yy70tIJvAsXivdjrM="; + }; + patches = [ + (fetchpatch { + url = "https://github.com/mapillary/OpenSfM/pull/872/commits/a76671db11038f3f4dfe5b8f17582fb447ad7dd5.patch"; + sha256 = "sha256-4nizQiZIjucdydOLrETvs1xdV3qiYqAQ7x1HECKvlHs="; + }) + ./0002-cmake-find-system-distributed-gtest.patch + ./0003-cmake-use-system-pybind11.patch + ./0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch + ./fix-scripts.patch + ]; + postPatch = '' + rm opensfm/src/cmake/FindGlog.cmake + rm opensfm/src/cmake/FindGflags.cmake + + # HAHOG is the default descriptor. + # We'll test both HAHOG and SIFT because this is + # where segfaults might be introduced in future + echo 'feature_type: SIFT' >> data/berlin/config.yaml + echo 'feature_type: HAHOG' >> data/lund/config.yaml + ''; + + nativeBuildInputs = [ cmake pkg-config sphinx ]; + buildInputs = [ + ceres' + suitesparse + metis + eigen + lapack + gflags + gtest + glog + pybind11 + ]; + propagatedBuildInputs = [ + numpy + scipy + pyyaml + opencv4 + networkx + pillow + matplotlib + fpdf + exifread + gpxpy + pyproj + python-dateutil + joblib + repoze_lru + xmltodict + cloudpickle + ]; + checkInputs = [ pytestCheckHook ]; + + dontUseCmakeBuildDir = true; + cmakeFlags = [ + "-Bcmake_build" + "-Sopensfm/src" + ]; + + disabledTests = lib.optionals stdenv.isDarwin [ + "test_reconstruction_incremental" + "test_reconstruction_triangulation" + ]; + + pythonImportsCheck = [ "opensfm" ]; + + meta = { + maintainers = [ lib.maintainers.SomeoneSerge ]; + license = lib.licenses.bsd2; + description = "Open source Structure-from-Motion pipeline from Mapillary"; + homepage = "https://opensfm.org/"; + }; +} diff --git a/pkgs/development/python-modules/opensfm/fix-scripts.patch b/pkgs/development/python-modules/opensfm/fix-scripts.patch new file mode 100644 index 0000000000000..634820a327558 --- /dev/null +++ b/pkgs/development/python-modules/opensfm/fix-scripts.patch @@ -0,0 +1,41 @@ +diff --git a/bin/opensfm b/bin/opensfm +index b5ee4b15..f05c0d1c 100755 +--- a/bin/opensfm ++++ b/bin/opensfm +@@ -1,12 +1,6 @@ +-#!/bin/bash ++#!/usr/bin/env bash + set -e + + DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +-if [ -x "$(command -v python3)" ]; then +- PYTHON=python3 +-else +- PYTHON=python +-fi +- +-"$PYTHON" "$DIR"/opensfm_main.py "$@" ++exec "$DIR"/opensfm_main.py "$@" +diff --git a/bin/opensfm_main.py b/bin/opensfm_main.py +index 31249e12..cc71560c 100755 +--- a/bin/opensfm_main.py ++++ b/bin/opensfm_main.py +@@ -1,3 +1,5 @@ ++#!/usr/bin/env python ++ + import sys + from os.path import abspath, join, dirname + +diff --git a/setup.py b/setup.py +index 1120717f..438a16db 100644 +--- a/setup.py ++++ b/setup.py +@@ -71,6 +71,7 @@ setuptools.setup( + scripts=[ + "bin/opensfm_run_all", + "bin/opensfm", ++ "bin/opensfm_main.py", + ], + package_data={ + "opensfm": [ |