1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
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
37let
38 ceresSplit = (builtins.length ceres-solver.outputs) > 1;
39 ceres' = if ceresSplit then ceres-solver.dev else ceres-solver;
40in
41buildPythonPackage rec {
42 pname = "opensfm";
43 version = "unstable-2023-12-09";
44
45 src = fetchFromGitHub {
46 owner = "mapillary";
47 repo = "OpenSfM";
48 rev = "7f170d0dc352340295ff480378e3ac37d0179f8e";
49 sha256 = "sha256-l/HTVenC+L+GpMNnDgnSGZ7+Qd2j8b8cuTs3SmORqrg=";
50 };
51 patches = [
52 ./0002-cmake-find-system-distributed-gtest.patch
53 ./0003-cmake-use-system-pybind11.patch
54 ./0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch
55 ./fix-scripts.patch
56 ];
57 postPatch = ''
58 rm opensfm/src/cmake/FindGlog.cmake
59 rm opensfm/src/cmake/FindGflags.cmake
60
61 # HAHOG is the default descriptor.
62 # We'll test both HAHOG and SIFT because this is
63 # where segfaults might be introduced in future
64 echo 'feature_type: SIFT' >> data/berlin/config.yaml
65 echo 'feature_type: HAHOG' >> data/lund/config.yaml
66
67 sed -i -e 's/^.*BuildDoc.*$//' setup.py
68 '';
69
70 nativeBuildInputs = [
71 cmake
72 pkg-config
73 sphinx
74 ];
75 buildInputs = [
76 ceres'
77 suitesparse
78 metis
79 eigen
80 lapack
81 gflags
82 gtest
83 glog
84 pybind11
85 ];
86 propagatedBuildInputs = [
87 numpy
88 scipy
89 pyyaml
90 opencv4.cxxdev
91 networkx
92 pillow
93 matplotlib
94 fpdf
95 exifread
96 gpxpy
97 pyproj
98 python-dateutil
99 joblib
100 repoze-lru
101 xmltodict
102 cloudpickle
103 ];
104 nativeCheckInputs = [ pytestCheckHook ];
105
106 dontUseCmakeBuildDir = true;
107 cmakeFlags = [
108 "-Bcmake_build"
109 "-Sopensfm/src"
110 ];
111
112 disabledTests =
113 [
114 "test_run_all" # Matplotlib issues. Broken integration is less useless than a broken build
115 ]
116 ++ lib.optionals stdenv.hostPlatform.isDarwin [
117 "test_reconstruction_incremental"
118 "test_reconstruction_triangulation"
119 ];
120
121 pythonImportsCheck = [ "opensfm" ];
122
123 meta = {
124 broken = stdenv.hostPlatform.isDarwin;
125 maintainers = [ lib.maintainers.SomeoneSerge ];
126 license = lib.licenses.bsd2;
127 changelog = "https://github.com/mapillary/OpenSfM/blob/${src.rev}/CHANGELOG.md";
128 description = "Open source Structure-from-Motion pipeline from Mapillary";
129 homepage = "https://opensfm.org/";
130 };
131}