@@ -53,6 +53,7 @@ void colArgMax(const cv::Mat& src,
5353DetectedKeypoints decode_simcc (const cv::Mat& simcc_x,
5454 const cv::Mat& simcc_y,
5555 const cv::Point2f& extra_scale = cv::Point2f(1 .f, 1 .f),
56+ const cv::Point2i& extra_offset = cv::Point2f(0 .f, 0 .f),
5657 bool apply_softmax = false,
5758 float simcc_split_ratio = 2.0f) {
5859 cv::Mat x_locs, max_val_x;
@@ -64,8 +65,9 @@ DetectedKeypoints decode_simcc(const cv::Mat& simcc_x,
6465 std::vector<cv::Point2f> keypoints (x_locs.rows );
6566 cv::Mat scores = cv::Mat::zeros (x_locs.rows , 1 , CV_32F);
6667 for (int i = 0 ; i < x_locs.rows ; i++) {
67- keypoints[i] =
68- cv::Point2f (x_locs.at <int >(i) * extra_scale.x , y_locs.at <int >(i) * extra_scale.y ) / simcc_split_ratio;
68+ keypoints[i] = cv::Point2f ((x_locs.at <int >(i) - extra_offset.x ) * extra_scale.x ,
69+ (y_locs.at <int >(i) - extra_offset.y ) * extra_scale.y ) /
70+ simcc_split_ratio;
6971 scores.at <float >(i) = std::min (max_val_x.at <float >(i), max_val_y.at <float >(i));
7072
7173 if (scores.at <float >(i) <= 0 .f ) {
@@ -220,8 +222,22 @@ std::unique_ptr<ResultBase> KeypointDetectionModel::postprocess(InferenceResult&
220222 float inverted_scale_x = static_cast <float >(image_data.inputImgWidth ) / netInputWidth,
221223 inverted_scale_y = static_cast <float >(image_data.inputImgHeight ) / netInputHeight;
222224
225+ int pad_left = 0 , pad_top = 0 ;
226+ if (RESIZE_KEEP_ASPECT == resizeMode || RESIZE_KEEP_ASPECT_LETTERBOX == resizeMode) {
227+ inverted_scale_x = inverted_scale_y = std::max (inverted_scale_x, inverted_scale_y);
228+ if (RESIZE_KEEP_ASPECT_LETTERBOX == resizeMode) {
229+ pad_left = (netInputWidth -
230+ static_cast <int >(std::round (static_cast <float >(image_data.inputImgWidth ) / inverted_scale_x))) /
231+ 2 ;
232+ pad_top = (netInputHeight -
233+ static_cast <int >(std::round (static_cast <float >(image_data.inputImgHeight ) / inverted_scale_y))) /
234+ 2 ;
235+ }
236+ }
237+
223238 result->poses .emplace_back (
224- decode_simcc (pred_x_mat, pred_y_mat, {inverted_scale_x, inverted_scale_y}, apply_softmax));
239+ decode_simcc (pred_x_mat, pred_y_mat, {inverted_scale_x, inverted_scale_y}, {pad_left, pad_top}, apply_softmax));
240+
225241 return std::unique_ptr<ResultBase>(result);
226242}
227243
0 commit comments