Beispiel #1
0
    def test_add_to_history_two_target(self):
        self.history.add_to_history('blue', (0, 0, 10, 10))
        self.history.add_to_history('green', (0, 0, 10, 11))
        self.history.add_to_history('red', (30, 30, 10, 12))

        interp1 = HistoryInterpreter()
        interp1.process("blue")
        interp1.process("green")
        expected1 = {
            "last_pos": (0, 0, 10, 11),
            "last_frame": 1,
            "history_interpreter": interp1,
            "history": ["blue", "green"]
        }

        interp2 = HistoryInterpreter()
        interp2.process("red")
        expected2 = {
            "last_pos": (30, 30, 10, 12),
            "last_frame": 2,
            "history_interpreter": interp2,
            "history": ["red"]
        }
        expected = [expected1, expected2]

        self.compare_history(self.history.history[0], expected[0])
        self.compare_history(self.history.history[1], expected[1])
Beispiel #2
0
 def _create_history_entry(self, detected, box): 
     interp = HistoryInterpreter(self.frame_complete_callback, str(box))
     interp.max_buffer_size = BUFFER_SIZE
     interp.process(detected)
     return {"last_pos": box,
             "last_frame": self.frame,
             "history_interpreter": interp,
             "history":[detected]}
Beispiel #3
0
    def test_equal(self):
        comp = HistoryInterpreter()

        self.assertEqual(self.hi, comp)

        comp.process("blue")
        self.assertNotEqual(self.hi, comp)

        self.hi.process("blue")
        self.assertEqual(self.hi, comp)
Beispiel #4
0
    def test_add_to_history_single_target(self):
        interp = HistoryInterpreter()
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('green', (0, 1, 10, 11), interp)
        interp = self.helper_add_to_history('red', (0, 2, 10, 12), interp)

        expected = {
            "last_pos": (0, 2, 10, 12),
            "last_frame": 2,
            "history_interpreter": interp,
            "history": ["blue", "green", "red"]
        }
        actual = self.history.history[0]

        self.compare_history(actual, expected)
Beispiel #5
0
    def test_trigger_frame_complete(self):
        interp = HistoryInterpreter()

        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('red', (0, 1, 10, 12), interp)
        interp = self.helper_add_to_history('red', (0, 1, 10, 12), interp)
        interp = self.helper_add_to_history('red', (0, 1, 10, 12), interp)
        interp = self.helper_add_to_history('red', (0, 1, 10, 12), interp)
        interp = self.helper_add_to_history('green', (0, 1, 10, 11), interp)
        interp = self.helper_add_to_history('green', (0, 1, 10, 11), interp)
        interp = self.helper_add_to_history('green', (0, 1, 10, 11), interp)
        interp = self.helper_add_to_history('green', (0, 1, 10, 11), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)
        interp = self.helper_add_to_history('blue', (0, 0, 10, 10), interp)

        expected = {
            "last_pos": (0, 0, 10, 10),
            "last_frame":
            15,
            "history_interpreter":
            interp,
            "history": [
                "blue",
                "blue",
                "blue",
                "blue",
                "red",
                "red",
                "red",
                "red",
                "green",
                "green",
                "green",
                "green",
                "blue",
                "blue",
                "blue",
                "blue",
            ]
        }

        actual = self.history.history[0]
        self.compare_history(actual, expected)
Beispiel #6
0
    def test_update_history(self):

        interp = HistoryInterpreter()

        start = {
            "last_pos": (0, 0, 10, 12),
            "last_frame": 0,
            "history_interpreter": interp,
            "history": ["blue"]
        }

        expected = {
            "last_pos": (1, 1, 10, 12),
            "last_frame": 0,
            "history_interpreter": interp,
            "history": ["blue", "green"]
        }

        new = self.history._update_history_entry(start, "green",
                                                 (1, 1, 10, 12))

        self.compare_history(new, expected)
Beispiel #7
0
 def setUp(self):
     self.hi = HistoryInterpreter()
Beispiel #8
0
class TestHistoryInterpreter(unittest.TestCase):
    def setUp(self):
        self.hi = HistoryInterpreter()

    def test_equal(self):
        comp = HistoryInterpreter()

        self.assertEqual(self.hi, comp)

        comp.process("blue")
        self.assertNotEqual(self.hi, comp)

        self.hi.process("blue")
        self.assertEqual(self.hi, comp)

    def test_process_clean(self):
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "red",
            "red",
            "red",
            "red",
            "green",
            "green",
            "green",
            "green",
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]
        expected = [1, 0, 1]

        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_process_missed_frame(self):
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",  # missing frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]
        expected = [0, 1]

        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_process_flipped_frame(self):
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "red",  # Flipped frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]
        expected = [0, 1]

        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_process_extra_frame(self):
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "green",
            "green",  # Extra frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]
        expected = [0, 1]

        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_process_unexpected_sentinel(self):
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "green",
            "blue",  # Extra frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]
        expected = [0, 1]

        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_process_unexpected_sentinel2(self):
        self.hi.output = []
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "blue",  # Extra frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]

        expected = [0, 1]
        self.hi.process_batch(test)
        self.assertEqual(self.hi.output, expected)

    def test_pop_output(self):
        self.hi.output = []
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "blue",  # Extra frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "blue",
        ]

        expected = [0, 1]
        self.hi.process_batch(test)
        self.assertEqual(self.hi.pop_output(), expected)
        self.assertEqual(self.hi.output, [])

    def test_change_to_detected(self):
        self.hi.output = []
        test = [
            "green",
            "green",
            "blue",
            "blue",
            "blue",
            "blue",
            "green",
            "green",
            "green",
            "blue",  # Extra frame here
            "red",
            "red",
            "red",
            "red",
            "blue",
            "blue",
            "blue",
            "red",
        ]

        expected = [0, 1]
        self.hi.process_batch(test)
        self.assertEqual(self.hi.pop_output(), expected)
        self.assertEqual(self.hi.state, HistoryInterpreter.DETECTED)