bundle_adjustment¶
Bundle adjustment over plain arrays, rig-free (ADR-0001).
build_state packs per-view rvecs, tvecs, intrs, dists and the observed 2D
into a flat state, with a small grammar for fixing and sharing parameters across
views, and bundle_adjust solves it; it depends only on deeperfly.geometry.
BASolution ¶
Bases: NamedTuple
Optimized parameters unpacked back into per-view arrays plus points.
Source code in src/deeperfly/bundle_adjustment/core.py
BAState ¶
Bases: NamedTuple
Packed bundle-adjustment state ready for bundle_adjust.
values is the flat parameter vector and fixed the mask held constant; the
*_idx arrays recover the per-view arrays and may alias to share. pts2d is the
observations, and mirrored, the apparatus's and never solved, rides beside them.
Source code in src/deeperfly/bundle_adjustment/state.py
build_state ¶
build_state(
rvecs: Float[ndarray, "V 3"],
tvecs: Float[ndarray, "V 3"],
intrs: Float[ndarray, "V P"],
dists: Float[ndarray, "V K"],
mirrored: Bool[ndarray, V],
pts2d: Float[ndarray, "V N 2"],
names: list[str] | None = None,
*,
fixed: Sequence[str] = (),
shared: Sequence[Sequence[str]] = (),
pts3d: Float[ndarray, "N 3"] | None = None,
) -> BAState
Build a BAState from per-view arrays and fix/share specs.
Intrinsics and distortion are per view unless shared. names (default "0",
"1"...) resolves references and must be one unique name per view. A reference
is "<view>.<param>" or "<view>.<param>[i]", <view> a name or * and
<param> one of rvec, tvec, intr (alias kmat) or dist. Each shared
group ties its members element-wise into one slot, so fixing one fixes all, and a
clash of initial values keeps the lowest slot's, with a warning. pts3d defaults
to a triangulation.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the per-view arrays disagree on the view count, |
Source code in src/deeperfly/bundle_adjustment/state.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
bundle_adjust ¶
bundle_adjust(
values: Float[ndarray, n_params],
fixed: Bool[ndarray, n_params],
rvecs_idx: Int[ndarray, "V 3"],
tvecs_idx: Int[ndarray, "V 3"],
intrs_idx: Int[ndarray, "V P"],
dists_idx: Int[ndarray, "V K"],
pts3d_idx: Int[ndarray, "N 3"],
pts2d: Float[ndarray, "V N 2"],
mirrored: Bool[ndarray, V],
loss: str = "linear",
f_scale: float = 1.0,
max_nfev: int = 1000,
weights: Float[ndarray, "V N"] | None = None,
bone_pairs: Int[ndarray, "B 2"] | None = None,
bone_targets: Float[ndarray, B] | None = None,
bone_weight: float = 1.0,
**kwargs: Any,
) -> tuple[OptimizeResult, BASolution]
Bundle adjustment with a JAX-computed analytic Jacobian.
The low-level solver over the packed state of
build_state (see its
BAState). loss and f_scale go to scipy.optimize.least_squares, with
huber, cauchy and arctan translated to IRLS form (_IRLS_LOSSES). weights
(V, N) scale each residual by sqrt(weight); a negative or non-finite one drops
the observation, and all zero falls back to uniform with a warning. bone_pairs,
bone_targets and bone_weight append a soft bone-length prior
bone_weight * (||p_i - p_j|| - target). kwargs go to scipy; x_scale
defaults to "jac" (ADR-0057).
Returns:
| Type | Description |
|---|---|
OptimizeResult
|
|
BASolution
|
into per-view arrays and points. |
Source code in src/deeperfly/bundle_adjustment/core.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
initialize_pts3d ¶
initialize_pts3d(
pts2d: Float[ndarray, "V *pts 2"],
rvecs: Float[ndarray, "V 3"],
tvecs: Float[ndarray, "V 3"],
intrs: Float[ndarray, "V P"] | Float[ndarray, P],
mirrored: Bool[ndarray, V],
) -> Float[Array, "*pts 3"]
Triangulate initial (*pts, 3) points from the 2D and the view poses.
Source code in src/deeperfly/bundle_adjustment/state.py
Packed parameter state for bundle adjustment.
The state concatenates [rvecs, tvecs, intrs, dists, pts3d], index arrays recover the
shapes, and a fixed mask holds parameters constant. Two index entries may point at
one slot, which is how parameters are shared; build_state exposes it through a
reference grammar ("f.tvec[2]", "*.intr").
BAState ¶
Bases: NamedTuple
Packed bundle-adjustment state ready for bundle_adjust.
values is the flat parameter vector and fixed the mask held constant; the
*_idx arrays recover the per-view arrays and may alias to share. pts2d is the
observations, and mirrored, the apparatus's and never solved, rides beside them.
Source code in src/deeperfly/bundle_adjustment/state.py
build_state ¶
build_state(
rvecs: Float[ndarray, "V 3"],
tvecs: Float[ndarray, "V 3"],
intrs: Float[ndarray, "V P"],
dists: Float[ndarray, "V K"],
mirrored: Bool[ndarray, V],
pts2d: Float[ndarray, "V N 2"],
names: list[str] | None = None,
*,
fixed: Sequence[str] = (),
shared: Sequence[Sequence[str]] = (),
pts3d: Float[ndarray, "N 3"] | None = None,
) -> BAState
Build a BAState from per-view arrays and fix/share specs.
Intrinsics and distortion are per view unless shared. names (default "0",
"1"...) resolves references and must be one unique name per view. A reference
is "<view>.<param>" or "<view>.<param>[i]", <view> a name or * and
<param> one of rvec, tvec, intr (alias kmat) or dist. Each shared
group ties its members element-wise into one slot, so fixing one fixes all, and a
clash of initial values keeps the lowest slot's, with a warning. pts3d defaults
to a triangulation.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the per-view arrays disagree on the view count, |
Source code in src/deeperfly/bundle_adjustment/state.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
initialize_pts3d ¶
initialize_pts3d(
pts2d: Float[ndarray, "V *pts 2"],
rvecs: Float[ndarray, "V 3"],
tvecs: Float[ndarray, "V 3"],
intrs: Float[ndarray, "V P"] | Float[ndarray, P],
mirrored: Bool[ndarray, V],
) -> Float[Array, "*pts 3"]
Triangulate initial (*pts, 3) points from the 2D and the view poses.
Source code in src/deeperfly/bundle_adjustment/state.py
Bundle adjustment with JAX-accelerated residuals and Jacobians.
bundle_adjust wraps scipy.optimize.least_squares (TRF and LSMR); the
per-observation residual and Jacobian come from jax.vmap and jax.jacrev on
project_full_one, assembled into a sparse
matrix through a precomputed pattern. The packed state is
deeperfly.bundle_adjustment.state's.
BASolution ¶
Bases: NamedTuple
Optimized parameters unpacked back into per-view arrays plus points.
Source code in src/deeperfly/bundle_adjustment/core.py
bundle_adjust ¶
bundle_adjust(
values: Float[ndarray, n_params],
fixed: Bool[ndarray, n_params],
rvecs_idx: Int[ndarray, "V 3"],
tvecs_idx: Int[ndarray, "V 3"],
intrs_idx: Int[ndarray, "V P"],
dists_idx: Int[ndarray, "V K"],
pts3d_idx: Int[ndarray, "N 3"],
pts2d: Float[ndarray, "V N 2"],
mirrored: Bool[ndarray, V],
loss: str = "linear",
f_scale: float = 1.0,
max_nfev: int = 1000,
weights: Float[ndarray, "V N"] | None = None,
bone_pairs: Int[ndarray, "B 2"] | None = None,
bone_targets: Float[ndarray, B] | None = None,
bone_weight: float = 1.0,
**kwargs: Any,
) -> tuple[OptimizeResult, BASolution]
Bundle adjustment with a JAX-computed analytic Jacobian.
The low-level solver over the packed state of
build_state (see its
BAState). loss and f_scale go to scipy.optimize.least_squares, with
huber, cauchy and arctan translated to IRLS form (_IRLS_LOSSES). weights
(V, N) scale each residual by sqrt(weight); a negative or non-finite one drops
the observation, and all zero falls back to uniform with a warning. bone_pairs,
bone_targets and bone_weight append a soft bone-length prior
bone_weight * (||p_i - p_j|| - target). kwargs go to scipy; x_scale
defaults to "jac" (ADR-0057).
Returns:
| Type | Description |
|---|---|
OptimizeResult
|
|
BASolution
|
into per-view arrays and points. |
Source code in src/deeperfly/bundle_adjustment/core.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |