|
26 | 26 | #include "xpano/algorithm/options.h"
|
27 | 27 | #include "xpano/algorithm/stitcher.h"
|
28 | 28 | #include "xpano/constants.h"
|
| 29 | +#include "xpano/utils/rect.h" |
| 30 | +#include "xpano/utils/vec_opencv.h" |
29 | 31 |
|
30 | 32 | using Catch::Matchers::Equals;
|
31 | 33 | using Catch::Matchers::WithinAbs;
|
@@ -441,6 +443,46 @@ TEST_CASE("Export [extra results]") {
|
441 | 443 | std::filesystem::remove(tmp_path);
|
442 | 444 | }
|
443 | 445 |
|
| 446 | +TEST_CASE("Export with crop") { |
| 447 | + const std::filesystem::path tmp_path = |
| 448 | + xpano::tests::TmpPath().replace_extension("png"); |
| 449 | + |
| 450 | + xpano::pipeline::StitcherPipeline<kReturnFuture> stitcher; |
| 451 | + auto loading_task = stitcher.RunLoading(kInputsWithExifMetadata, {}, {}); |
| 452 | + auto data = loading_task.future.get(); |
| 453 | + REQUIRE(data.panos.size() == 1); |
| 454 | + |
| 455 | + auto crop = xpano::utils::Rect(xpano::utils::Ratio2f{0.25f, 0.25f}, |
| 456 | + xpano::utils::Ratio2f{0.5f, 0.75f}); |
| 457 | + auto stitch_result = stitcher |
| 458 | + .RunStitching(data, {.pano_id = 0, |
| 459 | + .export_path = tmp_path, |
| 460 | + .export_crop = crop}) |
| 461 | + .future.get(); |
| 462 | + |
| 463 | + const float eps = 0.02; |
| 464 | + |
| 465 | + CHECK(stitch_result.pano.has_value()); |
| 466 | + CHECK(stitch_result.export_path.has_value()); |
| 467 | + |
| 468 | + REQUIRE(std::filesystem::exists(tmp_path)); |
| 469 | + auto image = cv::imread(tmp_path.string()); |
| 470 | + REQUIRE(!image.empty()); |
| 471 | + CHECK_THAT(image.rows, WithinRel(488, eps)); |
| 472 | + CHECK_THAT(image.cols, WithinRel(334, eps)); |
| 473 | + |
| 474 | + auto cv_rect = xpano::utils::GetCvRect(*stitch_result.pano, crop); |
| 475 | + auto pano_cropped = (*stitch_result.pano)(cv_rect); |
| 476 | + |
| 477 | + REQUIRE(pano_cropped.rows == image.rows); |
| 478 | + REQUIRE(pano_cropped.cols == image.cols); |
| 479 | + |
| 480 | + auto avg_diff = cv::norm(pano_cropped, image); |
| 481 | + CHECK(avg_diff <= 1e-6); |
| 482 | + |
| 483 | + std::filesystem::remove(tmp_path); |
| 484 | +} |
| 485 | + |
444 | 486 | TEST_CASE("ExportWithMetadata") {
|
445 | 487 | const std::filesystem::path tmp_path =
|
446 | 488 | xpano::tests::TmpPath().replace_extension("jpg");
|
|
0 commit comments