Skip to content

Commit 30d26ac

Browse files
committed
Make stitching panoramas reusable after estimating transform once
Stitcher will now make a working copy of the CameraParams object to avoid side effects when composing Panorama. Makes it possible to estimate transform once and then compose multiple panoramas. Useful for setup with fixed cameras.
1 parent bcac7bd commit 30d26ac

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

modules/stitching/src/stitcher.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra
261261
double compose_scale = 1;
262262
bool is_compose_scale_set = false;
263263

264+
std::vector<detail::CameraParams> cameras_scaled(cameras_);
265+
264266
UMat full_img, img;
265267
for (size_t img_idx = 0; img_idx < imgs_.size(); ++img_idx)
266268
{
@@ -282,16 +284,16 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra
282284
compose_work_aspect = compose_scale / work_scale_;
283285

284286
// Update warped image scale
285-
warped_image_scale_ *= static_cast<float>(compose_work_aspect);
286-
w = warper_->create((float)warped_image_scale_);
287+
float warp_scale = static_cast<float>(warped_image_scale_ * compose_work_aspect);
288+
w = warper_->create(warp_scale);
287289

288290
// Update corners and sizes
289291
for (size_t i = 0; i < imgs_.size(); ++i)
290292
{
291293
// Update intrinsics
292-
cameras_[i].focal *= compose_work_aspect;
293-
cameras_[i].ppx *= compose_work_aspect;
294-
cameras_[i].ppy *= compose_work_aspect;
294+
cameras_scaled[i].ppx *= compose_work_aspect;
295+
cameras_scaled[i].ppy *= compose_work_aspect;
296+
cameras_scaled[i].focal *= compose_work_aspect;
295297

296298
// Update corner and size
297299
Size sz = full_img_sizes_[i];
@@ -302,8 +304,8 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra
302304
}
303305

304306
Mat K;
305-
cameras_[i].K().convertTo(K, CV_32F);
306-
Rect roi = w->warpRoi(sz, K, cameras_[i].R);
307+
cameras_scaled[i].K().convertTo(K, CV_32F);
308+
Rect roi = w->warpRoi(sz, K, cameras_scaled[i].R);
307309
corners[i] = roi.tl();
308310
sizes[i] = roi.size();
309311
}
@@ -324,7 +326,7 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra
324326
LOGLN(" after resize time: " << ((getTickCount() - compositing_t) / getTickFrequency()) << " sec");
325327

326328
Mat K;
327-
cameras_[img_idx].K().convertTo(K, CV_32F);
329+
cameras_scaled[img_idx].K().convertTo(K, CV_32F);
328330

329331
#if ENABLE_LOG
330332
int64 pt = getTickCount();

0 commit comments

Comments
 (0)