6
6
#include " mmdeploy/core/utils/device_utils.h"
7
7
#include " mmdeploy/core/utils/formatter.h"
8
8
#include " mmdeploy/experimental/module_adapter.h"
9
+ #include " utils.h"
9
10
10
11
using namespace std ;
11
12
@@ -127,6 +128,13 @@ Result<Detections> ResizeBBox::GetBBoxes(const Value& prep_res, const Tensor& de
127
128
scale_factor = {1 .f , 1 .f , 1 .f , 1 .f };
128
129
}
129
130
131
+ int top_padding = 0 ;
132
+ int left_padding = 0 ;
133
+ if (prep_res.contains (" pad_param" )) {
134
+ top_padding = prep_res[" pad_param" ][0 ].get <int >();
135
+ left_padding = prep_res[" pad_param" ][1 ].get <int >();
136
+ }
137
+
130
138
float w_offset = 0 .f ;
131
139
float h_offset = 0 .f ;
132
140
if (prep_res.contains (" border" )) {
@@ -153,7 +161,7 @@ Result<Detections> ResizeBBox::GetBBoxes(const Value& prep_res, const Tensor& de
153
161
MMDEPLOY_DEBUG (" ori left {}, top {}, right {}, bottom {}, label {}" , left, top, right, bottom,
154
162
*labels_ptr);
155
163
auto rect = MapToOriginImage (left, top, right, bottom, scale_factor.data (), w_offset, h_offset,
156
- ori_width, ori_height);
164
+ ori_width, ori_height, top_padding, left_padding );
157
165
if (rect[2 ] - rect[0 ] < min_bbox_size_ || rect[3 ] - rect[1 ] < min_bbox_size_) {
158
166
MMDEPLOY_DEBUG (" ignore small bbox with width '{}' and height '{}" , rect[2 ] - rect[0 ],
159
167
rect[3 ] - rect[1 ]);
@@ -170,15 +178,6 @@ Result<Detections> ResizeBBox::GetBBoxes(const Value& prep_res, const Tensor& de
170
178
}
171
179
return objs;
172
180
}
173
- std::array<float , 4 > ResizeBBox::MapToOriginImage (float left, float top, float right, float bottom,
174
- const float * scale_factor, float x_offset,
175
- float y_offset, int ori_width, int ori_height) {
176
- left = std::max (left / scale_factor[0 ] + x_offset, 0 .f );
177
- top = std::max (top / scale_factor[1 ] + y_offset, 0 .f );
178
- right = std::min (right / scale_factor[2 ] + x_offset, (float )ori_width - 1 .f );
179
- bottom = std::min (bottom / scale_factor[3 ] + y_offset, (float )ori_height - 1 .f );
180
- return {left, top, right, bottom};
181
- }
182
181
183
182
MMDEPLOY_REGISTER_CODEBASE_COMPONENT (MMDetection, ResizeBBox);
184
183
0 commit comments