Ejemplo n.º 1
0
    def get_featuremap(self, frame, new_x1, new_y1, new_x2, new_y2, scale):
        """Important slice operation"""
        # pad_scale_roi = frame[max(new_y1, 0):new_y2+1, max(new_x1,0):new_x2 + 1]
        pad_scale_roi = get_border_roi(new_x1, new_y1, new_x2, new_y2, frame)

        if scale != 1.0:
            half_w = (new_x2 - new_x1 + 1) / 2 * (scale - 1)
            half_h = (new_y2 - new_y1 + 1) / 2 * (scale - 1)

            new_x1 = int(np.ceil(new_x1 - half_w))
            new_y1 = int(np.ceil(new_y1 - half_h))
            new_x2 = int(np.floor(new_x2 + half_w))
            new_y2 = int(np.floor(new_y2 + half_h))

            """Important slice operation"""
            # pad_scale_roi = frame[max(new_y1, 0):new_y2+1, max(new_x1, 0):new_x2+1]  # frame follow H x W sequenc
            pad_scale_roi = get_border_roi(new_x1, new_y1, new_x2, new_y2, frame)


        if self.pad != 0:
            half_w = (new_x2 - new_x1 + 1) / 2 * (self.pad - 1)
            half_h = (new_y2 - new_y1 + 1) / 2 * (self.pad - 1)

            tmp_x1 = int(np.ceil(new_x1 - half_w))
            tmp_y1 = int(np.ceil(new_y1 - half_h))
            tmp_x2 = int(np.floor(new_x2 + half_w))
            tmp_y2 = int(np.floor(new_y2 + half_h))

            """Important slice operation"""
            # pad_scale_roi = frame[max(tmp_y1, 0):tmp_y2+1, max(tmp_x1, 0):tmp_x2+1]  # frame fol
            pad_scale_roi = get_border_roi(tmp_x1, tmp_y1, tmp_x2, tmp_y2, frame, i=2)

        fix_roi = cv2.resize(pad_scale_roi, dsize=(self.fixed_size[1], self.fixed_size[1]))  # dsize follow W x H (64x64)
        fix_roi = np.asarray(fix_roi, dtype=np.float)  # np.array
        fix_roi = fix_roi / 255.0 - 0.5          # normalize
        fix_roi = np.power(fix_roi, self.gamma)  # gamma correct
        fix_roi = fix_roi * self.hann            # Hanning filter

        if self.hog:
            fix_roi = fix_roi + 0.5
            hog = HOG(window=fix_roi, cell_size=4, bin_size=8, gamma=1.0)
            self.adapt = 0.1
            hog.init_mag_angle()
            fix_roi = hog.get_window_grad()

        return fix_roi, [new_x1, new_y1, new_x2, new_y2]