# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import unittest from telemetry.util import external_modules try: np = external_modules.ImportRequiredModule('numpy') except ImportError: pass else: class CVUtilTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(CVUtilTest, self).__init__(*args, **kwargs) # Import modules with dependencies that may not be preset in test setup so # that importing this unit test doesn't cause the test runner to raise an # exception. from telemetry.image_processing import cv_util self.cv_util = cv_util def testAreLinesOrthogonalish(self): l1 = np.asfarray((0, 0, 1, 0)) l2 = np.asfarray((0, 0, 0, 1)) self.assertTrue(self.cv_util.AreLinesOrthogonal(l1, l2, 0)) self.assertTrue(self.cv_util.AreLinesOrthogonal(l2, l1, 0)) self.assertFalse(self.cv_util.AreLinesOrthogonal(l1, l1, np.pi / 2 - 1e-10)) self.assertFalse(self.cv_util.AreLinesOrthogonal(l2, l2, np.pi / 2 - 1e-10))
# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from telemetry.image_processing.io import frame_generator from telemetry.util import external_modules cv2 = external_modules.ImportRequiredModule('cv2') class VideoFileFrameGenerator(frame_generator.FrameGenerator): """Provides a Frame Generator for a video file. Sample Usage: generator = VideoFileFrameGenerator(sys.argv[1]).GetGenerator() for frame in generator: # Do something Attributes: _capture: The openCV video capture. _frame_count: The number of frames in the video capture. _frame_index: The frame number of the current frame. _timestamp: The timestamp of the current frame. _dimensions: The dimensions of the video capture.""" def __init__(self, video_filename, start_frame_index=0): """Initializes the VideoFileFrameGenerator object. Args: video_filename: str, The path to the video file. start_frame_index: int, The number of frames to skip at the start of the file.