Skip to content

Commit 065db29

Browse files
authored
Bugfix incomplete panos (#123)
* add image indices to saved camera parameters * add test for incomplete panos * tidy * update default sidebar width
1 parent 1856277 commit 065db29

File tree

6 files changed

+53
-13
lines changed

6 files changed

+53
-13
lines changed

tests/stitcher_pipeline_test.cc

+36-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ TEST_CASE("Pano too large") {
199199
xpano::algorithm::stitcher::Status::kErrPanoTooLarge);
200200
}
201201

202+
const std::vector<std::filesystem::path> kInputsIncomplete = {
203+
"data/image05.jpg", // pano 1
204+
"data/image06.jpg", // pano 2
205+
"data/image07.jpg" // pano 2
206+
};
207+
208+
TEST_CASE("Incomplete pano") {
209+
xpano::pipeline::StitcherPipeline<kReturnFuture> stitcher;
210+
211+
auto loading_task = stitcher.RunLoading(kInputsIncomplete, {}, {});
212+
auto stitch_data = loading_task.future.get();
213+
auto progress = loading_task.progress->Report();
214+
CHECK(progress.tasks_done == progress.num_tasks);
215+
216+
CHECK(stitch_data.images.size() == 3);
217+
REQUIRE(stitch_data.panos.size() == 1);
218+
REQUIRE_THAT(stitch_data.panos[0].ids, Equals<int>({1, 2}));
219+
220+
// add an unrelated image to the pano
221+
stitch_data.panos[0].ids = {0, 1, 2};
222+
223+
// stitch
224+
auto stitching_task0 = stitcher.RunStitching(stitch_data, {.pano_id = 0});
225+
auto stitch_result0 = stitching_task0.future.get();
226+
227+
// TODO(krupkat): fix, this is currently not equal
228+
// progress = stitching_task0.progress->Report();
229+
// CHECK(progress.tasks_done == progress.num_tasks);
230+
231+
REQUIRE(stitch_result0.pano.has_value());
232+
REQUIRE(stitch_result0.cameras.has_value());
233+
CHECK(stitch_result0.cameras->cameras.size() == 2);
234+
CHECK_THAT(stitch_result0.cameras->component, Equals<int>({1, 2}));
235+
}
236+
202237
TEST_CASE("Stitcher pipeline single pano matching") {
203238
xpano::pipeline::StitcherPipeline<kReturnFuture> stitcher;
204239
auto loading_task = stitcher.RunLoading(
@@ -657,4 +692,4 @@ TEST_CASE("Stitcher pipeline stack detection") {
657692
CHECK_THAT(result.panos[0].ids, Equals<int>({2, 3}));
658693
}
659694

660-
// NOLINTEND(readability-function-cognitive-complexity)
695+
// NOLINTEND(readability-function-cognitive-complexity)

xpano/algorithm/algorithm.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,9 @@ StitchResult Stitch(const std::vector<cv::Mat>& images,
272272
stitcher::Status status;
273273

274274
if (cameras &&
275-
cameras->wave_correction_user == user_options.wave_correction &&
276-
cameras->cameras.size() == images.size()) {
275+
cameras->wave_correction_user == user_options.wave_correction) {
277276
stitcher->SetWaveCorrectKind(cameras->wave_correction_auto);
278-
stitcher->SetTransform(images, cameras->cameras);
277+
stitcher->SetTransform(images, cameras->cameras, cameras->component);
279278
status = stitcher->ComposePanorama(pano);
280279
} else {
281280
status = stitcher->Stitch(images, pano);
@@ -290,9 +289,9 @@ StitchResult Stitch(const std::vector<cv::Mat>& images,
290289
stitcher->ResultMask().copyTo(mask);
291290
}
292291

293-
auto result_cameras =
294-
Cameras{stitcher->Cameras(), user_options.wave_correction,
295-
stitcher->WaveCorrectKind(), stitcher->GetWarpHelper()};
292+
auto result_cameras = Cameras{
293+
stitcher->Cameras(), stitcher->Component(), user_options.wave_correction,
294+
stitcher->WaveCorrectKind(), stitcher->GetWarpHelper()};
296295
return {status, pano, mask, std::move(result_cameras)};
297296
}
298297

xpano/algorithm/algorithm.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace xpano::algorithm {
2222

2323
struct Cameras {
2424
std::vector<cv::detail::CameraParams> cameras;
25+
std::vector<int> component;
2526
WaveCorrectionType wave_correction_user; // set by user
2627
cv::detail::WaveCorrectKind wave_correction_auto; // computed by OpenCV
2728
stitcher::WarpHelper warp_helper;

xpano/constants.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ constexpr int kMaxPngCompression = 9;
5656

5757
constexpr int kAboutBoxWidth = 70;
5858
constexpr int kAboutBoxHeight = 30;
59-
constexpr int kSidebarWidth = 27;
59+
constexpr int kSidebarWidth = 35;
6060
constexpr int kWideButtonWidth = 12;
6161

6262
const std::string kOrgName = "krupkat";

xpano/gui/action.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct ShowPanoExtra {
4848
bool full_res = false;
4949
bool scroll_thumbnails = false;
5050
bool reset_crop = false;
51+
bool reset_cameras = false;
5152
};
5253

5354
using LoadFilesExtra = std::vector<std::filesystem::path>;

xpano/gui/pano_gui.cc

+9-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Action ModifyPano(int clicked_image, Selection* selection,
123123
return {.type = ActionType::kShowPano,
124124
.target_id = selection->target_id,
125125
.delayed = true,
126-
.extra = ShowPanoExtra{.reset_crop = true}};
126+
.extra = ShowPanoExtra{.reset_crop = true, .reset_cameras = true}};
127127
}
128128
return {};
129129
}
@@ -454,18 +454,22 @@ Action PanoGui::PerformAction(const Action& action) {
454454
spdlog::info("Calculating pano {}", selection_.target_id);
455455
status_message_ = {};
456456
auto extra = ValueOrDefault<ShowPanoExtra>(action);
457+
auto& pano = stitcher_data_->panos[selection_.target_id];
458+
if (extra.reset_cameras) {
459+
pano.cameras.reset();
460+
pano.backup_cameras.reset();
461+
}
462+
if (extra.reset_crop) {
463+
pano.crop.reset();
464+
}
457465
stitcher_pipeline_.RunStitching(*stitcher_data_,
458466
{.pano_id = selection_.target_id,
459467
.full_res = extra.full_res,
460468
.stitch_algorithm = options_.stitch});
461-
auto& pano = stitcher_data_->panos[selection_.target_id];
462469
thumbnail_pane_.Highlight(pano.ids);
463470
if (extra.scroll_thumbnails) {
464471
thumbnail_pane_.SetScrollX(pano.ids);
465472
}
466-
if (extra.reset_crop) {
467-
pano.crop.reset();
468-
}
469473
break;
470474
}
471475
case ActionType::kModifyPano: {

0 commit comments

Comments
 (0)