diff --git a/scripts/utils_2d_pose.hpp b/scripts/utils_2d_pose.hpp index 2fd98c5..85b66a8 100644 --- a/scripts/utils_2d_pose.hpp +++ b/scripts/utils_2d_pose.hpp @@ -424,10 +424,10 @@ namespace utils_2d_pose } std::tuple, float, std::array, std::array> - calc_params(const cv::Mat &image, const std::array &bbox) const; + calc_params(const cv::Mat &image, const std::array &bbox) const; cv::Mat crop_resize_box(const cv::Mat &image, - const std::array &bbox) const; + const std::array &bbox) const; private: std::array target_size; @@ -438,7 +438,7 @@ namespace utils_2d_pose // ============================================================================================= std::tuple, float, std::array, std::array> - BoxCrop::calc_params(const cv::Mat &image, const std::array &bbox) const + BoxCrop::calc_params(const cv::Mat &image, const std::array &bbox) const { // Extract some params int img_h = image.rows; @@ -560,7 +560,7 @@ namespace utils_2d_pose // ============================================================================================= cv::Mat BoxCrop::crop_resize_box(const cv::Mat &image, - const std::array &bbox) const + const std::array &bbox) const { auto [paddings, _, new_box, new_size] = calc_params(image, bbox); @@ -625,7 +625,7 @@ namespace utils_2d_pose this->letterbox = std::make_unique(target_size, 114); } - std::vector> call(const cv::Mat &image); + std::vector> call(const cv::Mat &image); private: std::array target_size; @@ -634,17 +634,17 @@ namespace utils_2d_pose std::unique_ptr letterbox; cv::Mat preprocess(const cv::Mat &image); - std::vector> postprocess( + std::vector> postprocess( const std::vector>> &result, const cv::Mat &image); - void clip_boxes(std::vector> &boxes, + void clip_boxes(std::vector> &boxes, const cv::Mat &image) const; }; // ============================================================================================= - std::vector> RTMDet::call(const cv::Mat &image) + std::vector> RTMDet::call(const cv::Mat &image) { cv::Mat preprocessed = preprocess(image); std::vector inputs = {preprocessed}; @@ -663,14 +663,14 @@ namespace utils_2d_pose // ============================================================================================= - std::vector> RTMDet::postprocess( + std::vector> RTMDet::postprocess( const std::vector>> &result, const cv::Mat &image) { // Expected result shape: [B, N, 6] => (x1,y1,x2,y2,score,class) // Convert to vector of boxes - std::vector> boxes; + std::vector> boxes; for (auto &item : result[0]) { float x1 = item[0]; @@ -679,11 +679,7 @@ namespace utils_2d_pose float y2 = item[3]; float score = item[4]; float cls = item[5]; - - if (cls == 0) - { - boxes.push_back({x1, y1, x2, y2, score}); - } + boxes.push_back({x1, y1, x2, y2, score, cls}); } if (boxes.empty()) @@ -721,7 +717,7 @@ namespace utils_2d_pose // ============================================================================================= - void RTMDet::clip_boxes(std::vector> &boxes, + void RTMDet::clip_boxes(std::vector> &boxes, const cv::Mat &image) const { // Get paddings, scale from letterbox @@ -777,7 +773,7 @@ namespace utils_2d_pose } std::vector>> call(const cv::Mat &image, - const std::vector> &bboxes); + const std::vector> &bboxes); private: std::array target_size; @@ -785,21 +781,21 @@ namespace utils_2d_pose std::vector preprocess( const cv::Mat &image, - const std::vector> &bboxes); + const std::vector> &bboxes); std::vector>> postprocess( const std::vector>> &result, const cv::Mat &image, - const std::vector> &bboxes); + const std::vector> &bboxes); void clip_keypoints(std::vector> &kp, const cv::Mat &image, - const std::array &bbox) const; + const std::array &bbox) const; }; // ============================================================================================= std::vector>> RTMPose::call( - const cv::Mat &image, const std::vector> &bboxes) + const cv::Mat &image, const std::vector> &bboxes) { std::vector inputs = preprocess(image, bboxes); auto results = call_by_image(inputs); @@ -810,7 +806,7 @@ namespace utils_2d_pose // ============================================================================================= std::vector RTMPose::preprocess( - const cv::Mat &image, const std::vector> &bboxes) + const cv::Mat &image, const std::vector> &bboxes) { std::vector crops; for (auto &bbox : bboxes) @@ -827,7 +823,7 @@ namespace utils_2d_pose std::vector>> RTMPose::postprocess( const std::vector>> &result, const cv::Mat &image, - const std::vector> &bboxes) + const std::vector> &bboxes) { // Expected result shape: [B, N, 3] => (x,y,score) std::vector>> keypoints; @@ -859,7 +855,7 @@ namespace utils_2d_pose void RTMPose::clip_keypoints(std::vector> &kpts, const cv::Mat &image, - const std::array &bbox) const + const std::array &bbox) const { // Get paddings, scale from boxcrop auto [paddings, scale, box, _] = boxcrop->calc_params(image, bbox); @@ -923,6 +919,15 @@ namespace utils_2d_pose { auto bboxes = det_model->call(image); + // Drop boxes with non-person class + for (int i = bboxes.size() - 1; i >= 0; i--) + { + if (static_cast(bboxes[i][5]) != 0) + { + bboxes.erase(bboxes.begin() + i); + } + } + std::vector>> poses; if (this->batch_poses) {