test_wave_correction.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. namespace opencv_test {
  6. namespace {
  7. detail::WaveCorrectKind correctionKind(const std::vector<UMat>& images)
  8. {
  9. Ptr<Stitcher> stitcher = Stitcher::create(Stitcher::PANORAMA);
  10. stitcher->estimateTransform(images);
  11. std::vector<Mat> rmats;
  12. auto cameras = stitcher->cameras();
  13. for (const auto& camera: cameras)
  14. rmats.push_back(camera.R);
  15. return detail::autoDetectWaveCorrectKind(rmats);
  16. }
  17. TEST(WaveCorrection, AutoWaveCorrection)
  18. {
  19. std::vector<UMat> images(2);
  20. imread(cvtest::TS::ptr()->get_data_path() + "stitching/s1.jpg").copyTo(images[0]);
  21. imread(cvtest::TS::ptr()->get_data_path() + "stitching/s2.jpg").copyTo(images[1]);
  22. EXPECT_EQ(detail::WAVE_CORRECT_HORIZ, correctionKind(images));
  23. std::vector<UMat> rotated_images(2);
  24. rotate(images[0], rotated_images[0], cv::ROTATE_90_CLOCKWISE);
  25. rotate(images[1], rotated_images[1], cv::ROTATE_90_CLOCKWISE);
  26. EXPECT_EQ(detail::WAVE_CORRECT_VERT, correctionKind(rotated_images));
  27. rotate(images[0], rotated_images[0], cv::ROTATE_90_COUNTERCLOCKWISE);
  28. rotate(images[1], rotated_images[1], cv::ROTATE_90_COUNTERCLOCKWISE);
  29. EXPECT_EQ(detail::WAVE_CORRECT_VERT, correctionKind(rotated_images));
  30. rotate(images[0], rotated_images[0], cv::ROTATE_180);
  31. rotate(images[1], rotated_images[1], cv::ROTATE_180);
  32. EXPECT_EQ(detail::WAVE_CORRECT_HORIZ, correctionKind(rotated_images));
  33. }
  34. } // namespace
  35. } // namespace opencv_test