test_stitcher.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import unittest
  2. import os
  3. import sys
  4. import numpy as np
  5. import cv2 as cv
  6. sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
  7. '..', '..')))
  8. from opencv_stitching.stitcher import Stitcher
  9. # %%
  10. class TestStitcher(unittest.TestCase):
  11. def test_stitcher_aquaduct(self):
  12. stitcher = Stitcher(nfeatures=250)
  13. result = stitcher.stitch(["s1.jpg", "s2.jpg"])
  14. cv.imwrite("result.jpg", result)
  15. max_image_shape_derivation = 3
  16. np.testing.assert_allclose(result.shape[:2],
  17. (700, 1811),
  18. atol=max_image_shape_derivation)
  19. @unittest.skip("skip boat test (high resuolution ran >30s)")
  20. def test_stitcher_boat1(self):
  21. settings = {"warper_type": "fisheye",
  22. "wave_correct_kind": "no",
  23. "finder": "dp_colorgrad",
  24. "compensator": "no",
  25. "confidence_threshold": 0.3}
  26. stitcher = Stitcher(**settings)
  27. result = stitcher.stitch(["boat5.jpg", "boat2.jpg",
  28. "boat3.jpg", "boat4.jpg",
  29. "boat1.jpg", "boat6.jpg"])
  30. cv.imwrite("boat_fisheye.jpg", result)
  31. max_image_shape_derivation = 600
  32. np.testing.assert_allclose(result.shape[:2],
  33. (14488, 7556),
  34. atol=max_image_shape_derivation)
  35. @unittest.skip("skip boat test (high resuolution ran >30s)")
  36. def test_stitcher_boat2(self):
  37. settings = {"warper_type": "compressedPlaneA2B1",
  38. "finder": "dp_colorgrad",
  39. "compensator": "channel_blocks",
  40. "confidence_threshold": 0.3}
  41. stitcher = Stitcher(**settings)
  42. result = stitcher.stitch(["boat5.jpg", "boat2.jpg",
  43. "boat3.jpg", "boat4.jpg",
  44. "boat1.jpg", "boat6.jpg"])
  45. cv.imwrite("boat_plane.jpg", result)
  46. max_image_shape_derivation = 600
  47. np.testing.assert_allclose(result.shape[:2],
  48. (7400, 12340),
  49. atol=max_image_shape_derivation)
  50. def test_stitcher_boat_aquaduct_subset(self):
  51. settings = {"final_megapix": 1, "crop": True}
  52. stitcher = Stitcher(**settings)
  53. result = stitcher.stitch(["boat5.jpg",
  54. "s1.jpg", "s2.jpg",
  55. "boat2.jpg",
  56. "boat3.jpg", "boat4.jpg",
  57. "boat1.jpg", "boat6.jpg"])
  58. cv.imwrite("subset_low_res.jpg", result)
  59. max_image_shape_derivation = 100
  60. np.testing.assert_allclose(result.shape[:2],
  61. (705, 3374),
  62. atol=max_image_shape_derivation)
  63. def test_stitcher_budapest(self):
  64. settings = {"matcher_type": "affine",
  65. "estimator": "affine",
  66. "adjuster": "affine",
  67. "warper_type": "affine",
  68. "wave_correct_kind": "no",
  69. "confidence_threshold": 0.3}
  70. stitcher = Stitcher(**settings)
  71. result = stitcher.stitch(["budapest1.jpg", "budapest2.jpg",
  72. "budapest3.jpg", "budapest4.jpg",
  73. "budapest5.jpg", "budapest6.jpg"])
  74. cv.imwrite("budapest.jpg", result)
  75. max_image_shape_derivation = 50
  76. np.testing.assert_allclose(result.shape[:2],
  77. (1155, 2310),
  78. atol=max_image_shape_derivation)
  79. def starttest():
  80. unittest.main()
  81. if __name__ == "__main__":
  82. starttest()