def make_training_example_BBShift_(self, bbParams, visualize_example=False): """TODO: Docstring for make_training_example_BBShift_. :returns: TODO """ bbox_curr_gt = self.bbox_curr_gt_ bbox_curr_shift = BoundingBox(0, 0, 0, 0) bbox_curr_shift = bbox_curr_gt.shift( self.img_curr_, bbParams.lamda_scale, bbParams.lamda_shift, bbParams.min_scale, bbParams.max_scale, True, bbox_curr_shift) rand_search_region, rand_search_location, edge_spacing_x, edge_spacing_y = cropPadImage( bbox_curr_shift, self.img_curr_) bbox_curr_gt = self.bbox_curr_gt_ bbox_gt_recentered = BoundingBox(0, 0, 0, 0) bbox_gt_recentered = bbox_curr_gt.recenter(rand_search_location, edge_spacing_x, edge_spacing_y, bbox_gt_recentered) bbox_gt_recentered.scale(rand_search_region) bbox_gt_scaled = bbox_gt_recentered return rand_search_region, self.target_pad_, bbox_gt_scaled
def init(self, image_curr, init_bbox): """ initializing the first frame in the video """ left = float(init_bbox[0]) top = float(init_bbox[1]) right = float(init_bbox[2]) bottom = float(init_bbox[3]) bbox_gt = BoundingBox(left, top, right, bottom) self.image_prev = image_curr self.bbox_prev_tight = bbox_gt self.bbox_curr_prior_tight = bbox_gt self.DeltaBox = np.array([0., 0.]) self.lambdaBox = 0.3 self.prevBoxeffect = 0 self.occlusion_flag = 0 target_pad, _, _, _ = cropPadImage(self.bbox_prev_tight, self.image_prev) # image, BGR(training type) target_pad_resize = self.preprocess(target_pad) # jaehyuk, check hanning windows hann_1d = np.expand_dims(np.hanning(227), axis=0) hann_2d = np.transpose(hann_1d) * hann_1d hann_2d = np.expand_dims(hann_2d, axis=2) target_pad_resize = target_pad_resize * hann_2d target_pad_expdim = np.expand_dims(target_pad_resize, axis=0) self.target_pool5 = sess.run( [tracknet.target_pool5], feed_dict={tracknet.target: target_pad_expdim}) self.target_pool5 = np.resize(self.target_pool5, [1, 6, 6, 256])
def reset(self, bbox_curr, bbox_prev, img_curr, img_prev): """TODO: to be defined1. """ target_pad, _, _, _ = cropPadImage(bbox_prev, img_prev) self.img_curr_ = img_curr self.bbox_curr_gt_ = bbox_curr self.bbox_prev_gt_ = bbox_prev self.target_pad_ = target_pad
def track(self, image_curr, tracknet, sess): """TODO: Docstring for tracker. :returns: TODO """ target_pad, _, _, _ = cropPadImage(self.bbox_prev_tight, self.image_prev) cur_search_region, search_location, edge_spacing_x, edge_spacing_y = cropPadImage( self.bbox_curr_prior_tight, image_curr) # image, BGR(training type) cur_search_region_resize = self.preprocess(cur_search_region) target_pad_resize = self.preprocess(target_pad) cur_search_region_expdim = np.expand_dims(cur_search_region_resize, axis=0) target_pad_expdim = np.expand_dims(target_pad_resize, axis=0) fc8 = sess.run( [tracknet.fc8], feed_dict={ tracknet.image: cur_search_region_expdim, tracknet.target: target_pad_expdim }) bbox_estimate = calculate_box(fc8) # this box is NMS result, TODO, all bbox check if not len(bbox_estimate) == 0: bbox_estimate = BoundingBox(bbox_estimate[0][0], bbox_estimate[0][1], bbox_estimate[0][2], bbox_estimate[0][3]) # Inplace correction of bounding box bbox_estimate.unscale(cur_search_region) bbox_estimate.uncenter(image_curr, search_location, edge_spacing_x, edge_spacing_y) self.image_prev = image_curr self.bbox_prev_tight = bbox_estimate self.bbox_curr_prior_tight = bbox_estimate else: bbox_estimate = False return bbox_estimate
def make_true_example(self): """TODO: Docstring for make_true_example. :returns: TODO """ curr_prior_tight = self.bbox_prev_gt_ target_pad = self.target_pad_ curr_search_region, curr_search_location, edge_spacing_x, edge_spacing_y = cropPadImage(curr_prior_tight, self.img_curr_) bbox_curr_gt = self.bbox_curr_gt_ bbox_curr_gt_recentered = BoundingBox(0, 0, 0, 0) bbox_curr_gt_recentered = bbox_curr_gt.recenter(curr_search_location, edge_spacing_x, edge_spacing_y, bbox_curr_gt_recentered) bbox_curr_gt_recentered.scale(curr_search_region) return curr_search_region, target_pad, bbox_curr_gt_recentered
def track(self, image_curr, tracknet, velocity, sess): """TODO: Docstring for tracker. :returns: TODO """ target_pad, _, _, _ = cropPadImage(self.bbox_prev_tight, self.image_prev) cur_search_region, search_location, edge_spacing_x, edge_spacing_y = cropPadImage( self.bbox_curr_prior_tight, image_curr) # image, BGR(training type) cur_search_region_resize = self.preprocess(cur_search_region) target_pad_resize = self.preprocess(target_pad) cur_search_region_expdim = np.expand_dims(cur_search_region_resize, axis=0) target_pad_expdim = np.expand_dims(target_pad_resize, axis=0) re_fc4_image, fc4_adj = sess.run( [tracknet.re_fc4_image, tracknet.fc4_adj], feed_dict={ tracknet.image: cur_search_region_expdim, tracknet.target: target_pad_expdim }) bbox_estimate, object_bool, objectness = calculate_box( re_fc4_image, fc4_adj) print('objectness_s is: ', objectness) ########### original method ############ # this box is NMS result, TODO, all bbox check if not len(bbox_estimate) == 0: bbox_estimate = BoundingBox(bbox_estimate[0][0], bbox_estimate[0][1], bbox_estimate[0][2], bbox_estimate[0][3]) # Inplace correction of bounding box bbox_estimate.unscale(cur_search_region) bbox_estimate.uncenter(image_curr, search_location, edge_spacing_x, edge_spacing_y) # self.image_prev = image_curr # self.bbox_prev_tight = bbox_estimate self.bbox_curr_prior_tight = bbox_estimate else: # self.image_prev = self.image_prev # self.bbox_prev_tight = self.bbox_prev_tight self.bbox_curr_prior_tight = self.bbox_curr_prior_tight bbox_estimate = self.bbox_curr_prior_tight ########### original method ############ ############ trick method ############ # if object_bool: # # if not len(bbox_estimate) == 0: # # current_box_wh = np.array([(bbox_estimate.[0][2] - bbox_estimate.[0][0]), (bbox_estimate.[0][3] - bbox_estimate.[0][1])], dtype=np.float32) # # prev_box_wh = np.array([5., 5.], dtype=np.float32) # # bbox_estimate = BoundingBox(bbox_estimate[0][0], bbox_estimate[0][1], bbox_estimate[0][2], bbox_estimate[0][3]) # # # relative distance from center point [5. 5.] # relative_current_box = np.array([(bbox_estimate.x2 + bbox_estimate.x1) / 2, # (bbox_estimate.y2 + bbox_estimate.y1) / 2], # dtype=np.float32) # relative_distance = np.linalg.norm(relative_current_box - np.array([5., 5.])) # # # Inplace correction of bounding box # bbox_estimate.unscale(cur_search_region) # bbox_estimate.uncenter(image_curr, search_location, edge_spacing_x, edge_spacing_y) # # # image's width height , center point # current_box = np.array([(bbox_estimate.x2 + bbox_estimate.x1) / 2, (bbox_estimate.y2 + bbox_estimate.y1) / 2], dtype=np.float32) # prev_box = np.array([(self.bbox_curr_prior_tight.x2 + self.bbox_curr_prior_tight.x1) / 2, (self.bbox_curr_prior_tight.y2 + self.bbox_curr_prior_tight.y1) / 2], # dtype=np.float32) # # if relative_distance < 2: # self.DeltaBox = self.lambdaBox * (current_box - prev_box) + (1 - self.lambdaBox) * self.DeltaBox # # # self.image_prev = image_curr # self.bbox_prev_tight = bbox_estimate # self.bbox_curr_prior_tight = bbox_estimate # print(self.DeltaBox) # else: # # under prev img, box block is no update # self.image_prev = self.image_prev # self.bbox_prev_tight = self.bbox_prev_tight # # self.bbox_curr_prior_tight = self.bbox_prev_tight # self.bbox_curr_prior_tight = BoundingBox(self.bbox_curr_prior_tight.x1 + self.DeltaBox[0], # self.bbox_curr_prior_tight.y1 + self.DeltaBox[1], # self.bbox_curr_prior_tight.x2 + self.DeltaBox[0], # self.bbox_curr_prior_tight.y2 + self.DeltaBox[1]) # bbox_estimate = self.bbox_curr_prior_tight # print('distance is {:>3}'.format(relative_distance)) # print(self.DeltaBox) # else: # # under prev img, box block is no update # self.image_prev = self.image_prev # self.bbox_prev_tight = self.bbox_prev_tight # # self.bbox_curr_prior_tight = self.bbox_prev_tight # self.bbox_curr_prior_tight = BoundingBox(self.bbox_curr_prior_tight.x1 + self.DeltaBox[0], # self.bbox_curr_prior_tight.y1 + self.DeltaBox[1], # self.bbox_curr_prior_tight.x2 + self.DeltaBox[0], # self.bbox_curr_prior_tight.y2 + self.DeltaBox[1]) # bbox_estimate = self.bbox_curr_prior_tight # print('occlusion is detected') # print(self.DeltaBox) # # ############ trick method ############ left_x = bbox_estimate.x1 left_y = bbox_estimate.y1 width = bbox_estimate.x2 - bbox_estimate.x1 height = bbox_estimate.y2 - bbox_estimate.y1 return vot.Rectangle(left_x, left_y, width, height)