Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

93 Zeilen
3.3 KiB

  1. """test_feature_extractors_functional.py -- functional tests for feature extractors
  2. This module contains functional tests for FEs using crafted and/or generated media files
  3. to verify that the FEs are working as expected:
  4. - laughter detection -- uses videos with laughs at known times
  5. - video activity -- uses videos with visual activity at known times
  6. - audio loudness -- uses videos with audio at known times
  7. etc.
  8. These tests are marked slow to avoid running them during normal test runs.
  9. """
  10. import unittest
  11. import pipeline.feature_extractors as extractors
  12. import test.mocks as mocks
  13. class FEFunctionalTest(unittest.TestCase):
  14. """FEFunctionalTest -- base class for functional tests for feature extractors
  15. """
  16. SAMPLE_DIR = "/home/robert/code/softdev2023-24/summerproject/highlights/test/sample_videos"
  17. class TestVideoActivityFEFunctional(FEFunctionalTest):
  18. """TestVisualActivityFEFunctional -- functional tests for visual activity feature extractor
  19. """
  20. def test_visual_activity_functional(self):
  21. """Test visual activity feature extractor
  22. use:
  23. - sample_videos/sample-manual-visualactivity.mp4 :: activity at 15-20s -- pass if activity detected anywhere in this range
  24. """
  25. SAMPLE_VIDEO = f"{self.SAMPLE_DIR}/sample-manual-visualactivity.mp4"
  26. START_TIME = 15
  27. END_TIME = 20
  28. # create mock source with the video
  29. source = mocks.MockSource(path=SAMPLE_VIDEO)
  30. # create the feature extractor
  31. testfe = extractors.VideoActivityFeatureExtractor(input_files=[source])
  32. testfe.setup()
  33. testfe.run()
  34. testfe.teardown()
  35. # check if the feature was extracted:
  36. self.assertTrue(testfe.features)
  37. # check if the feature interval is within the expected range
  38. self.assertTrue(testfe.features[0].interval.start >= START_TIME)
  39. class TestLoudAudioFEFunctional(FEFunctionalTest):
  40. """TestAudioLoudnessFEFunctional -- functional tests for audio loudness feature extractor
  41. """
  42. def test_audio_loudness_functional_one_feature(self):
  43. """Test audio loudness feature extractor
  44. use:
  45. - sample_videos/sample-manual-audio.mp4 :: audio at 15-20s -- pass if audio detected anywhere in this range
  46. -- peak at 16s - 18s, verify this is highest scoring
  47. """
  48. SAMPLE_VIDEO = f"{self.SAMPLE_DIR}/sample-manual-audio.mp4"
  49. START_TIME = 15
  50. END_TIME = 20
  51. PEAK_START = 16
  52. PEAK_END = 18
  53. # create mock source with the video
  54. source = mocks.MockSource(path=SAMPLE_VIDEO)
  55. # create the feature extractor
  56. testfe = extractors.LoudAudioFeatureExtractor(input_files=[source])
  57. testfe.setup()
  58. testfe.run()
  59. testfe.teardown()
  60. # check if the feature was extracted:
  61. self.assertTrue(testfe.features)
  62. # check if the feature interval is within the expected range
  63. self.assertTrue(testfe.features[0].interval.start >= START_TIME)
  64. # get sorted list of features based on feature.score
  65. sorted_features = sorted(testfe.features, key=lambda x: x.score, reverse=True)
  66. # check if the highest scoring feature is within the peak range
  67. self.assertTrue(sorted_features[0].interval.start >= PEAK_START)
  68. if __name__ == "__main__":
  69. unittest.main()