File size: 1,726 Bytes
d015578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


class Processor:
    def __init__(self):
        self.attributes = []

    def process_frame(self, frame, tracked_obj):
        """
        Process tracked objects to extract interesting features.
        :param frame: OpenCV image.
        :param tracked_obj: List with the objects to be processed.
        """
        raise NotImplementedError()

    def plot_features(self, image, features, plotter, show_attributes):
        """
        Visualize objects detected in the input image.
        :param image: OpenCV image.
        :param features: List of object features detect after processing the frame.
        :param plotter: Plotter interface.
        :param show_attributes: Selected object attributes to be displayed.
        """
        raise NotImplementedError()


class EmptyProcessor(Processor):
    def __init__(self):
        super().__init__()

    def process_frame(self, frame, tracked_obj):
        return tracked_obj

    def plot_features(self, image, features, plotter, show_attributes):
        return image


class ProcessorsGroup(Processor):
    def __init__(self):
        super().__init__()
        self.group = []

    def process_frame(self, frame, tracked_obj):
        for elem in self.group:
            tracked_obj = elem.process_frame(frame, tracked_obj)
        return tracked_obj

    def plot_features(self, image, features, plotter, show_attributes):
        for elem in self.group:
            image = elem.plot_features(image, features, plotter, show_attributes)
        return image

    def add_processor(self, processor):
        self.group.append(processor)
        self.attributes += processor.attributes

    def get_number_of_processors(self):
        return len(self.group)