예제 #1
0
    def test_display_class_not_in_threshold(self, mock_put_text):
        test_display = base_display.DisplayClassnameOverlay(
            thresholds={'Dabbing': 0.5})
        test_display.display(self.img,
                             {'sorted_predictions': [['Nodding', 1.0]]})

        mock_put_text.assert_not_called()
예제 #2
0
    def test_display_default_within_duration(self, mock_display_class_name):
        test_display = base_display.DisplayClassnameOverlay(
            thresholds={'Dabbing': 0.5}, duration=self.duration)

        # Set start time and call display once
        test_display.display(self.img,
                             {'sorted_predictions': [['Dabbing', 0.51]]})
        mock_display_class_name.assert_called_with(self.img, 'Dabbing')
        assert mock_display_class_name.call_count == 1

        # Class name will continue to be displayed during the duration even if input is below threshold
        with patch("sense.display.DisplayClassnameOverlay._get_current_time",
                   return_value=test_display._start_time + self.half_duration):
            test_display.display(self.img,
                                 {'sorted_predictions': [['Dabbing', 0.49]]})
            assert mock_display_class_name.call_count == 2

        # Call display post the duration
        with patch("sense.display.DisplayClassnameOverlay._get_current_time",
                   return_value=test_display._start_time + self.duration):
            # Display nothing after duration has passed
            test_display.display(self.img,
                                 {'sorted_predictions': [['Dabbing', 0.49]]})
            # Total call counts should remain the same
            assert mock_display_class_name.call_count == 2
예제 #3
0
    def test_display_default(self, mock_put_text):
        test_display = base_display.DisplayClassnameOverlay(thresholds={'Dabbing': 0.5})
        test_display.display(self.img, {'sorted_predictions': [['Dabbing', 0.6]]})

        mock_put_text.assert_called_with(self.img,
                                         'Dabbing',
                                         font_scale=self.font_scale,
                                         position=(224, 294),
                                         thickness=self.thickness)
예제 #4
0
    def test_display_adjust_font_scale(self, mock_put_text):
        test_display = base_display.DisplayClassnameOverlay(thresholds={'Swiping down (with two hands)': 0.5})
        test_display.display(self.img, {'sorted_predictions': [['Swiping down (with two hands)', 0.6]]})

        text_width = getTextSize('Swiping down (with two hands)', FONT_HERSHEY_PLAIN, self.font_scale,
                                 self.thickness)[0][0]
        _, frame_width, _ = self.img.shape
        font_scale = self.font_scale / (text_width / frame_width)

        mock_put_text.assert_called_with(self.img,
                                         'Swiping down (with two hands)',
                                         font_scale=font_scale,
                                         position=(0, 291),
                                         thickness=self.thickness)