def __init__(self, class_names, weight_path, input_shape):
        self.class_names = class_names
        self.num_classes = len(class_names)
        self.input_shape = input_shape
        self.model = SSD(self.input_shape, num_classes=self.num_classes)
        self.model.load_weights(weight_path)
        self.model._make_predict_function()
        self.bbox_util = BBoxUtility(self.num_classes)
        #self.timer = Timer(1, self.timer_callback)
        #self.current_time = 0
        # self.current_fps = 0
        #self.exec_time = None
        #self.prev_extra_time = None
        #self.extra_time = None
        # self.fps_time_slot = list()
        #self.is_finish = False
        #self.fps_start = False
        #self.fps_start_time = 0

        # Create unique and somewhat visually distinguishable bright
        # colors for the different classes.
        self.class_colors = []
        for i in range(0, self.num_classes):
            # This can probably be written in a more elegant manner
            hue = 255 * i / self.num_classes
            col = np.zeros((1, 1, 3)).astype("uint8")
            col[0][0][0] = hue
            col[0][0][1] = 128  # Saturation
            col[0][0][2] = 255  # Value
            cvcol = cv2.cvtColor(col, cv2.COLOR_HSV2BGR)
            col = (int(cvcol[0][0][0]), int(cvcol[0][0][1]),
                   int(cvcol[0][0][2]))
            self.class_colors.append(col)
Esempio n. 2
0
    def __init__(self, class_names, model, input_shape):
        self.class_names = class_names
        self.num_classes = len(class_names)
        self.model = model
        self.input_shape = input_shape
        self.bbox_util = BBoxUtility(self.num_classes)

        # Create unique and somewhat visually distinguishable bright
        # colors for the different classes.
        self.class_colors = []
        for i in range(0, self.num_classes):
            # This can probably be written in a more elegant manner
            hue = 255 * i / self.num_classes
            col = np.zeros((1, 1, 3)).astype("uint8")
            col[0][0][0] = hue
            col[0][0][1] = 128  # Saturation
            col[0][0][2] = 255  # Value
            cvcol = cv2.cvtColor(col, cv2.COLOR_HSV2BGR)
            col = (int(cvcol[0][0][0]), int(cvcol[0][0][1]),
                   int(cvcol[0][0][2]))
            self.class_colors.append(col)