test_algorithm_rw.py 946 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. """Algorithm serialization test."""
  3. import tempfile
  4. import os
  5. import cv2 as cv
  6. from tests_common import NewOpenCVTests
  7. class algorithm_rw_test(NewOpenCVTests):
  8. def test_algorithm_rw(self):
  9. fd, fname = tempfile.mkstemp(prefix="opencv_python_algorithm_", suffix=".yml")
  10. os.close(fd)
  11. # some arbitrary non-default parameters
  12. gold = cv.AKAZE_create(descriptor_size=1, descriptor_channels=2, nOctaves=3, threshold=4.0)
  13. gold.write(cv.FileStorage(fname, cv.FILE_STORAGE_WRITE), "AKAZE")
  14. fs = cv.FileStorage(fname, cv.FILE_STORAGE_READ)
  15. algorithm = cv.AKAZE_create()
  16. algorithm.read(fs.getNode("AKAZE"))
  17. self.assertEqual(algorithm.getDescriptorSize(), 1)
  18. self.assertEqual(algorithm.getDescriptorChannels(), 2)
  19. self.assertEqual(algorithm.getNOctaves(), 3)
  20. self.assertEqual(algorithm.getThreshold(), 4.0)
  21. os.remove(fname)