From c929f1b62f65f3d28445e5af328ca6ffc96774f4 Mon Sep 17 00:00:00 2001 From: xiong-jie-y Date: Sun, 15 May 2022 13:00:01 +0900 Subject: [PATCH] Add make_capture_src for video stream to Python --- modules/gapi/include/opencv2/gapi/streaming/cap.hpp | 6 ++++++ modules/gapi/misc/python/samples/gaze_estimation.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/streaming/cap.hpp b/modules/gapi/include/opencv2/gapi/streaming/cap.hpp index aad6af618c..73d5bfcbeb 100644 --- a/modules/gapi/include/opencv2/gapi/streaming/cap.hpp +++ b/modules/gapi/include/opencv2/gapi/streaming/cap.hpp @@ -119,6 +119,12 @@ GAPI_EXPORTS_W cv::Ptr inline make_capture_src(const std::string& return make_src(path); } +// NB: Overload for using from python +GAPI_EXPORTS_W cv::Ptr inline make_capture_src(const int id) +{ + return make_src(id); +} + } // namespace wip } // namespace gapi } // namespace cv diff --git a/modules/gapi/misc/python/samples/gaze_estimation.py b/modules/gapi/misc/python/samples/gaze_estimation.py index 5536787e60..bdcc7851ee 100644 --- a/modules/gapi/misc/python/samples/gaze_estimation.py +++ b/modules/gapi/misc/python/samples/gaze_estimation.py @@ -27,7 +27,7 @@ def build_argparser(): parser = argparse.ArgumentParser(description='This is an OpenCV-based version of Gaze Estimation example') parser.add_argument('--input', - help='Path to the input video file') + help='Path to the input video file or camera device number') parser.add_argument('--out', help='Path to the output video file') parser.add_argument('--facem', @@ -323,7 +323,11 @@ if __name__ == '__main__': # ------------------------Execution part------------------------ ccomp = comp.compileStreaming(args=cv.gapi.compile_args(kernels, nets)) - source = cv.gapi.wip.make_capture_src(ARGUMENTS.input) + if ARGUMENTS.input.isdigit(): + source = cv.gapi.wip.make_capture_src(int(ARGUMENTS.input)) + else: + source = cv.gapi.wip.make_capture_src(ARGUMENTS.input) + ccomp.setSource(cv.gin(source)) ccomp.start()