Skip to content

Commit 533405d

Browse files
authored
Update to Colmap 3.9.1 and add Dockerfile (#26)
1 parent 7f66455 commit 533405d

File tree

4 files changed

+100
-26
lines changed

4 files changed

+100
-26
lines changed

Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
ARG UBUNTU_VERSION=22.04
2+
ARG NVIDIA_CUDA_VERSION=12.3.1
3+
FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as builder
4+
5+
ARG COLMAP_VERSION=3.9.1
6+
ARG CUDA_ARCHITECTURES=70
7+
ENV CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES}
8+
ENV QT_XCB_GL_INTEGRATION=xcb_egl
9+
10+
# Prevent stop building ubuntu at time zone selection.
11+
ENV DEBIAN_FRONTEND=noninteractive
12+
13+
# Prepare and empty machine for building.
14+
RUN apt-get update && \
15+
apt-get install -y --no-install-recommends --no-install-suggests \
16+
git \
17+
cmake \
18+
ninja-build \
19+
build-essential \
20+
libboost-program-options-dev \
21+
libboost-filesystem-dev \
22+
libboost-graph-dev \
23+
libboost-system-dev \
24+
libeigen3-dev \
25+
libflann-dev \
26+
libfreeimage-dev \
27+
libmetis-dev \
28+
libgoogle-glog-dev \
29+
libgtest-dev \
30+
libsqlite3-dev \
31+
libglew-dev \
32+
qtbase5-dev \
33+
libqt5opengl5-dev \
34+
libcgal-dev \
35+
python-is-python3 \
36+
python3-minimal \
37+
python3-pip \
38+
python3-dev \
39+
python3-setuptools
40+
41+
# Install Ceres.
42+
RUN apt-get install -y --no-install-recommends --no-install-suggests wget && \
43+
wget "http://ceres-solver.org/ceres-solver-2.1.0.tar.gz" && \
44+
tar zxf ceres-solver-2.1.0.tar.gz && \
45+
mkdir ceres-build && \
46+
cd ceres-build && \
47+
cmake ../ceres-solver-2.1.0 -GNinja && \
48+
ninja install
49+
50+
# Install Colmap.
51+
RUN wget "https://github.com/colmap/colmap/archive/refs/tags/${COLMAP_VERSION}.tar.gz" -O colmap-${COLMAP_VERSION}.tar.gz && \
52+
tar zxvf colmap-${COLMAP_VERSION}.tar.gz && \
53+
mkdir colmap-build && \
54+
cd colmap-build && \
55+
cmake ../colmap-${COLMAP_VERSION} -GNinja -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} && \
56+
ninja install
57+
58+
59+
# Build pyceres.
60+
COPY . /pyceres
61+
WORKDIR /pyceres
62+
RUN pip install . -vv

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ git clone --recursive git@github.com:cvg/pyceres.git
1111
cd pyceres
1212
```
1313

14-
2. Install [COLMAP 3.8](https://colmap.github.io/) - _make sure to use tag 3.8_.
14+
2. Install [COLMAP 3.9.1](https://colmap.github.io/)
1515

1616
3. Build the package:
1717

1818
```sh
1919
pip install -e .
2020
```
2121

22+
### Docker image
23+
24+
Alternatively, you can build the Docker image:
25+
26+
```sh
27+
export COLMAP_VERSION=3.9.1
28+
export CUDA_ARCHITECTURES=70
29+
docker build -t pyceres \
30+
--build-arg COLMAP_VERSION=${COLMAP_VERSION} \
31+
--build-arg CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} \
32+
-f Dockerfile .
33+
```
34+
2235
## Factor graph optimization
2336

2437
For now we support the following cost functions, defined in `_pyceres/factors/`:

_pyceres/factors/bundle.cc

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <colmap/camera/models.h>
2-
#include <colmap/geometry/projection.h>
1+
#include <colmap/scene/projection.h>
2+
#include <colmap/sensor/models.h>
33
#include <colmap/util/types.h>
44

55
#include <ceres/ceres.h>
@@ -15,12 +15,9 @@ inline void WorldToPixel(const T* camera_params, const T* qvec, const T* tvec,
1515
projection[1] += tvec[1];
1616
projection[2] += tvec[2];
1717

18-
// Project to image plane.
19-
projection[0] /= projection[2]; // u
20-
projection[1] /= projection[2]; // v
21-
2218
// Distort and transform to pixel space.
23-
CameraModel::WorldToImage(camera_params, projection[0], projection[1], &xy[0], &xy[1]);
19+
CameraModel::ImgFromCam(camera_params, projection[0], projection[1], projection[2],
20+
&xy[0], &xy[1]);
2421
}
2522

2623
template <typename T>
@@ -43,7 +40,7 @@ class BundleAdjustmentCost {
4340
static ceres::CostFunction* Create(const Eigen::Vector2d& point2D,
4441
const double stddev) {
4542
return (new ceres::AutoDiffCostFunction<BundleAdjustmentCost<CameraModel>, 2, 4, 3, 3,
46-
CameraModel::kNumParams>(
43+
CameraModel::num_params>(
4744
new BundleAdjustmentCost(point2D, stddev)));
4845
}
4946

@@ -78,7 +75,7 @@ class BundleAdjustmentConstantPoseCost : public BundleAdjustmentCost<CameraModel
7875
const Eigen::Vector4d qvec,
7976
const Eigen::Vector3d tvec) {
8077
return (new ceres::AutoDiffCostFunction<BundleAdjustmentConstantPoseCost<CameraModel>,
81-
2, 3, CameraModel::kNumParams>(
78+
2, 3, CameraModel::num_params>(
8279
new BundleAdjustmentConstantPoseCost(point2D, stddev, qvec, tvec)));
8380
}
8481

@@ -111,7 +108,7 @@ class BundleAdjustmentConstantRigCost : public BundleAdjustmentCost<CameraModel>
111108
const Eigen::Vector4d rel_qvec,
112109
const Eigen::Vector3d rel_tvec) {
113110
return (new ceres::AutoDiffCostFunction<BundleAdjustmentConstantRigCost<CameraModel>,
114-
2, 4, 3, 3, CameraModel::kNumParams>(
111+
2, 4, 3, 3, CameraModel::num_params>(
115112
new BundleAdjustmentConstantRigCost(point2D, stddev, rel_qvec, rel_tvec)));
116113
}
117114

@@ -144,7 +141,7 @@ class BundleAdjustmentRigCost : public BundleAdjustmentCost<CameraModel> {
144141
static ceres::CostFunction* Create(const Eigen::Vector2d& point2D,
145142
const double stddev) {
146143
return (new ceres::AutoDiffCostFunction<BundleAdjustmentRigCost<CameraModel>, 2, 4, 3,
147-
4, 3, 3, CameraModel::kNumParams>(
144+
4, 3, 3, CameraModel::num_params>(
148145
new BundleAdjustmentRigCost(point2D, stddev)));
149146
}
150147

@@ -159,12 +156,12 @@ class BundleAdjustmentRigCost : public BundleAdjustmentCost<CameraModel> {
159156
}
160157
};
161158

162-
ceres::CostFunction* CreateBundleAdjustmentCost(int camera_model_id,
163-
const Eigen::Vector2d& point2D,
164-
const double stddev) {
159+
ceres::CostFunction* CreateBundleAdjustmentCost(
160+
const colmap::CameraModelId camera_model_id, const Eigen::Vector2d& point2D,
161+
const double stddev) {
165162
switch (camera_model_id) {
166163
#define CAMERA_MODEL_CASE(CameraModel) \
167-
case colmap::CameraModel::kModelId: \
164+
case colmap::CameraModel::model_id: \
168165
return BundleAdjustmentCost<colmap::CameraModel>::Create(point2D, stddev); \
169166
break;
170167
CAMERA_MODEL_SWITCH_CASES
@@ -173,11 +170,11 @@ ceres::CostFunction* CreateBundleAdjustmentCost(int camera_model_id,
173170
}
174171

175172
ceres::CostFunction* CreateBundleAdjustmentConstantPoseCost(
176-
int camera_model_id, const Eigen::Vector2d& point2D, const Eigen::Vector4d& qvec,
177-
const Eigen::Vector3d& tvec, const double stddev) {
173+
const colmap::CameraModelId camera_model_id, const Eigen::Vector2d& point2D,
174+
const Eigen::Vector4d& qvec, const Eigen::Vector3d& tvec, const double stddev) {
178175
switch (camera_model_id) {
179176
#define CAMERA_MODEL_CASE(CameraModel) \
180-
case colmap::CameraModel::kModelId: \
177+
case colmap::CameraModel::model_id: \
181178
return BundleAdjustmentConstantPoseCost<colmap::CameraModel>::Create( \
182179
point2D, stddev, qvec, tvec); \
183180
break;
@@ -187,11 +184,12 @@ ceres::CostFunction* CreateBundleAdjustmentConstantPoseCost(
187184
}
188185

189186
ceres::CostFunction* CreateBundleAdjustmentConstantRigCost(
190-
int camera_model_id, const Eigen::Vector2d& point2D, const Eigen::Vector4d& rel_qvec,
191-
const Eigen::Vector3d& rel_tvec, const double stddev) {
187+
const colmap::CameraModelId camera_model_id, const Eigen::Vector2d& point2D,
188+
const Eigen::Vector4d& rel_qvec, const Eigen::Vector3d& rel_tvec,
189+
const double stddev) {
192190
switch (camera_model_id) {
193191
#define CAMERA_MODEL_CASE(CameraModel) \
194-
case colmap::CameraModel::kModelId: \
192+
case colmap::CameraModel::model_id: \
195193
return BundleAdjustmentConstantRigCost<colmap::CameraModel>::Create( \
196194
point2D, stddev, rel_qvec, rel_tvec); \
197195
break;
@@ -200,12 +198,12 @@ ceres::CostFunction* CreateBundleAdjustmentConstantRigCost(
200198
}
201199
}
202200

203-
ceres::CostFunction* CreateBundleAdjustmentRigCost(int camera_model_id,
204-
const Eigen::Vector2d& point2D,
205-
const double stddev) {
201+
ceres::CostFunction* CreateBundleAdjustmentRigCost(
202+
const colmap::CameraModelId camera_model_id, const Eigen::Vector2d& point2D,
203+
const double stddev) {
206204
switch (camera_model_id) {
207205
#define CAMERA_MODEL_CASE(CameraModel) \
208-
case colmap::CameraModel::kModelId: \
206+
case colmap::CameraModel::model_id: \
209207
return BundleAdjustmentRigCost<colmap::CameraModel>::Create(point2D, stddev); \
210208
break;
211209
CAMERA_MODEL_SWITCH_CASES

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def build_extension(self, ext):
3939
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
4040
'-DPYTHON_EXECUTABLE=' + sys.executable,
4141
'-DVERSION_INFO={}'.format(self.distribution.get_version()),
42+
'-DCMAKE_CUDA_ARCHITECTURES={}'.format(os.environ.get('CUDA_ARCHITECTURES', 'native')),
4243
]
4344
eigen_dir = os.environ.get('EIGEN3_INCLUDE_DIRS')
4445
if eigen_dir is not None:

0 commit comments

Comments
 (0)