├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── assets
├── images
│ └── example.jpg
└── videos
│ └── demo_deeplsd.gif
├── deeplsd
├── __init__.py
├── configs
│ ├── export_eth3d.yaml
│ ├── export_hpatches.yaml
│ ├── export_minidepth.yaml
│ ├── export_nyu.yaml
│ ├── export_rdnim.yaml
│ ├── export_wireframe.yaml
│ ├── export_york_urban.yaml
│ ├── export_york_urban_lines.yaml
│ ├── train_merged_datasets.yaml
│ ├── train_minidepth.yaml
│ └── train_wireframe.yaml
├── datasets
│ ├── __init__.py
│ ├── base_dataset.py
│ ├── hpatches.py
│ ├── merge_dataset.py
│ ├── minidepth.py
│ ├── nyu.py
│ ├── rdnim.py
│ ├── utils
│ │ ├── __init__.py
│ │ ├── data_augmentation.py
│ │ ├── homographies.py
│ │ ├── megadepth_train_scenes.txt
│ │ ├── megadepth_val_scenes.txt
│ │ └── preprocessing.py
│ ├── wireframe_eval.py
│ ├── wireframe_ha.py
│ ├── york_urban.py
│ └── york_urban_lines.py
├── evaluation
│ ├── __init__.py
│ └── ls_evaluation.py
├── geometry
│ ├── __init__.py
│ ├── homography_adaptation.py
│ ├── line_utils.py
│ ├── projection.py
│ ├── utils.py
│ └── viz_2d.py
├── models
│ ├── __init__.py
│ ├── backbones
│ │ ├── __init__.py
│ │ └── vgg_unet.py
│ ├── base_model.py
│ ├── deeplsd.py
│ ├── deeplsd_inference.py
│ ├── lbd.py
│ └── line_refiner.py
├── scripts
│ ├── evaluate_line_detection.py
│ ├── evaluate_vp_estimation.py
│ ├── export_features.py
│ ├── homography_adaptation_df.py
│ ├── line_refinement.py
│ └── train.py
├── settings.py
└── utils
│ ├── __init__.py
│ ├── experiments.py
│ ├── stdout_capturing.py
│ ├── tensor.py
│ └── tools.py
├── install.sh
├── line_refinement
├── CMakeLists.txt
├── cost_functions.h
├── line_vp_optim.cpp
├── setup.py
└── vp_det.h
├── notebooks
├── demo_line_detection.ipynb
└── quickstart_demo.ipynb
├── quickstart_install.sh
├── requirements.txt
├── setup.py
└── third_party
└── afm_lib
├── afm_op
├── __init__.py
├── afm.h
├── cuda
│ ├── afm.cu
│ └── afm.h
├── example.py
├── setup.py
└── vision.cpp
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Build -----------------------------------------------------------------------
3 |
4 | ### Output and Cache Directories ###
5 | /External/
6 | /Debug/
7 | /Docs/
8 | /Release/
9 | /build/
10 | /bin/
11 | /out/
12 | /cmake-build-*/
13 | /dist/
14 |
15 | ### CMake ###
16 | CMakeCache.txt
17 | CMakeFiles
18 | CMakeScripts
19 | Makefile
20 | cmake_install.cmake
21 | install_manifest.txt
22 |
23 | # Language --------------------------------------------------------------------
24 |
25 | ### C++ ###
26 | # Compiled Object files
27 | *.slo
28 | *.lo
29 | *.o
30 |
31 | # Comment this line if you want to version Wavefront .obj files.
32 | *.obj
33 |
34 | # Precompiled Headers
35 | *.gch
36 | *.pch
37 |
38 | # Compiled Dynamic libraries
39 | *.so
40 | *.dylib
41 | *.dll
42 |
43 | # Fortran module files
44 | *.mod
45 |
46 | # Compiled Static libraries
47 | *.lai
48 | *.la
49 | *.a
50 | *.lib
51 |
52 | # Executables
53 | *.exe
54 | *.out
55 | *.app
56 |
57 | # Byte-compiled / optimized / DLL files
58 | __pycache__/
59 | *.py[cod]
60 | *$py.class
61 |
62 | # C extensions
63 | *.so
64 |
65 | # Distribution / packaging
66 | .Python
67 | build/
68 | develop-eggs/
69 | dist/
70 | downloads/
71 | eggs/
72 | .eggs/
73 | lib/
74 | lib64/
75 | parts/
76 | sdist/
77 | var/
78 | wheels/
79 | pip-wheel-metadata/
80 | share/python-wheels/
81 | *.egg-info/
82 | .installed.cfg
83 | *.egg
84 | MANIFEST
85 |
86 | # PyInstaller
87 | # Usually these files are written by a python script from a template
88 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
89 | *.manifest
90 | *.spec
91 |
92 | # Installer logs
93 | pip-log.txt
94 | pip-delete-this-directory.txt
95 |
96 | # Unit test / coverage reports
97 | htmlcov/
98 | .tox/
99 | .nox/
100 | .coverage
101 | .coverage.*
102 | .cache
103 | nosetests.xml
104 | coverage.xml
105 | *.cover
106 | *.py,cover
107 | .hypothesis/
108 | .pytest_cache/
109 |
110 | # Translations
111 | *.mo
112 | *.pot
113 |
114 | # Django stuff:
115 | *.log
116 | local_settings.py
117 | db.sqlite3
118 | db.sqlite3-journal
119 |
120 | # Flask stuff:
121 | instance/
122 | .webassets-cache
123 |
124 | # Scrapy stuff:
125 | .scrapy
126 |
127 | # Sphinx documentation
128 | docs/_build/
129 |
130 | # PyBuilder
131 | target/
132 |
133 | # Jupyter Notebook
134 | .ipynb_checkpoints
135 |
136 | # IPython
137 | profile_default/
138 | ipython_config.py
139 |
140 | # pyenv
141 | .python-version
142 |
143 | # pipenv
144 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
145 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
146 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
147 | # install all needed dependencies.
148 | #Pipfile.lock
149 |
150 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
151 | __pypackages__/
152 |
153 | # Celery stuff
154 | celerybeat-schedule
155 | celerybeat.pid
156 |
157 | # SageMath parsed files
158 | *.sage.py
159 |
160 | # Environments
161 | .env
162 | .venv
163 | env/
164 | venv/
165 | ENV/
166 | env.bak/
167 | venv.bak/
168 |
169 | # Spyder project settings
170 | .spyderproject
171 | .spyproject
172 |
173 | # Rope project settings
174 | .ropeproject
175 |
176 | # mkdocs documentation
177 | /site
178 |
179 | # mypy
180 | .mypy_cache/
181 | .dmypy.json
182 | dmypy.json
183 |
184 | # Pyre type checker
185 | .pyre/
186 |
187 | ### VS Code
188 | .vscode
189 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "third_party/progressive-x"]
2 | path = third_party/progressive-x
3 | url = https://github.com/danini/progressive-x.git
4 | [submodule "third_party/pytlbd"]
5 | path = third_party/pytlbd
6 | url = https://github.com/iago-suarez/pytlbd.git
7 | [submodule "line_refinement/pybind11"]
8 | path = line_refinement/pybind11
9 | url = https://github.com/pybind/pybind11
10 | [submodule "third_party/homography_est"]
11 | path = third_party/homography_est
12 | url = https://github.com/rpautrat/homography_est.git
13 | [submodule "third_party/pytlsd"]
14 | path = third_party/pytlsd
15 | url = https://github.com/iago-suarez/pytlsd.git
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Rémi Pautrat
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DeepLSD
2 | Implementation of the paper [DeepLSD: Line Segment Detection and Refinement with Deep Image Gradients](https://arxiv.org/abs/2212.07766), accepted at CVPR 2023. **DeepLSD is a generic line detector that combines the robustness of deep learning with the accuracy of handcrafted detectors**. It can be used to extract **generic line segments from images in-the-wild**, and is **suitable for any task requiring high precision**, such as homography estimation, visual localization, and 3D reconstruction. By predicting a line distance and angle fields, **it can furthermore refine any existing line segments** through an optimization.
3 |
4 | Demo of the lines detected by DeepLSD, its line distance field, and line angle field:
5 |
6 |
7 |
8 |
9 |
10 | ## Installation
11 | First clone the repository and its submodules:
12 | ```
13 | git clone --recurse-submodules https://github.com/cvg/DeepLSD.git
14 | cd DeepLSD
15 | ```
16 |
17 | ### Quickstart install (for inference only)
18 |
19 | To test the pre-trained model on your images, without the final line refinement, the following installation is sufficient:
20 | ```
21 | bash quickstart_install.sh
22 | ```
23 | You can then test it with the notebook `notebooks/quickstart_demo.ipynb`.
24 |
25 | ### Full install
26 |
27 | Follow these instructions if you wish to re-train DeepLSD, evaluate it, or use the final step of line refinement.
28 |
29 | Dependencies that need to be installed on your system:
30 | - [OpenCV](https://opencv.org/)
31 | - [GFlags](https://github.com/gflags/gflags)
32 | - [GLog](https://github.com/google/glog)
33 | - [Ceres](http://ceres-solver.org/)
34 | - DeepLSD was successfully tested with GCC 9, Python 3.7, and CUDA 11. Other combinations may work as well.
35 |
36 | Once these libraries are installed, you can proceed with the installation of the necessary requirements and third party libraries:
37 | ```
38 | bash install.sh
39 | ```
40 |
41 | This repo uses a base experiment folder (EXPER_PATH) containing the output of all trainings, and a base dataset path (DATA_PATH) containing all the evaluation and training datasets. You can set the path to these two folders in the file `deeplsd/settings.py`.
42 |
43 | ## Usage
44 | We provide two pre-trained models for DeepLSD: [deeplsd_wireframe.tar](https://cvg-data.inf.ethz.ch/DeepLSD/deeplsd_wireframe.tar) and [deeplsd_md.tar](https://cvg-data.inf.ethz.ch/DeepLSD/deeplsd_md.tar), trained respectively on the Wireframe and MegaDepth datasets. The former can be used for easy indoor datasets, while the latter is more generic and works outdoors and on more challenging scenes.
45 | The example notebook `notebooks/demo_line_detection.ipynb` showcases how to use DeepLSD in practice. Please refer to the comments on the config of this notebook to understand the usage of each hyperparameter.
46 |
47 | You can download the two models with the following command:
48 | ```
49 | mkdir weights
50 | wget https://cvg-data.inf.ethz.ch/DeepLSD/deeplsd_wireframe.tar -O weights/deeplsd_wireframe.tar
51 | wget https://cvg-data.inf.ethz.ch/DeepLSD/deeplsd_md.tar -O weights/deeplsd_md.tar
52 | ```
53 |
54 | ## Ground truth (GT) generation
55 | DeepLSD requires generating a ground truth for line distance and angle field, through homography adaptation. We provide a Python script to do it for any list of images, leveraging CUDA:
56 | ```
57 | python -m deeplsd.scripts.homography_adaptation_df