def init(self, first_frame, bbox): first_frame = first_frame.astype(np.float32) bbox = np.array(bbox).astype(np.int64) x, y, w, h = tuple(bbox) self._center = (x + w / 2, y + h / 2) self.w, self.h = w, h self.crop_size = (int(w * (1 + self.padding)), int(h * (1 + self.padding))) self.base_target_size = (self.w, self.h) self.target_sz = (self.w, self.h) self._window = cos_window(self.crop_size) output_sigma = np.sqrt(self.w * self.h) * self.output_sigma_factor self.y = gaussian2d_labels(self.crop_size, output_sigma) self._init_response_center = np.unravel_index( np.argmax(self.y, axis=None), self.y.shape) self.yf = fft2(self.y) self.current_scale_factor = 1. xl = self.get_translation_sample(first_frame, self._center, self.crop_size, self.current_scale_factor, self._window) self.xlf = fft2(xl) self.hf_den = np.sum(self.xlf * np.conj(self.xlf), axis=2) self.hf_num = self.yf[:, :, None] * np.conj(self.xlf) #带入以后响应的计算公式 if self.scale_type == 'normal': self.scale_estimator = DSSTScaleEstimator( self.target_sz, config=self.scale_config) #多尺度估计 self.scale_estimator.init(first_frame, self._center, self.base_target_size, self.current_scale_factor) self._num_scales = self.scale_estimator.num_scales #17 self._scale_step = self.scale_estimator.scale_step #1.02 self._min_scale_factor = self._scale_step**np.ceil( np.log( np.max(5 / np.array( ([self.crop_size[0], self.crop_size[1]])))) / np.log(self._scale_step)) self._max_scale_factor = self._scale_step**np.floor( np.log( np.min(first_frame.shape[:2] / np.array( [self.base_target_size[1], self.base_target_size[0]]))) / np.log(self._scale_step)) elif self.scale_type == 'LP': self.scale_estimator = LPScaleEstimator(self.target_sz, config=self.scale_config) self.scale_estimator.init(first_frame, self._center, self.base_target_size, self.current_scale_factor)
def init(self, first_frame, bbox): first_frame = first_frame.astype(np.float32) bbox = np.array(bbox).astype(np.int64) x, y, w, h = tuple(bbox) self._center = (x + w / 2, y + h / 2) self.w, self.h = w, h self.crop_size = (int(w * (1 + self.padding)), int(h * (1 + self.padding))) self.base_target_size = (self.w, self.h) self.target_sz = (self.w, self.h) self._window = cos_window(self.crop_size) output_sigma = np.sqrt(self.w * self.h) * self.output_sigma_factor self.y = gaussian2d_labels(self.crop_size, output_sigma) self._init_response_center = np.unravel_index( np.argmax(self.y, axis=None), self.y.shape) self.yf = fft2(self.y) patch = self.get_sub_window(first_frame, self._center, self.crop_size, self.sc) xl = self.get_feature_map(patch) xl = xl * self._window[:, :, None] self.xlf = fft2(xl) self.hf_den = np.sum(self.xlf * np.conj(self.xlf), axis=2) self.hf_num = self.yf[:, :, None] * np.conj(self.xlf) avg_dim = (w + h) / 2.5 self.scale_sz = ((w + avg_dim) / self.sc, (h + avg_dim) / self.sc) 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(first_frame, (int(np.floor(self.sc * self.scale_sz[0])), int(np.floor(self.sc * self.scale_sz[1]))), self._center) 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)
def init(self,first_frame,bbox): if len(first_frame.shape)==3: assert first_frame.shape[2]==3 first_frame=cv2.cvtColor(first_frame,cv2.COLOR_BGR2GRAY) first_frame=first_frame.astype(np.float32) bbox=np.array(bbox).astype(np.int64) x,y,w,h=tuple(bbox) self._center=(x+w/2,y+h/2) self.w,self.h=w,h self._window=cos_window((int(round(2*w)),int(round(2*h)))) self.crop_size=(int(round(2*w)),int(round(2*h))) self.x=cv2.getRectSubPix(first_frame,(int(round(2*w)),int(round(2*h))),self._center)/255-0.5 self.x=self.x*self._window s=np.sqrt(w*h)/16 self.y=gaussian2d_labels((int(round(2*w)),int(round(2*h))),s) self._init_response_center=np.unravel_index(np.argmax(self.y,axis=None),self.y.shape) self.alphaf=self._training(self.x,self.y)
def init(self,first_frame,bbox): bbox=np.array(bbox).astype(np.int64) x,y,w,h=tuple(bbox) self._center=(x+w/2,y+h/2) self.w,self.h=w,h self._window=cos_window((int(w*(1+self.padding)),int(h*(1+self.padding)))) self.crop_size=(self._window.shape[1],self._window.shape[0]) s=np.sqrt(w*h)*self.output_sigma_factor self.y=gaussian2d_labels(self.crop_size,s) self.yf=fft2(self.y) self._init_response_center=np.unravel_index(np.argmax(self.y,axis=None),self.y.shape) self.x=self.get_sub_window(first_frame, self._center, self.crop_size) self.x=self._window[:,:,None]*self.x kf=fft2(self._dgk(self.x,self.x)) self.alphaf_num=(self.yf)*kf self.alphaf_den=kf*(kf+self.lambda_)
def init(self, first_frame, bbox): if len(first_frame.shape) != 2: assert first_frame.shape[2] == 3 first_frame = cv2.cvtColor(first_frame, cv2.COLOR_BGR2GRAY) first_frame = first_frame.astype(np.float32) / 255 x, y, w, h = tuple(bbox) self._center = (x + w / 2, y + h / 2) self.w, self.h = w, h w, h = int(round(w)), int(round(h)) self.cos_window = cos_window((w, h)) self._fi = cv2.getRectSubPix(first_frame, (w, h), self._center) self._G = np.fft.fft2(gaussian2d_labels((w, h), self.sigma)) self.crop_size = (w, h) self._Ai = np.zeros_like(self._G) self._Bi = np.zeros_like(self._G) for _ in range(8): fi = self._rand_warp(self._fi) Fi = np.fft.fft2(self._preprocessing(fi, self.cos_window)) self._Ai += self._G * np.conj(Fi) self._Bi += Fi * np.conj(Fi)
def init(self, first_frame, bbox): first_frame = first_frame.astype(np.float32) bbox = np.array(bbox).astype(np.int64) x, y, w, h = tuple(bbox) self._center = (x + w / 2, y + h / 2) self.w, self.h = w, h self.crop_size = (int(w * (1 + self.padding)), int(h * (1 + self.padding))) self.base_target_size = (self.w, self.h) self.target_sz = (self.w, self.h) self._window = cos_window(self.crop_size) output_sigma = np.sqrt(self.w * self.h) * self.output_sigma_factor self.y = gaussian2d_labels(self.crop_size, output_sigma) self._init_response_center = np.unravel_index( np.argmax(self.y, axis=None), self.y.shape) self.yf = fft2(self.y) self.scale_sigma = self.num_of_scales / np.sqrt( 33) * self.scale_sigma_factor ss = np.arange(1, self.num_of_scales + 1) - np.ceil( self.num_of_scales / 2) ys = np.exp(-0.5 * (ss**2) / (self.scale_sigma**2)) self.ysf = np.fft.fft(ys) if self.num_of_scales % 2 == 0: scale_window = np.hanning(self.num_of_scales + 1) self.scale_window = scale_window[1:] else: self.scale_window = np.hanning(self.num_of_scales) ss = np.arange(1, self.num_of_scales + 1) self.scale_factors = self.scale_step**( np.ceil(self.num_of_scales / 2) - ss) self.scale_model_factor = 1. if (self.w * self.h) > self.scale_model_max_area: self.scale_model_factor = np.sqrt(self.scale_model_max_area / (self.w * self.h)) self.scale_model_sz = (int(np.floor(self.w * self.scale_model_factor)), int(np.floor(self.h * self.scale_model_factor))) self.current_scale_factor = 1. self.min_scale_factor = self.scale_step**(int( np.ceil( np.log(max(5 / self.crop_size[0], 5 / self.crop_size[1])) / np.log(self.scale_step)))) self.max_scale_factor = self.scale_step**(int( np.floor((np.log( min(first_frame.shape[1] / self.w, first_frame.shape[0] / self.h)) / np.log(self.scale_step))))) xl = self.get_translation_sample(first_frame, self._center, self.crop_size, self.current_scale_factor, self._window) self.xlf = fft2(xl) self.hf_den = np.sum(self.xlf * np.conj(self.xlf), axis=2) self.hf_num = self.yf[:, :, None] * np.conj(self.xlf) xs = self.get_scale_sample(first_frame, self._center) xsf = np.fft.fft(xs, axis=1) self.sf_num = self.ysf * np.conj(xsf) self.sf_den = np.sum(xsf * np.conj(xsf), axis=0)