39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
|
|
#include "frame/rect.h"
|
|
|
|
namespace rk3588 {
|
|
|
|
inline float ComputeCenteredXOffset(float width_scale) {
|
|
return (1.0f - width_scale) * 0.5f;
|
|
}
|
|
|
|
inline Rect ClipPersonShoeRoi(const Rect& roi, int img_w, int img_h) {
|
|
Rect out = roi;
|
|
out.x = std::max(0.0f, out.x);
|
|
out.y = std::max(0.0f, out.y);
|
|
if (img_w > 0) out.w = std::min(out.w, static_cast<float>(img_w) - out.x);
|
|
if (img_h > 0) out.h = std::min(out.h, static_cast<float>(img_h) - out.y);
|
|
out.w = std::max(0.0f, out.w);
|
|
out.h = std::max(0.0f, out.h);
|
|
return out;
|
|
}
|
|
|
|
inline Rect BuildPersonFootRegion(const Rect& person_bbox,
|
|
int img_w,
|
|
int img_h,
|
|
float y_offset,
|
|
float width_scale,
|
|
float height_scale) {
|
|
Rect roi;
|
|
roi.x = person_bbox.x + person_bbox.w * ComputeCenteredXOffset(width_scale);
|
|
roi.y = person_bbox.y + person_bbox.h * y_offset;
|
|
roi.w = person_bbox.w * width_scale;
|
|
roi.h = person_bbox.h * height_scale;
|
|
return ClipPersonShoeRoi(roi, img_w, img_h);
|
|
}
|
|
|
|
} // namespace rk3588
|