Allow keypoint detections outside the image.
This commit is contained in:
@ -867,8 +867,6 @@ namespace utils_2d_pose
|
||||
int pad_top = paddings[2];
|
||||
int box_left = box[0];
|
||||
int box_top = box[1];
|
||||
int img_w = image.cols;
|
||||
int img_h = image.rows;
|
||||
|
||||
for (auto &kp : kpts)
|
||||
{
|
||||
@ -884,10 +882,6 @@ namespace utils_2d_pose
|
||||
|
||||
x += box_left;
|
||||
y += box_top;
|
||||
|
||||
// Clamp to iamge region
|
||||
x = std::max(0.0f, std::min(x, img_w - 1.0f));
|
||||
y = std::max(0.0f, std::min(y, img_h - 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
@ -949,6 +943,37 @@ namespace utils_2d_pose
|
||||
// Sometimes the detection model predicts multiple boxes with different shapes for the same
|
||||
// person. They then result in strongly overlapping poses, which are merged here.
|
||||
merge_close_poses(poses, {(size_t)image.cols, (size_t)image.rows});
|
||||
|
||||
// Clip keypoints far outside the image
|
||||
float mask_offset = (image.cols + image.rows) / 10.0;
|
||||
for (size_t i = 0; i < poses.size(); ++i)
|
||||
{
|
||||
for (size_t j = 0; j < poses[i].size(); ++j)
|
||||
{
|
||||
auto &kp = poses[i][j];
|
||||
if (kp[0] < -mask_offset)
|
||||
{
|
||||
kp[0] = -mask_offset;
|
||||
kp[2] = 0.001;
|
||||
}
|
||||
if (kp[1] < -mask_offset)
|
||||
{
|
||||
kp[1] = -mask_offset;
|
||||
kp[2] = 0.001;
|
||||
}
|
||||
if (kp[0] >= image.cols + mask_offset)
|
||||
{
|
||||
kp[0] = image.cols + mask_offset;
|
||||
kp[2] = 0.001;
|
||||
}
|
||||
if (kp[1] >= image.rows + mask_offset)
|
||||
{
|
||||
kp[1] = image.rows + mask_offset;
|
||||
kp[2] = 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return poses;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user