Example #1
0
 def get_feature_map(self, im_patch, hog_cell_sz):
     hog_feature = extract_hog_feature(im_patch,
                                       cell_size=hog_cell_sz)[:, :, :27]
     if hog_cell_sz > 1:
         im_patch = self.mex_resize(
             im_patch,
             (self._window.shape[1], self._window.shape[0])).astype(
                 np.uint8)
     gray = cv2.cvtColor(im_patch,
                         cv2.COLOR_BGR2GRAY)[:, :, np.newaxis] / 255 - 0.5
     return np.concatenate((gray, hog_feature), axis=2)
Example #2
0
def get_csr_features(img, center, scale, template_sz, resize_sz, cell_size):
    center = (int(center[0]), int(center[1]))
    patch = cv2.getRectSubPix(img,
                              patchSize=(int(scale * template_sz[0]),
                                         int(scale * template_sz[1])),
                              center=center)
    patch = cv2.resize(patch, resize_sz).astype(np.uint8)
    hog_feature = extract_hog_feature(patch, cell_size)[:, :, :18]
    # gray feature is included in the cn features
    cn_feature = extract_cn_feature(patch, cell_size)
    features = np.concatenate((hog_feature, cn_feature), axis=2)
    return features
Example #3
0
 def get_scale_subwindow(self, im, center, base_target_sz, scale_factors, scale_window, scale_model_sz,
                         hog_scale_cell_sz):
     n_scales = len(self.scale_factors)
     out = None
     for s in range(n_scales):
         patch_sz = (int(base_target_sz[0] * scale_factors[s]),
                     int(base_target_sz[1] * scale_factors[s]))
         patch_sz = (max(2, patch_sz[0]), max(2, patch_sz[1]))
         im_patch = cv2.getRectSubPix(im, patch_sz, center)
         im_patch_resized = self.mex_resize(im_patch, scale_model_sz).astype(np.uint8)
         tmp = extract_hog_feature(im_patch_resized, cell_size=hog_scale_cell_sz)
         if out is None:
             out = tmp.flatten() * scale_window[s]
         else:
             out = np.c_[out, tmp.flatten() * scale_window[s]]
     return out
Example #4
0
 def update(self, im, pos, base_target_sz, current_scale_factor):
     patchL = cv2.getRectSubPix(
         im, (int(np.floor(current_scale_factor * self.scale_sz[0])),
              int(np.floor(current_scale_factor * self.scale_sz[1]))), pos)
     patchL = cv2.resize(patchL, self.scale_sz_window)
     # convert into logpolar
     patchLp = cv2.logPolar(patchL.astype(np.float32),
                            ((patchL.shape[1] - 1) / 2,
                             (patchL.shape[0] - 1) / 2),
                            self.mag,
                            flags=cv2.INTER_LINEAR + cv2.WARP_FILL_OUTLIERS)
     patchLp = extract_hog_feature(patchLp, cell_size=4)
     tmp_sc, _, _ = self.estimate_scale(self.model_patchLp, patchLp,
                                        self.mag)
     tmp_sc = np.clip(tmp_sc, a_min=0.6, a_max=1.4)
     scale_factor = current_scale_factor * tmp_sc
     self.model_patchLp = (
         1 - self.learning_rate_scale
     ) * self.model_patchLp + self.learning_rate_scale * patchLp
     return scale_factor
Example #5
0
    def _extract_scale_sample(self, im, pos, base_target_sz, scale_factors,
                              scale_model_sz):
        scale_sample = []
        base_target_sz = np.array([base_target_sz[0], base_target_sz[1]])
        for idx, scale in enumerate(scale_factors):
            patch_sz = np.floor(base_target_sz * scale)
            im_patch = cv2.getRectSubPix(im,
                                         (int(patch_sz[0]), int(patch_sz[1])),
                                         pos)
            if scale_model_sz[0] > patch_sz[1]:
                interpolation = cv2.INTER_LINEAR
            else:
                interpolation = cv2.INTER_AREA

            im_patch_resized = cv2.resize(
                im_patch, (int(scale_model_sz[0]), int(scale_model_sz[1])),
                interpolation=interpolation).astype(np.uint8)
            scale_sample.append(
                extract_hog_feature(im_patch_resized, cell_size=4).reshape(
                    (-1, 1)))
        scale_sample = np.concatenate(scale_sample, axis=1)
        return scale_sample
Example #6
0
    def init(self, im, pos, base_target_sz, current_scale_factor):
        w, h = base_target_sz
        avg_dim = (w + h) / 2.5
        self.scale_sz = ((w + avg_dim) / current_scale_factor,
                         (h + avg_dim) / current_scale_factor)
        self.scale_sz0 = self.scale_sz
        self.cos_window_scale = cos_window(
            (self.scale_sz_window[0], self.scale_sz_window[1]))
        self.mag = self.cos_window_scale.shape[0] / np.log(
            np.sqrt((self.cos_window_scale.shape[0]**2 +
                     self.cos_window_scale.shape[1]**2) / 4))

        # scale lp
        patchL = cv2.getRectSubPix(
            im, (int(np.floor(current_scale_factor * self.scale_sz[0])),
                 int(np.floor(current_scale_factor * self.scale_sz[1]))), pos)
        patchL = cv2.resize(patchL, self.scale_sz_window)
        patchLp = cv2.logPolar(patchL.astype(np.float32),
                               ((patchL.shape[1] - 1) / 2,
                                (patchL.shape[0] - 1) / 2),
                               self.mag,
                               flags=cv2.INTER_LINEAR + cv2.WARP_FILL_OUTLIERS)

        self.model_patchLp = extract_hog_feature(patchLp, cell_size=4)