Skip to content

Commit dd14866

Browse files
committed
Merge branch 'dev-1.x' of https://github.com/open-mmlab/mmpose into dev-1.x
2 parents 9fbc66e + 346030b commit dd14866

File tree

2 files changed

+68
-68
lines changed

2 files changed

+68
-68
lines changed

projects/rtmpose/README.md

+34-34
Original file line numberDiff line numberDiff line change
@@ -1023,51 +1023,51 @@ if __name__ == '__main__':
10231023
Here is a basic example of SDK C++ API:
10241024

10251025
```C++
1026-
#include "mmdeploy/detector.hpp"
1027-
1028-
#include "opencv2/imgcodecs/imgcodecs.hpp"
1029-
#include "utils/argparse.h"
1030-
#include "utils/visualize.h"
1031-
1032-
DEFINE_ARG_string(model, "Model path");
1033-
DEFINE_ARG_string(image, "Input image path");
1034-
DEFINE_string(device, "cpu", R"(Device name, e.g. "cpu", "cuda")");
1035-
DEFINE_string(output, "detector_output.jpg", "Output image path");
1036-
1037-
DEFINE_double(det_thr, .5, "Detection score threshold");
1026+
#include "mmdeploy/pose_detector.hpp"
1027+
#include "opencv2/imgcodecs.hpp"
1028+
#include "opencv2/imgproc.hpp"
1029+
#include "utils/argparse.h" // See: https://github.com/open-mmlab/mmdeploy/blob/main/demo/csrc/cpp/utils/argparse.h
1030+
1031+
DEFINE_ARG_string(model_path, "Model path");
1032+
DEFINE_ARG_string(image_path, "Input image path");
1033+
DEFINE_string(device_name, "cpu", R"(Device name, e.g. "cpu", "cuda")");
1034+
DEFINE_int32(bbox_x, -1, R"(x position of the bounding box)");
1035+
DEFINE_int32(bbox_y, -1, R"(y position of the bounding box)");
1036+
DEFINE_int32(bbox_w, -1, R"(width of the bounding box)");
1037+
DEFINE_int32(bbox_h, -1, R"(height of the bounding box)");
10381038

10391039
int main(int argc, char* argv[]) {
10401040
if (!utils::ParseArguments(argc, argv)) {
10411041
return -1;
10421042
}
10431043

1044-
cv::Mat img = cv::imread(ARGS_image);
1045-
if (img.empty()) {
1046-
fprintf(stderr, "failed to load image: %s\n", ARGS_image.c_str());
1047-
return -1;
1048-
}
1044+
cv::Mat img = cv::imread(ARGS_image_path);
1045+
1046+
mmdeploy::PoseDetector detector(mmdeploy::Model{ARGS_model_path}, mmdeploy::Device{FLAGS_device_name, 0});
10491047

1050-
// construct a detector instance
1051-
mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, mmdeploy::Device{FLAGS_device});
1052-
1053-
// apply the detector, the result is an array-like class holding references to
1054-
// `mmdeploy_detection_t`, will be released automatically on destruction
1055-
mmdeploy::Detector::Result dets = detector.Apply(img);
1056-
1057-
// visualize
1058-
utils::Visualize v;
1059-
auto sess = v.get_session(img);
1060-
int count = 0;
1061-
for (const mmdeploy_detection_t& det : dets) {
1062-
if (det.score > FLAGS_det_thr) { // filter bboxes
1063-
sess.add_det(det.bbox, det.label_id, det.score, det.mask, count++);
1064-
}
1048+
mmdeploy::PoseDetector::Result result{0, 0, nullptr};
1049+
1050+
if (FLAGS_bbox_x == -1 || FLAGS_bbox_y == -1 || FLAGS_bbox_w == -1 || FLAGS_bbox_h == -1) {
1051+
result = detector.Apply(img);
1052+
} else {
1053+
// convert (x, y, w, h) -> (left, top, right, bottom)
1054+
mmdeploy::cxx::Rect rect;
1055+
rect.left = FLAGS_bbox_x;
1056+
rect.top = FLAGS_bbox_y;
1057+
rect.right = FLAGS_bbox_x + FLAGS_bbox_w;
1058+
rect.bottom = FLAGS_bbox_y + FLAGS_bbox_h;
1059+
result = detector.Apply(img, {rect});
10651060
}
10661061

1067-
if (!FLAGS_output.empty()) {
1068-
cv::imwrite(FLAGS_output, sess.get());
1062+
// Draw circles at detected keypoints
1063+
for (size_t i = 0; i < result[0].length; ++i) {
1064+
cv::Point keypoint(result[0].point[i].x, result[0].point[i].y);
1065+
cv::circle(img, keypoint, 1, cv::Scalar(0, 255, 0), 2); // Draw filled circle
10691066
}
10701067

1068+
// Save the output image
1069+
cv::imwrite("output_pose.png", img);
1070+
10711071
return 0;
10721072
}
10731073
```

projects/rtmpose/README_CN.md

+34-34
Original file line numberDiff line numberDiff line change
@@ -1016,51 +1016,51 @@ if __name__ == '__main__':
10161016
#### C++ API
10171017

10181018
```C++
1019-
#include "mmdeploy/detector.hpp"
1020-
1021-
#include "opencv2/imgcodecs/imgcodecs.hpp"
1022-
#include "utils/argparse.h"
1023-
#include "utils/visualize.h"
1024-
1025-
DEFINE_ARG_string(model, "Model path");
1026-
DEFINE_ARG_string(image, "Input image path");
1027-
DEFINE_string(device, "cpu", R"(Device name, e.g. "cpu", "cuda")");
1028-
DEFINE_string(output, "detector_output.jpg", "Output image path");
1029-
1030-
DEFINE_double(det_thr, .5, "Detection score threshold");
1019+
#include "mmdeploy/pose_detector.hpp"
1020+
#include "opencv2/imgcodecs.hpp"
1021+
#include "opencv2/imgproc.hpp"
1022+
#include "utils/argparse.h" // See: https://github.com/open-mmlab/mmdeploy/blob/main/demo/csrc/cpp/utils/argparse.h
1023+
1024+
DEFINE_ARG_string(model_path, "Model path");
1025+
DEFINE_ARG_string(image_path, "Input image path");
1026+
DEFINE_string(device_name, "cpu", R"(Device name, e.g. "cpu", "cuda")");
1027+
DEFINE_int32(bbox_x, -1, R"(x position of the bounding box)");
1028+
DEFINE_int32(bbox_y, -1, R"(y position of the bounding box)");
1029+
DEFINE_int32(bbox_w, -1, R"(width of the bounding box)");
1030+
DEFINE_int32(bbox_h, -1, R"(height of the bounding box)");
10311031

10321032
int main(int argc, char* argv[]) {
10331033
if (!utils::ParseArguments(argc, argv)) {
10341034
return -1;
10351035
}
10361036

1037-
cv::Mat img = cv::imread(ARGS_image);
1038-
if (img.empty()) {
1039-
fprintf(stderr, "failed to load image: %s\n", ARGS_image.c_str());
1040-
return -1;
1041-
}
1037+
cv::Mat img = cv::imread(ARGS_image_path);
1038+
1039+
mmdeploy::PoseDetector detector(mmdeploy::Model{ARGS_model_path}, mmdeploy::Device{FLAGS_device_name, 0});
10421040

1043-
// construct a detector instance
1044-
mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, mmdeploy::Device{FLAGS_device});
1045-
1046-
// apply the detector, the result is an array-like class holding references to
1047-
// `mmdeploy_detection_t`, will be released automatically on destruction
1048-
mmdeploy::Detector::Result dets = detector.Apply(img);
1049-
1050-
// visualize
1051-
utils::Visualize v;
1052-
auto sess = v.get_session(img);
1053-
int count = 0;
1054-
for (const mmdeploy_detection_t& det : dets) {
1055-
if (det.score > FLAGS_det_thr) { // filter bboxes
1056-
sess.add_det(det.bbox, det.label_id, det.score, det.mask, count++);
1057-
}
1041+
mmdeploy::PoseDetector::Result result{0, 0, nullptr};
1042+
1043+
if (FLAGS_bbox_x == -1 || FLAGS_bbox_y == -1 || FLAGS_bbox_w == -1 || FLAGS_bbox_h == -1) {
1044+
result = detector.Apply(img);
1045+
} else {
1046+
// convert (x, y, w, h) -> (left, top, right, bottom)
1047+
mmdeploy::cxx::Rect rect;
1048+
rect.left = FLAGS_bbox_x;
1049+
rect.top = FLAGS_bbox_y;
1050+
rect.right = FLAGS_bbox_x + FLAGS_bbox_w;
1051+
rect.bottom = FLAGS_bbox_y + FLAGS_bbox_h;
1052+
result = detector.Apply(img, {rect});
10581053
}
10591054

1060-
if (!FLAGS_output.empty()) {
1061-
cv::imwrite(FLAGS_output, sess.get());
1055+
// Draw circles at detected keypoints
1056+
for (size_t i = 0; i < result[0].length; ++i) {
1057+
cv::Point keypoint(result[0].point[i].x, result[0].point[i].y);
1058+
cv::circle(img, keypoint, 1, cv::Scalar(0, 255, 0), 2); // Draw filled circle
10621059
}
10631060

1061+
// Save the output image
1062+
cv::imwrite("output_pose.png", img);
1063+
10641064
return 0;
10651065
}
10661066
```

0 commit comments

Comments
 (0)