提交 7e008591 编写于 作者: Z zhiboniu 提交者: zhiboniu

update ema filter;

refix keypoint transform to orgimage
上级 07f5f782
...@@ -33,7 +33,8 @@ void transform_preds(std::vector<float>& coords, ...@@ -33,7 +33,8 @@ void transform_preds(std::vector<float>& coords,
std::vector<float>& scale, std::vector<float>& scale,
std::vector<int>& output_size, std::vector<int>& output_size,
std::vector<int>& dim, std::vector<int>& dim,
std::vector<float>& target_coords); std::vector<float>& target_coords,
bool affine);
void box_to_center_scale(std::vector<int>& box, void box_to_center_scale(std::vector<int>& box,
int width, int width,
int height, int height,
......
...@@ -74,11 +74,26 @@ void transform_preds(std::vector<float>& coords, ...@@ -74,11 +74,26 @@ void transform_preds(std::vector<float>& coords,
std::vector<float>& scale, std::vector<float>& scale,
std::vector<int>& output_size, std::vector<int>& output_size,
std::vector<int64_t>& dim, std::vector<int64_t>& dim,
std::vector<float>& target_coords) { std::vector<float>& target_coords,
bool affine=false) {
if (affine) {
cv::Mat trans(2, 3, CV_64FC1); cv::Mat trans(2, 3, CV_64FC1);
get_affine_transform(center, scale, 0, output_size, trans, 1); get_affine_transform(center, scale, 0, output_size, trans, 1);
for (int p = 0; p < dim[1]; ++p) { for (int p = 0; p < dim[1]; ++p) {
affine_tranform(coords[p * 2], coords[p * 2 + 1], trans, target_coords, p); affine_tranform(
coords[p * 2], coords[p * 2 + 1], trans, target_coords, p);
}
} else {
float heat_w = static_cast<float>(output_size[0]);
float heat_h = static_cast<float>(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;
}
} }
} }
......
...@@ -165,7 +165,7 @@ def topdown_unite_predict_video(detector, ...@@ -165,7 +165,7 @@ def topdown_unite_predict_video(detector,
frame2, results, topdown_keypoint_detector, keypoint_batch_size, frame2, results, topdown_keypoint_detector, keypoint_batch_size,
FLAGS.run_benchmark) 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]) current_keypoints = np.array(keypoint_res['keypoint'][0][0])
smooth_keypoints = keypoint_smoothing.smooth_process( smooth_keypoints = keypoint_smoothing.smooth_process(
current_keypoints) current_keypoints)
...@@ -215,7 +215,7 @@ class KeypointSmoothing(object): ...@@ -215,7 +215,7 @@ class KeypointSmoothing(object):
fc_d=0.1, fc_d=0.1,
fc_min=0.1, fc_min=0.1,
beta=0.1, beta=0.1,
thres_mult=0.2): thres_mult=0.3):
super(KeypointSmoothing, self).__init__() super(KeypointSmoothing, self).__init__()
self.image_width = width self.image_width = width
self.image_height = height self.image_height = height
...@@ -234,7 +234,7 @@ class KeypointSmoothing(object): ...@@ -234,7 +234,7 @@ class KeypointSmoothing(object):
if self.filter_type == 'OneEuro': if self.filter_type == 'OneEuro':
self.smooth_func = self.one_euro_filter self.smooth_func = self.one_euro_filter
elif self.filter_type == 'EMA': elif self.filter_type == 'EMA':
self.smooth_func = self.exponential_smoothing self.smooth_func = self.ema_filter
else: else:
raise ValueError('filter type must be one_euro or ema') raise ValueError('filter type must be one_euro or ema')
...@@ -261,6 +261,7 @@ class KeypointSmoothing(object): ...@@ -261,6 +261,7 @@ class KeypointSmoothing(object):
else: else:
result = self.smooth_func(current_keypoint, self.x_prev_hat[index], result = self.smooth_func(current_keypoint, self.x_prev_hat[index],
index) index)
return result return result
def one_euro_filter(self, x_cur, x_pre, index): def one_euro_filter(self, x_cur, x_pre, index):
...@@ -276,6 +277,11 @@ class KeypointSmoothing(object): ...@@ -276,6 +277,11 @@ class KeypointSmoothing(object):
self.x_prev_hat[index] = x_cur_hat self.x_prev_hat[index] = x_cur_hat
return 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): def smoothing_factor(self, te, fc):
r = 2 * math.pi * fc * te r = 2 * math.pi * fc * te
return r / (r + 1) return r / (r + 1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册