Ejemplo n.º 1
0
class TestHyperlapse(unittest.TestCase):
    def setUp(self):
        video = Video('/home/victorhugomoura/Documents/example.mp4')

        extractor = 'face'
        velocity = 10

        self.hyperlapse = SemanticHyperlapse(video, extractor, velocity)

    def testExtractor(self):
        self.hyperlapse.checkExtractor()
        self.hyperlapse.extractor = ''
        self.assertRaises(InputError, self.hyperlapse.checkExtractor)

    def testVelocity(self):
        self.hyperlapse.checkAndSetVelocity()
        self.hyperlapse.velocity = ''
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = 'A'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = '1'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)

    def testOpticalFlowCommand(self):
        command = self.hyperlapse.opticalFlowCommand()
        expectedCommand = './optflow -v /home/victorhugomoura/Documents/example.mp4 ' + \
            '-c default-config.xml -o /home/victorhugomoura/Documents/example.csv'

        self.assertEqual(command, expectedCommand)

    def testOpticalFlowExists(self):
        self.assertTrue(self.hyperlapse.opticalFlowExists()
                        )  # works only if the file already exists

    def testCheckVideoInput(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)
        self.hyperlapse.video = Video(
            '/home/victorhugomoura/Documents/example.csv')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)

    def testInputError(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')

        try:
            self.hyperlapse.checkVideoInput()
        except InputError as IE:
            self.assertEqual(IE.__str__(), 'Please insert input video first')
Ejemplo n.º 2
0
class TestHyperlapse(unittest.TestCase):
    def setUp(self):
        video = Video('/home/victorhugomoura/Documents/example.mp4')

        extractor = 'face'
        velocity = 10

        alpha = ['1', '2']
        beta = ['4', '3']
        gama = ['5', '6']
        eta = ['8', '7']

        self.hyperlapse = SemanticHyperlapse(video, extractor, velocity, alpha,
                                             beta, gama, eta)

    def testExtractor(self):
        self.hyperlapse.checkExtractor()
        self.hyperlapse.extractor = ''
        self.assertRaises(InputError, self.hyperlapse.checkExtractor)

    def testVelocity(self):
        self.hyperlapse.checkAndSetVelocity()
        self.hyperlapse.velocity = ''
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = 'A'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = '1'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)

    def testCheckWeights(self):
        self.hyperlapse.checkAndSetWeights()
        self.hyperlapse.alpha = ['', '']
        self.assertRaises(InputError, self.hyperlapse.checkAndSetWeights)
        self.hyperlapse.alpha = ['1', '1']
        self.hyperlapse.beta = ['a', '10']
        self.assertRaises(InputError, self.hyperlapse.checkAndSetWeights)

    def testOpticalFlowCommand(self):
        command = self.hyperlapse.opticalFlowCommand()
        expectedCommand = './optflow -v /home/victorhugomoura/Documents/example.mp4 ' + \
            '-c default-config.xml -o /home/victorhugomoura/Documents/example.csv'

        self.assertEqual(command, expectedCommand)

    def testOpticalFlowExists(self):
        self.assertTrue(self.hyperlapse.opticalFlowExists()
                        )  # works only on Verlab machines

    def testCheckVideoInput(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)
        self.hyperlapse.video = Video(
            '/home/victorhugomoura/Documents/example.csv')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)

    def testCheckParameters(self):
        self.hyperlapse.checkParameters()

    def testInputError(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')

        try:
            self.hyperlapse.checkVideoInput()
        except InputError as IE:
            self.assertEqual(IE.__str__(), 'Please insert input video first')
class TestHyperlapse(unittest.TestCase):
    def setUp(self):
        video = Video()
        video.setVideoFile('/home/victorhugomoura/Documents/example.mp4')
        self.hyperlapse = SemanticHyperlapse()
        self.hyperlapse.setVideo(video)
        self.hyperlapse.setPaths()

    def testVideo(self):
        self.assertIsInstance(self.hyperlapse.getVideo(), Video)

    def testPath(self):
        self.assertEqual(self.hyperlapse.getPath(), os.getcwd())
        self.hyperlapse.setPath('/')
        self.assertEqual(self.hyperlapse.getPath(), '/')

    def testVelocity(self):
        self.assertRaises(InputError, self.hyperlapse.setVelocity, '')
        self.assertRaises(InputError, self.hyperlapse.setVelocity, 'A')
        self.assertRaises(InputError, self.hyperlapse.setVelocity, '1')
        self.hyperlapse.setVelocity('10')
        self.assertEqual(self.hyperlapse.getVelocity(), 10)

    def testMaxVel(self):
        self.hyperlapse.setMaxVel(100.0)
        self.assertEqual(self.hyperlapse.getMaxVel(), 100)

    def testCheckWeights(self):
        self.assertRaises(ValueError, self.hyperlapse.convertWeights, ['', ''])
        self.assertRaises(ValueError, self.hyperlapse.convertWeights,
                          ['a', '10'])
        self.assertRaises(InputError, self.hyperlapse.checkAndSetWeights,
                          ['', ''])
        self.assertListEqual(self.hyperlapse.checkAndSetWeights(['10', '10']),
                             [10, 10])

    def testWeights(self):
        self.hyperlapse.setAlpha(['50', '50'])
        self.hyperlapse.setBeta(['20', '20'])
        self.hyperlapse.setGama(['30', '30'])
        self.hyperlapse.setEta(['40', '50'])

        self.assertListEqual(self.hyperlapse.getAlpha(), [50, 50])
        self.assertListEqual(self.hyperlapse.getBeta(), [20, 20])
        self.assertListEqual(self.hyperlapse.getGama(), [30, 30])
        self.assertListEqual(self.hyperlapse.getEta(), [40, 50])

    def testOpticalFlowCommand(self):
        command = self.hyperlapse.opticalFlowCommand()
        expectedCommand = './optflow -v /home/victorhugomoura/Documents/example.mp4 ' + \
            '-c default-config.xml -o /home/victorhugomoura/Documents/example.csv'

        self.assertEqual(command, expectedCommand)

    def testCheckVideoInput(self):
        self.hyperlapse.getVideo().setVideoFile('')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)

        self.hyperlapse.getVideo().setVideoFile(
            '/home/victorhugomoura/Documents/example.csv')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)

    def testSetup(self):
        alpha = ['1', '2']
        beta = ['4', '3']
        gama = ['5', '6']
        eta = ['8', '7']
        speed = '10'

        # check if it don't raise an exception
        self.hyperlapse.setup(speed, alpha, beta, gama, eta)

        speed = '1'
        self.assertRaises(InputError, self.hyperlapse.setup, speed, alpha,
                          beta, gama, eta)

    def testInputError(self):
        self.hyperlapse.getVideo().setVideoFile('')

        try:
            self.hyperlapse.checkVideoInput()
        except InputError as IE:
            self.assertEqual(IE.__str__(), 'Please insert input video first')
class TestHyperlapse(unittest.TestCase):
    def setUp(self):
        video = Video('/home/victorhugomoura/Documents/example.mp4')

        extractor = 'face'
        velocity = 10

        self.hyperlapse = SemanticHyperlapse(video, extractor, velocity)

    def testExtractor(self):
        self.hyperlapse.checkExtractor()
        self.hyperlapse.extractor = ''
        self.assertRaises(InputError, self.hyperlapse.checkExtractor)

    def testVelocity(self):
        self.hyperlapse.checkAndSetVelocity()
        self.hyperlapse.velocity = ''
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = 'A'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)
        self.hyperlapse.velocity = '1'
        self.assertRaises(InputError, self.hyperlapse.checkAndSetVelocity)

    def testOpticalFlowCommand(self):
        command = self.hyperlapse.opticalFlowCommand()
        expectedCommand = './optflow -v /home/victorhugomoura/Documents/example.mp4 ' + \
            '-c default-config.xml -o /home/victorhugomoura/Documents/example.csv'

        self.assertEqual(command, expectedCommand)

    def testDarknetCommand(self):
        command = self.hyperlapse.darknetCommand()
        expectedCommand = './darknet detector demo cfg/coco.data cfg/yolo.cfg '\
            + 'yolo.weights /home/victorhugomoura/Documents/example.mp4 ' \
            + '/home/victorhugomoura/Documents/example_yolo_raw.txt'
        self.assertEqual(command, expectedCommand)

        self.hyperlapse.video = Video(
            '/home/victorhugomoura/Documents/teste.mp4')
        command = self.hyperlapse.darknetCommand()
        expectedCommand = './darknet detector demo cfg/coco.data cfg/yolo.cfg '\
            + 'yolo.weights /home/victorhugomoura/Documents/teste.mp4 ' \
            + '/home/victorhugomoura/Documents/teste_yolo_raw.txt'
        self.assertEqual(command, expectedCommand)

    def testCheckVideoInput(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)
        self.hyperlapse.video = Video(
            '/home/victorhugomoura/Documents/example.csv')
        self.assertRaises(InputError, self.hyperlapse.checkVideoInput)

    def testInputError(self):
        self.hyperlapse.checkVideoInput()
        self.hyperlapse.video = Video('')

        try:
            self.hyperlapse.checkVideoInput()
        except InputError as IE:
            self.assertEqual(IE.__str__(), 'Please insert input video first')