diff --git a/deploy/lite/include/keypoint_postprocess.h b/deploy/lite/include/keypoint_postprocess.h index 0d1e747f306e44679d0500272e80df8a5fb19ab9..4e0e54c2640104488ef85e733af1c16bdc2d86aa 100644 --- a/deploy/lite/include/keypoint_postprocess.h +++ b/deploy/lite/include/keypoint_postprocess.h @@ -33,7 +33,8 @@ void transform_preds(std::vector& coords, std::vector& scale, std::vector& output_size, std::vector& dim, - std::vector& target_coords); + std::vector& target_coords, + bool affine); void box_to_center_scale(std::vector& box, int width, int height, diff --git a/deploy/lite/src/keypoint_postprocess.cc b/deploy/lite/src/keypoint_postprocess.cc index 5f28d2adcffaee6b2a3135eb828996c3b00488fa..6c75ece87c2c8f743f0f112ab6bd23fdcc96a270 100644 --- a/deploy/lite/src/keypoint_postprocess.cc +++ b/deploy/lite/src/keypoint_postprocess.cc @@ -74,11 +74,26 @@ void transform_preds(std::vector& coords, std::vector& scale, std::vector& output_size, std::vector& dim, - std::vector& target_coords) { - cv::Mat trans(2, 3, CV_64FC1); - get_affine_transform(center, scale, 0, output_size, trans, 1); - for (int p = 0; p < dim[1]; ++p) { - affine_tranform(coords[p * 2], coords[p * 2 + 1], trans, target_coords, p); + std::vector& target_coords, + bool affine=false) { + if (affine) { + cv::Mat trans(2, 3, CV_64FC1); + get_affine_transform(center, scale, 0, output_size, trans, 1); + for (int p = 0; p < dim[1]; ++p) { + affine_tranform( + coords[p * 2], coords[p * 2 + 1], trans, target_coords, p); + } + } else { + float heat_w = static_cast(output_size[0]); + float heat_h = static_cast(output_size[1]); + float x_scale = scale[0] / heat_w; + float y_scale = scale[1] / heat_h; + float offset_x = center[0] - scale[0] / 2.; + float offset_y = center[1] - scale[1] / 2.; + for (int i = 0; i < dim[1]; i++) { + target_coords[i * 3 + 1] = x_scale * coords[i * 2] + offset_x; + target_coords[i * 3 + 2] = y_scale * coords[i * 2 + 1] + offset_y; + } } } diff --git a/deploy/python/det_keypoint_unite_infer.py b/deploy/python/det_keypoint_unite_infer.py index f0b80752ea087cd438bd3f87b9ff267a5c0be4dc..df22cde8d6b2b5ffef45404f067370fb835f2e3b 100644 --- a/deploy/python/det_keypoint_unite_infer.py +++ b/deploy/python/det_keypoint_unite_infer.py @@ -165,7 +165,7 @@ def topdown_unite_predict_video(detector, frame2, results, topdown_keypoint_detector, keypoint_batch_size, FLAGS.run_benchmark) - if FLAGS.smooth and len(keypoint_res['keypoint'][0])==1: + if FLAGS.smooth and len(keypoint_res['keypoint'][0]) == 1: current_keypoints = np.array(keypoint_res['keypoint'][0][0]) smooth_keypoints = keypoint_smoothing.smooth_process( current_keypoints) @@ -215,7 +215,7 @@ class KeypointSmoothing(object): fc_d=0.1, fc_min=0.1, beta=0.1, - thres_mult=0.2): + thres_mult=0.3): super(KeypointSmoothing, self).__init__() self.image_width = width self.image_height = height @@ -234,7 +234,7 @@ class KeypointSmoothing(object): if self.filter_type == 'OneEuro': self.smooth_func = self.one_euro_filter elif self.filter_type == 'EMA': - self.smooth_func = self.exponential_smoothing + self.smooth_func = self.ema_filter else: raise ValueError('filter type must be one_euro or ema') @@ -261,6 +261,7 @@ class KeypointSmoothing(object): else: result = self.smooth_func(current_keypoint, self.x_prev_hat[index], index) + return result def one_euro_filter(self, x_cur, x_pre, index): @@ -276,6 +277,11 @@ class KeypointSmoothing(object): self.x_prev_hat[index] = x_cur_hat return x_cur_hat + def ema_filter(self, x_cur, x_pre, index): + x_cur_hat = self.exponential_smoothing(x_cur, x_pre) + self.x_prev_hat[index] = x_cur_hat + return x_cur_hat + def smoothing_factor(self, te, fc): r = 2 * math.pi * fc * te return r / (r + 1)