git.iko.soy/typeable/nixpkgs
on master help sign in
python39Packages.opensfm: init at 0.5.2 (#152957)

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>

commitc02944e17d0d8ea91c9dc8878dc93697f7098838 authorSerge K <newkozlukov@gmail.com> dateWed 2 Mar 2022, 13:37 (5 years ago) parentb2897c2
6 files changed+474
pkgs/development/python-modules/opensfm/0002-cmake-find-system-distributed-gtest.patch+57 pkgs/development/python-modules/opensfm/0003-cmake-use-system-pybind11.patch+161 pkgs/development/python-modules/opensfm/0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch+86 pkgs/development/python-modules/opensfm/default.nix+127 pkgs/development/python-modules/opensfm/fix-scripts.patch+41 pkgs/top-level/python-packages.nix+2
pkgs/development/python-modules/opensfm/0002-cmake-find-system-distributed-gtest.patchnew file+57
@@ -0,0 +1,57 @@
1+From 79577371be21df40f1f6d4a4fe3453be6df9e93c Mon Sep 17 00:00:00 2001
2+From: Someone Serge <sergei.kozlukov@aalto.fi>
3+Date: Fri, 31 Dec 2021 10:03:25 +0200
4+Subject: [PATCH 2/4] cmake: find system-distributed gtest
5+
6+---
7+ opensfm/src/CMakeLists.txt | 19 +++++++------------
8+ 1 file changed, 7 insertions(+), 12 deletions(-)
9+
10+diff --git a/opensfm/src/CMakeLists.txt b/opensfm/src/CMakeLists.txt
11+index c85aa6fb..640d47a6 100644
12+--- a/opensfm/src/CMakeLists.txt
13++++ b/opensfm/src/CMakeLists.txt
14+@@ -52,12 +52,14 @@ if (OPENMP_FOUND)
15+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
16+ endif()
17+
18++find_package(gflags REQUIRED)
19++
20+ find_package(LAPACK)
21+ find_package(SuiteSparse)
22+ find_package(Eigen3 REQUIRED)
23+ find_package(Ceres)
24+-find_package(Gflags REQUIRED)
25+-find_package(Glog REQUIRED)
26++find_package(glog REQUIRED)
27++find_package(GTest REQUIRED)
28+
29+ # Ceres2 exposes Ceres::ceres target.
30+ # Ceres1 exposes just ceres.
31+@@ -100,20 +102,13 @@ option(OPENSFM_BUILD_TESTS "Build OpenSfM unit tests." on)
32+
33+ if (OPENSFM_BUILD_TESTS)
34+ enable_testing()
35+- include_directories(third_party/gtest)
36+- add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
37+-
38+- add_library(gtest
39+- third_party/gtest/gmock_gtest_all.cc
40+- third_party/gtest/gmock_main.cc)
41+- target_include_directories(gtest PRIVATE ${GFLAGS_INCLUDE_DIR})
42+
43+ set(TEST_MAIN test_main)
44+ add_library(${TEST_MAIN} testing_main.cc)
45+ target_link_libraries(${TEST_MAIN}
46+- ${GFLAGS_LIBRARY}
47+- ${GLOG_LIBRARY}
48+- gtest)
49++ gflags
50++ glog::glog
51++ GTest::gtest)
52+ endif()
53+
54+ ####### OpenSfM libraries #######
55+--
56+2.33.1
57+
pkgs/development/python-modules/opensfm/0003-cmake-use-system-pybind11.patchnew file+161
@@ -0,0 +1,161 @@
1+From 36820fbab1abeeebd99f14e368093e0e3f934ca7 Mon Sep 17 00:00:00 2001
2+From: Someone Serge <sergei.kozlukov@aalto.fi>
3+Date: Sat, 19 Feb 2022 02:37:54 +0200
4+Subject: [PATCH 3/4] cmake: use system pybind11
5+
6+---
7+ opensfm/src/CMakeLists.txt | 3 ++-
8+ opensfm/src/bundle/CMakeLists.txt | 2 +-
9+ opensfm/src/dense/CMakeLists.txt | 2 +-
10+ opensfm/src/features/CMakeLists.txt | 1 -
11+ opensfm/src/foundation/CMakeLists.txt | 1 -
12+ opensfm/src/geo/CMakeLists.txt | 1 -
13+ opensfm/src/geometry/CMakeLists.txt | 1 -
14+ opensfm/src/map/CMakeLists.txt | 3 +--
15+ opensfm/src/robust/CMakeLists.txt | 1 -
16+ opensfm/src/sfm/CMakeLists.txt | 1 -
17+ 10 files changed, 5 insertions(+), 11 deletions(-)
18+
19+diff --git a/opensfm/src/CMakeLists.txt b/opensfm/src/CMakeLists.txt
20+index 640d47a6..6e391ffa 100644
21+--- a/opensfm/src/CMakeLists.txt
22++++ b/opensfm/src/CMakeLists.txt
23+@@ -54,6 +54,8 @@ endif()
24+
25+ find_package(gflags REQUIRED)
26+
27++find_package(pybind11 REQUIRED)
28++
29+ find_package(LAPACK)
30+ find_package(SuiteSparse)
31+ find_package(Eigen3 REQUIRED)
32+@@ -82,7 +84,6 @@ else()
33+ endif()
34+
35+ ####### Third party libraries #######
36+-add_subdirectory(third_party/pybind11)
37+ add_subdirectory(third_party/akaze)
38+ add_subdirectory(third_party/vlfeat)
39+
40+diff --git a/opensfm/src/bundle/CMakeLists.txt b/opensfm/src/bundle/CMakeLists.txt
41+index 7cd9cf74..307e963a 100644
42+--- a/opensfm/src/bundle/CMakeLists.txt
43++++ b/opensfm/src/bundle/CMakeLists.txt
44+@@ -52,7 +52,7 @@ target_link_libraries(pybundle PRIVATE
45+ bundle
46+ geometry
47+ foundation
48+- pybind11)
49++)
50+ set_target_properties(pybundle PROPERTIES
51+ LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
52+ )
53+diff --git a/opensfm/src/dense/CMakeLists.txt b/opensfm/src/dense/CMakeLists.txt
54+index cbebb5ea..2728749d 100644
55+--- a/opensfm/src/dense/CMakeLists.txt
56++++ b/opensfm/src/dense/CMakeLists.txt
57+@@ -23,7 +23,7 @@ endif()
58+
59+ pybind11_add_module(pydense python/pybind.cc)
60+ target_include_directories(pydense PRIVATE ${GLOG_INCLUDE_DIR})
61+-target_link_libraries(pydense PRIVATE dense foundation pybind11)
62++target_link_libraries(pydense PRIVATE dense foundation)
63+ set_target_properties(pydense PROPERTIES
64+ LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
65+ )
66+diff --git a/opensfm/src/features/CMakeLists.txt b/opensfm/src/features/CMakeLists.txt
67+index b131d30a..6db5b3f1 100644
68+--- a/opensfm/src/features/CMakeLists.txt
69++++ b/opensfm/src/features/CMakeLists.txt
70+@@ -22,7 +22,6 @@ target_link_libraries(pyfeatures
71+ PRIVATE
72+ features
73+ foundation
74+- pybind11
75+ akaze
76+ )
77+ set_target_properties(pyfeatures PROPERTIES
78+diff --git a/opensfm/src/foundation/CMakeLists.txt b/opensfm/src/foundation/CMakeLists.txt
79+index 40185227..9e0e45e7 100644
80+--- a/opensfm/src/foundation/CMakeLists.txt
81++++ b/opensfm/src/foundation/CMakeLists.txt
82+@@ -12,7 +12,6 @@ set(FOUNDATION_FILES
83+ add_library(foundation ${FOUNDATION_FILES})
84+ target_link_libraries(foundation
85+ PUBLIC
86+- pybind11
87+ ${OpenCV_LIBS}
88+ ${OpenMP_libomp_LIBRARY}
89+ Eigen3::Eigen
90+diff --git a/opensfm/src/geo/CMakeLists.txt b/opensfm/src/geo/CMakeLists.txt
91+index a9cbae02..75620d06 100644
92+--- a/opensfm/src/geo/CMakeLists.txt
93++++ b/opensfm/src/geo/CMakeLists.txt
94+@@ -29,7 +29,6 @@ target_link_libraries(pygeo
95+ PRIVATE
96+ geo
97+ foundation
98+- pybind11
99+ )
100+ set_target_properties(pygeo PROPERTIES
101+ LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
102+diff --git a/opensfm/src/geometry/CMakeLists.txt b/opensfm/src/geometry/CMakeLists.txt
103+index e6dda2c2..51bfd6c5 100644
104+--- a/opensfm/src/geometry/CMakeLists.txt
105++++ b/opensfm/src/geometry/CMakeLists.txt
106+@@ -48,7 +48,6 @@ target_link_libraries(pygeometry
107+ PRIVATE
108+ geometry
109+ foundation
110+- pybind11
111+ )
112+ set_target_properties(pygeometry PROPERTIES
113+ LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
114+diff --git a/opensfm/src/map/CMakeLists.txt b/opensfm/src/map/CMakeLists.txt
115+index b6f67bcd..f869aa4c 100644
116+--- a/opensfm/src/map/CMakeLists.txt
117++++ b/opensfm/src/map/CMakeLists.txt
118+@@ -20,7 +20,7 @@ set(MAP_FILES
119+ add_library(map ${MAP_FILES})
120+ target_link_libraries(map
121+ PUBLIC
122+- pybind11
123++ pybind11::module
124+ Eigen3::Eigen
125+ PRIVATE
126+ geo
127+@@ -39,7 +39,6 @@ target_link_libraries(pymap
128+ map
129+ geometry
130+ bundle
131+- pybind11
132+ )
133+
134+ if (OPENSFM_BUILD_TESTS)
135+diff --git a/opensfm/src/robust/CMakeLists.txt b/opensfm/src/robust/CMakeLists.txt
136+index ce70749f..40bdf7a4 100644
137+--- a/opensfm/src/robust/CMakeLists.txt
138++++ b/opensfm/src/robust/CMakeLists.txt
139+@@ -29,7 +29,6 @@ target_link_libraries(pyrobust
140+ PRIVATE
141+ robust
142+ foundation
143+- pybind11
144+ )
145+ set_target_properties(pyrobust PROPERTIES
146+ LIBRARY_OUTPUT_DIRECTORY "${opensfm_SOURCE_DIR}/.."
147+diff --git a/opensfm/src/sfm/CMakeLists.txt b/opensfm/src/sfm/CMakeLists.txt
148+index 98c28f41..7f56b791 100644
149+--- a/opensfm/src/sfm/CMakeLists.txt
150++++ b/opensfm/src/sfm/CMakeLists.txt
151+@@ -35,7 +35,6 @@ target_include_directories(pysfm PRIVATE ${GLOG_INCLUDE_DIR})
152+ target_link_libraries(pysfm
153+ PRIVATE
154+ foundation
155+- pybind11
156+ sfm
157+ )
158+ set_target_properties(pysfm PROPERTIES
159+--
160+2.33.1
161+
pkgs/development/python-modules/opensfm/0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patchnew file+86
@@ -0,0 +1,86 @@
1+From c35b110a83286e7413d7309eb218eb43b52f7d48 Mon Sep 17 00:00:00 2001
2+From: Someone Serge <sergei.kozlukov@aalto.fi>
3+Date: Sat, 19 Feb 2022 14:36:12 +0200
4+Subject: [PATCH 4/4] pybind_utils.h: conflicts with nixpkgs' pybind
5+
6+---
7+ opensfm/src/map/pybind_utils.h | 45 +++-------------------------------
8+ 1 file changed, 3 insertions(+), 42 deletions(-)
9+
10+diff --git a/opensfm/src/map/pybind_utils.h b/opensfm/src/map/pybind_utils.h
11+index 817d1a16..3f98a2ab 100644
12+--- a/opensfm/src/map/pybind_utils.h
13++++ b/opensfm/src/map/pybind_utils.h
14+@@ -52,38 +52,6 @@ struct sfm_iterator_state {
15+ };
16+ PYBIND11_NAMESPACE_END_(detail)
17+
18+-/// Makes an python iterator over the keys (`.first`) of a iterator over pairs
19+-/// from a first and past-the-end InputIterator.
20+-template <return_value_policy Policy = return_value_policy::reference_internal,
21+- typename Iterator, typename Sentinel,
22+- typename KeyType = decltype((*std::declval<Iterator>()).second),
23+- typename... Extra>
24+-iterator make_value_iterator(Iterator first, Sentinel last, Extra &&... extra) {
25+- typedef detail::sfm_iterator_state<Iterator, Sentinel, detail::RefIterator,
26+- Policy>
27+- state;
28+-
29+- if (!detail::get_type_info(typeid(state), false)) {
30+- class_<state>(handle(), "iterator", pybind11::module_local())
31+- .def("__iter__", [](state &s) -> state & { return s; })
32+- .def("__next__",
33+- [](state &s) -> KeyType {
34+- if (!s.first_or_done)
35+- ++s.it;
36+- else
37+- s.first_or_done = false;
38+- if (s.it == s.end) {
39+- s.first_or_done = true;
40+- throw stop_iteration();
41+- }
42+- return (*s.it).second;
43+- },
44+- std::forward<Extra>(extra)..., Policy);
45+- }
46+-
47+- return cast(state{first, last, true});
48+-}
49+-
50+ template <return_value_policy Policy = return_value_policy::reference_internal,
51+ typename Iterator, typename Sentinel,
52+ typename KeyType = decltype(&((*std::declval<Iterator>()).second)),
53+@@ -148,12 +116,13 @@ iterator make_ref_iterator(Iterator first, Sentinel last, Extra &&... extra) {
54+ }
55+
56+ /// Makes a python iterator from a first and past-the-end C++ InputIterator.
57+-template <return_value_policy Policy = return_value_policy::reference_internal,
58++template <typename Access,
59++ return_value_policy Policy = return_value_policy::reference_internal,
60+ typename Iterator, typename Sentinel,
61+ typename ValueType = decltype(std::declval<Iterator>()),
62+ typename... Extra>
63+ iterator make_ptr_iterator(Iterator first, Sentinel last, Extra &&... extra) {
64+- typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state;
65++ typedef detail::iterator_state<Access, Policy, Iterator, Sentinel, ValueType, Extra...> state;
66+
67+ if (!detail::get_type_info(typeid(state), false)) {
68+ class_<state>(handle(), "iterator", pybind11::module_local())
69+@@ -176,14 +145,6 @@ iterator make_ptr_iterator(Iterator first, Sentinel last, Extra &&... extra) {
70+ return cast(state{first, last, true});
71+ }
72+
73+-/// Makes an iterator over the keys (`.first`) of a stl map-like container
74+-/// supporting `std::begin()`/`std::end()`
75+-template <return_value_policy Policy = return_value_policy::reference_internal,
76+- typename Type, typename... Extra>
77+-iterator make_value_iterator(Type &value, Extra &&... extra) {
78+- return make_value_iterator<Policy>(std::begin(value), std::end(value),
79+- extra...);
80+-}
81+ template <return_value_policy Policy = return_value_policy::reference_internal,
82+ typename Type, typename... Extra>
83+ iterator make_unique_ptr_value_iterator(Type &value, Extra &&... extra) {
84+--
85+2.33.1
86+
pkgs/development/python-modules/opensfm/default.nixnew file+127
@@ -0,0 +1,127 @@
1+{ lib
2+, stdenv
3+, buildPythonPackage
4+, fetchFromGitHub
5+, fetchpatch
6+, cmake
7+, opencv4
8+, ceres-solver
9+, suitesparse
10+, metis
11+, eigen
12+, pkg-config
13+, pybind11
14+, numpy
15+, pyyaml
16+, lapack
17+, gtest
18+, gflags
19+, glog
20+, pytestCheckHook
21+, networkx
22+, pillow
23+, exifread
24+, gpxpy
25+, pyproj
26+, python-dateutil
27+, joblib
28+, repoze_lru
29+, xmltodict
30+, cloudpickle
31+, scipy
32+, sphinx
33+, matplotlib
34+, fpdf
35+,
36+}:
37+
38+let
39+ ceresSplit = (builtins.length ceres-solver.outputs) > 1;
40+ ceres' =
41+ if ceresSplit
42+ then ceres-solver.dev
43+ else ceres-solver;
44+in
45+buildPythonPackage rec {
46+ pname = "OpenSfM";
47+ version = "0.5.2";
48+
49+ src = fetchFromGitHub {
50+ owner = "mapillary";
51+ repo = pname;
52+ rev = "79aa4bdd8bd08dc0cd9e3086d170cedb29ac9760";
53+ sha256 = "sha256-dHBrkYwLA1OUxUSoe7DysyeEm9Yy70tIJvAsXivdjrM=";
54+ };
55+ patches = [
56+ (fetchpatch {
57+ url = "https://github.com/mapillary/OpenSfM/pull/872/commits/a76671db11038f3f4dfe5b8f17582fb447ad7dd5.patch";
58+ sha256 = "sha256-4nizQiZIjucdydOLrETvs1xdV3qiYqAQ7x1HECKvlHs=";
59+ })
60+ ./0002-cmake-find-system-distributed-gtest.patch
61+ ./0003-cmake-use-system-pybind11.patch
62+ ./0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch
63+ ./fix-scripts.patch
64+ ];
65+ postPatch = ''
66+ rm opensfm/src/cmake/FindGlog.cmake
67+ rm opensfm/src/cmake/FindGflags.cmake
68+
69+ # HAHOG is the default descriptor.
70+ # We'll test both HAHOG and SIFT because this is
71+ # where segfaults might be introduced in future
72+ echo 'feature_type: SIFT' >> data/berlin/config.yaml
73+ echo 'feature_type: HAHOG' >> data/lund/config.yaml
74+ '';
75+
76+ nativeBuildInputs = [ cmake pkg-config sphinx ];
77+ buildInputs = [
78+ ceres'
79+ suitesparse
80+ metis
81+ eigen
82+ lapack
83+ gflags
84+ gtest
85+ glog
86+ pybind11
87+ ];
88+ propagatedBuildInputs = [
89+ numpy
90+ scipy
91+ pyyaml
92+ opencv4
93+ networkx
94+ pillow
95+ matplotlib
96+ fpdf
97+ exifread
98+ gpxpy
99+ pyproj
100+ python-dateutil
101+ joblib
102+ repoze_lru
103+ xmltodict
104+ cloudpickle
105+ ];
106+ checkInputs = [ pytestCheckHook ];
107+
108+ dontUseCmakeBuildDir = true;
109+ cmakeFlags = [
110+ "-Bcmake_build"
111+ "-Sopensfm/src"
112+ ];
113+
114+ disabledTests = lib.optionals stdenv.isDarwin [
115+ "test_reconstruction_incremental"
116+ "test_reconstruction_triangulation"
117+ ];
118+
119+ pythonImportsCheck = [ "opensfm" ];
120+
121+ meta = {
122+ maintainers = [ lib.maintainers.SomeoneSerge ];
123+ license = lib.licenses.bsd2;
124+ description = "Open source Structure-from-Motion pipeline from Mapillary";
125+ homepage = "https://opensfm.org/";
126+ };
127+}
pkgs/development/python-modules/opensfm/fix-scripts.patchnew file+41
@@ -0,0 +1,41 @@
1+diff --git a/bin/opensfm b/bin/opensfm
2+index b5ee4b15..f05c0d1c 100755
3+--- a/bin/opensfm
4++++ b/bin/opensfm
5+@@ -1,12 +1,6 @@
6+-#!/bin/bash
7++#!/usr/bin/env bash
8+ set -e
9+
10+ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
11+
12+-if [ -x "$(command -v python3)" ]; then
13+- PYTHON=python3
14+-else
15+- PYTHON=python
16+-fi
17+-
18+-"$PYTHON" "$DIR"/opensfm_main.py "$@"
19++exec "$DIR"/opensfm_main.py "$@"
20+diff --git a/bin/opensfm_main.py b/bin/opensfm_main.py
21+index 31249e12..cc71560c 100755
22+--- a/bin/opensfm_main.py
23++++ b/bin/opensfm_main.py
24+@@ -1,3 +1,5 @@
25++#!/usr/bin/env python
26++
27+ import sys
28+ from os.path import abspath, join, dirname
29+
30+diff --git a/setup.py b/setup.py
31+index 1120717f..438a16db 100644
32+--- a/setup.py
33++++ b/setup.py
34+@@ -71,6 +71,7 @@ setuptools.setup(
35+ scripts=[
36+ "bin/opensfm_run_all",
37+ "bin/opensfm",
38++ "bin/opensfm_main.py",
39+ ],
40+ package_data={
41+ "opensfm": [
pkgs/top-level/python-packages.nix+2
@@ -5743,6 +5743,8 @@ in {
57435743
57445744 opensensemap-api = callPackage ../development/python-modules/opensensemap-api { };
57455745
5746+ opensfm = callPackage ../development/python-modules/opensfm { };
5747+
57465748 openshift = callPackage ../development/python-modules/openshift { };
57475749
57485750 opensimplex = callPackage ../development/python-modules/opensimplex { };