Skip to content

Commit 5de0ecf

Browse files
authored
[Fix] Add an option to flip webcam inputs for pose tracker demo (open-mmlab#1725)
1 parent 2b18596 commit 5de0ecf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

demo/csrc/cpp/pose_tracker.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DEFINE_string(device, "cpu", "Device name, e.g. \"cpu\", \"cuda\"");
1414
DEFINE_string(output, "", "Output video path or format string");
1515

1616
DEFINE_int32(output_size, 0, "Long-edge of output frames");
17+
DEFINE_int32(flip, 0, "Set to 1 for flipping the input horizontally");
1718
DEFINE_int32(show, 1, "Delay passed to `cv::waitKey` when using `cv::imshow`; -1: disable");
1819

1920
DEFINE_string(skeleton, "coco", R"(Path to skeleton data or name of predefined skeletons: "coco")");
@@ -38,7 +39,7 @@ int main(int argc, char* argv[]) {
3839
// create a tracker state for each video
3940
mmdeploy::PoseTracker::State state = tracker.CreateState(params);
4041

41-
utils::mediaio::Input input(ARGS_input);
42+
utils::mediaio::Input input(ARGS_input, FLAGS_flip);
4243
utils::mediaio::Output output(FLAGS_output, FLAGS_show);
4344

4445
utils::Visualize v(FLAGS_output_size);
@@ -59,7 +60,7 @@ int main(int argc, char* argv[]) {
5960

6061
// write to output stream
6162
if (!output.write(sess.get())) {
62-
// user requested exit by pressing 'q'
63+
// user requested exit by pressing ESC
6364
break;
6465
}
6566
}

demo/csrc/cpp/utils/mediaio.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ class BatchInputIterator {
154154

155155
class Input {
156156
public:
157-
explicit Input(const std::string& path, MediaType type = MediaType::kUnknown)
158-
: path_(path), type_(type) {
157+
explicit Input(const std::string& path, bool flip = false, MediaType type = MediaType::kUnknown)
158+
: path_(path), flip_(flip), type_(type) {
159159
if (type_ == MediaType::kUnknown) {
160160
auto ext = detail::get_extension(path);
161161
if (detail::is_image(ext)) {
@@ -212,6 +212,9 @@ class Input {
212212
}
213213
}
214214
}
215+
if (flip_ && !img.empty()) {
216+
cv::flip(img, img, 1);
217+
}
215218
return img;
216219
}
217220

@@ -270,8 +273,9 @@ class Input {
270273
}
271274

272275
private:
273-
MediaType type_{MediaType::kUnknown};
274276
std::string path_;
277+
bool flip_{};
278+
MediaType type_{MediaType::kUnknown};
275279
std::vector<std::string> items_;
276280
cv::VideoCapture cap_;
277281
size_t index_{};
@@ -350,7 +354,7 @@ class Output {
350354
}
351355
if (show_ >= 0) {
352356
cv::imshow("", frame);
353-
exit = cv::waitKey(show_) == 'q';
357+
exit = cv::waitKey(show_) == 27; // ESC
354358
}
355359
++frame_id_;
356360
return !exit;
@@ -385,4 +389,5 @@ OutputIterator& OutputIterator::operator=(const cv::Mat& frame) {
385389

386390
} // namespace mediaio
387391
} // namespace utils
392+
388393
#endif // MMDEPLOY_MEDIAIO_H

0 commit comments

Comments
 (0)