test_stabilizer.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <opencv2/ts/cuda_test.hpp> // EXPECT_MAT_NEAR
  6. namespace opencv_test { namespace {
  7. using namespace ::cv::videostab;
  8. class OneFrameTestSource : public IFrameSource
  9. {
  10. public:
  11. OneFrameTestSource(const Mat &frame)
  12. {
  13. frameNumber_ = 0;
  14. frame_ = frame;
  15. }
  16. virtual void reset() CV_OVERRIDE
  17. {
  18. frameNumber_ = 0;
  19. }
  20. virtual Mat nextFrame() CV_OVERRIDE
  21. {
  22. return (frameNumber_++ == 0) ? frame_ : Mat();
  23. }
  24. private:
  25. int frameNumber_;
  26. Mat frame_;
  27. };
  28. TEST(OnePassStabilizer, oneFrame)
  29. {
  30. Mat frame(2, 3, CV_8UC3);
  31. randu(frame, Scalar::all(0), Scalar::all(255));
  32. OnePassStabilizer stabilizer;
  33. stabilizer.setRadius(10);
  34. stabilizer.setFrameSource(makePtr<OneFrameTestSource>(frame));
  35. Mat stabilizedFrame = stabilizer.nextFrame();
  36. EXPECT_MAT_NEAR(frame, stabilizedFrame, 0);
  37. EXPECT_TRUE(stabilizer.nextFrame().empty());
  38. }
  39. TEST(OnePassStabilizer, oneFrame_deblur)
  40. {
  41. Mat frame(2, 3, CV_8UC3);
  42. randu(frame, Scalar::all(0), Scalar::all(255));
  43. OnePassStabilizer stabilizer;
  44. stabilizer.setRadius(1);
  45. stabilizer.setFrameSource(makePtr<OneFrameTestSource>(frame));
  46. Ptr<WeightingDeblurer> deblurer = makePtr<WeightingDeblurer>();
  47. deblurer->setRadius(10);
  48. stabilizer.setDeblurer(deblurer);
  49. Mat stabilizedFrame = stabilizer.nextFrame();
  50. EXPECT_MAT_NEAR(frame, stabilizedFrame, 0);
  51. EXPECT_TRUE(stabilizer.nextFrame().empty());
  52. }
  53. TEST(TwoPassStabilizer, oneFrame)
  54. {
  55. Mat frame(2, 3, CV_8UC3);
  56. randu(frame, Scalar::all(0), Scalar::all(255));
  57. TwoPassStabilizer stabilizer;
  58. stabilizer.setRadius(10);
  59. stabilizer.setFrameSource(makePtr<OneFrameTestSource>(frame));
  60. Mat stabilizedFrame = stabilizer.nextFrame();
  61. EXPECT_MAT_NEAR(frame, stabilizedFrame, 0);
  62. EXPECT_TRUE(stabilizer.nextFrame().empty());
  63. }
  64. }} // namespace