Skip to content

Commit cd6ba9a

Browse files
Port G-API demos to API2.0
1 parent f1f7361 commit cd6ba9a

File tree

6 files changed

+59
-37
lines changed

6 files changed

+59
-37
lines changed

.github/workflows/cpp_gapi-demos.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ jobs:
3535
- if: ${{ !steps.cache.outputs.cache-hit }}
3636
name: Compile OpenCV
3737
run: |
38+
sudo apt install pkg-config
39+
sudo apt install ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev
3840
rm -rf cache/opencv/.git/ # Minimize cache
3941
mkdir cache/opencv/build
4042
cd cache/opencv/build
41-
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_INF_ENGINE=y -DOpenVINO_DIR=$GITHUB_WORKSPACE/ov/runtime/cmake/ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_LINKER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_C_LINKER_LAUNCHER=ccache -DBUILD_TESTS=n -DBUILD_PERF_TESTS=n -DBUILD_EXAMPLES=n -DBUILD_opencv_apps=n -DWITH_OPENCL=n -DWITH_OPENCLAMDBLAS=n -DWITH_OPENCLAMDFFT=n -DWITH_VA=n -DWITH_VA_INTEL=n -DWITH_V4L=n -DWITH_GSTREAMER=n -DWITH_PROTOBUF=n -DBUILD_PROTOBUF=n -DBUILD_JAVA=n -DBUILD_opencv_java_bindings_generator=n -DBUILD_opencv_python2=n -DBUILD_opencv_python3=n -DWITH_IMGCODEC_HDR=n -DWITH_IMGCODEC_SUNRASTER=n -DWITH_IMGCODEC_PXM=n -DWITH_IMGCODEC_PFM=n -DWITH_PNG=n -DWITH_TIFF=n -DWITH_WEBP=n -DWITH_OPENJPEG=n -DWITH_JASPER=n -DWITH_OPENEXR=n -DBUILD_opencv_dnn=n -DBUILD_opencv_features2d=n -DBUILD_opencv_flann=n -DWITH_TBB=n -DBUILD_INFO_SKIP_EXTRA_MODULES=n -DBUILD_JASPER=n -DBUILD_PNG=n -DBUILD_OPENEXR=n -DBUILD_WEBP=n -DBUILD_ZLIB=n -DWITH_CUDA=n -DWITH_EIGEN=n -DWITH_GPHOTO2=n -DOPENCV_GAPI_GSTREAMER=n -DWITH_LAPACK=n -DWITH_MATLAB=n -DWITH_MFX=n -DWITH_QUIRC=n -DWITH_VTK=n -DINSTALL_PDB=n -DINSTALL_TESTS=n -DINSTALL_C_EXAMPLES=n -DINSTALL_PYTHON_EXAMPLES=n -DOPENCV_GENERATE_SETUPVARS=n -DWITH_1394=n -DWITH_FFMPEG=n -DWITH_GTK_2_X=y -DBUILD_JPEG=y -DWITH_IPP=y -DENABLE_CONFIG_VERIFICATION=y -DBUILD_LIST=core,gapi,highgui,imgcodecs,imgproc,videoio ..
43+
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_INF_ENGINE=y -DOpenVINO_DIR=$GITHUB_WORKSPACE/ov/runtime/cmake/ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_LINKER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_C_LINKER_LAUNCHER=ccache -DBUILD_TESTS=y -DVIDEOIO_ENABLE_PLUGINS=y -DBUILD_PERF_TESTS=n -DBUILD_EXAMPLES=n -DBUILD_opencv_apps=y -DWITH_OPENCL=n -DWITH_OPENCLAMDBLAS=n -DWITH_GSTREAMER=n -DWITH_V4L=ON -DWITH_LIBV4L=ON -DWITH_OPENCLAMDFFT=n -DWITH_VA=n -DWITH_VA_INTEL=n -DWITH_PROTOBUF=n -DBUILD_PROTOBUF=n -DBUILD_JAVA=n -DBUILD_opencv_java_bindings_generator=n -DBUILD_opencv_python2=n -DBUILD_opencv_python3=n -DWITH_IMGCODEC_HDR=y -DWITH_IMGCODEC_SUNRASTER=y -DWITH_IMGCODEC_PXM=y -DWITH_IMGCODEC_PFM=y -DWITH_PNG=y -DWITH_TIFF=n -DWITH_WEBP=n -DWITH_OPENJPEG=n -DWITH_JASPER=n -DWITH_OPENEXR=n -DBUILD_opencv_dnn=n -DBUILD_opencv_features2d=n -DBUILD_opencv_flann=n -DWITH_TBB=n -DBUILD_INFO_SKIP_EXTRA_MODULES=n -DBUILD_JASPER=n -DBUILD_PNG=n -DBUILD_OPENEXR=n -DBUILD_WEBP=n -DBUILD_ZLIB=n -DWITH_CUDA=n -DWITH_EIGEN=n -DWITH_GPHOTO2=n -DOPENCV_GAPI_GSTREAMER=n -DWITH_LAPACK=n -DWITH_MATLAB=n -DWITH_MFX=n -DWITH_QUIRC=n -DWITH_VTK=n -DINSTALL_PDB=n -DINSTALL_TESTS=n -DINSTALL_C_EXAMPLES=n -DINSTALL_PYTHON_EXAMPLES=n -DOPENCV_GENERATE_SETUPVARS=n -DWITH_1394=n -DWITH_FFMPEG=y -DWITH_GTK_2_X=y -DBUILD_JPEG=y -DWITH_IPP=y -DENABLE_CONFIG_VERIFICATION=y -DBUILD_LIST=core,gapi,highgui,imgcodecs,imgproc,videoio,video ..
4244
cmake --build . -j $((`nproc`*2+2))
4345
- name: build_demos.sh
4446
run: |

demos/background_subtraction_demo/cpp_gapi/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <opencv2/gapi/imgproc.hpp>
2929
#include <opencv2/gapi/infer.hpp>
3030
#include <opencv2/gapi/infer/ie.hpp>
31+
#include <opencv2/gapi/infer/ov.hpp>
3132
#include <opencv2/gapi/own/assert.hpp>
3233
#include <opencv2/gapi/streaming/source.hpp>
3334
#include <opencv2/gapi/util/optional.hpp>
@@ -147,13 +148,13 @@ int main(int argc, char* argv[]) {
147148
auto config = ConfigFactory::getUserConfig(FLAGS_d, FLAGS_nireq, FLAGS_nstreams, FLAGS_nthreads);
148149
// clang-format off
149150
const auto net =
150-
cv::gapi::ie::Params<cv::gapi::Generic>{
151+
cv::gapi::ov::Params<cv::gapi::Generic>{
151152
model->getName(),
152153
FLAGS_m, // path to topology IR
153154
fileNameNoExt(FLAGS_m) + ".bin", // path to weights
154155
FLAGS_d // device specifier
155156
}.cfgNumRequests(config.maxAsyncRequests)
156-
.pluginConfig(config.getLegacyConfig());
157+
.cfgPluginConfig(config.getLegacyConfig());
157158
// clang-format on
158159

159160
slog::info << "The background matting model " << FLAGS_m << " is loaded to " << FLAGS_d << " device."

demos/gaze_estimation_demo/cpp_gapi/main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <opencv2/gapi/gstreaming.hpp>
3232
#include <opencv2/gapi/infer.hpp>
3333
#include <opencv2/gapi/infer/ie.hpp>
34+
#include <opencv2/gapi/infer/ov.hpp>
3435
#include <opencv2/gapi/streaming/format.hpp>
3536
#include <opencv2/highgui.hpp>
3637
#include <opencv2/imgproc.hpp>
@@ -175,7 +176,7 @@ int main(int argc, char* argv[]) {
175176
processed_gaze_vectors));
176177
/** ---------------- End of graph ---------------- **/
177178
/** Configure networks **/
178-
auto face_net = cv::gapi::ie::Params<nets::Faces>{
179+
auto face_net = cv::gapi::ov::Params<nets::Faces>{
179180
FLAGS_m_fd, // path to topology IR
180181
fileNameNoExt(FLAGS_m_fd) + ".bin", // path to weights
181182
FLAGS_d_fd, // device specifier
@@ -210,11 +211,11 @@ int main(int argc, char* argv[]) {
210211

211212
if (std::fabs(imageAspectRatio - networkAspectRatio) > aspectRatioThreshold) {
212213
inShape[3] = static_cast<unsigned long>(inShape[2] * imageAspectRatio);
213-
face_net.cfgInputReshape(input.get_any_name(), inShape);
214+
face_net.cfgReshape(inShape);
214215
}
215216
}
216217
auto head_net =
217-
cv::gapi::ie::Params<nets::HeadPose>{
218+
cv::gapi::ov::Params<nets::HeadPose>{
218219
FLAGS_m_hp, // path to topology IR
219220
fileNameNoExt(FLAGS_m_hp) + ".bin", // path to weights
220221
FLAGS_d_hp, // device specifier
@@ -223,7 +224,7 @@ int main(int argc, char* argv[]) {
223224
slog::info << "The Head Pose Estimation model " << FLAGS_m_hp << " is loaded to " << FLAGS_d_hp << " device."
224225
<< slog::endl;
225226

226-
auto landmarks_net = cv::gapi::ie::Params<nets::Landmarks>{
227+
auto landmarks_net = cv::gapi::ov::Params<nets::Landmarks>{
227228
FLAGS_m_lm, // path to topology IR
228229
fileNameNoExt(FLAGS_m_lm) + ".bin", // path to weights
229230
FLAGS_d_lm, // device specifier
@@ -233,7 +234,7 @@ int main(int argc, char* argv[]) {
233234

234235
// clang-format off
235236
auto gaze_net =
236-
cv::gapi::ie::Params<nets::Gaze>{
237+
cv::gapi::ov::Params<nets::Gaze>{
237238
FLAGS_m, // path to topology IR
238239
fileNameNoExt(FLAGS_m) + ".bin", // path to weights
239240
FLAGS_d, // device specifier
@@ -242,7 +243,7 @@ int main(int argc, char* argv[]) {
242243
slog::info << "The Gaze Estimation model " << FLAGS_m << " is loaded to " << FLAGS_d << " device."
243244
<< slog::endl;
244245

245-
auto eyes_net = cv::gapi::ie::Params<nets::Eyes>{
246+
auto eyes_net = cv::gapi::ov::Params<nets::Eyes>{
246247
FLAGS_m_es, // path to topology IR
247248
fileNameNoExt(FLAGS_m_es) + ".bin", // path to weights
248249
FLAGS_d_es, // device specifier

demos/gesture_recognition_demo/cpp_gapi/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <opencv2/gapi/gstreaming.hpp>
2727
#include <opencv2/gapi/infer.hpp>
2828
#include <opencv2/gapi/infer/ie.hpp>
29+
#include <opencv2/gapi/infer/ov.hpp>
2930
#include <opencv2/gapi/streaming/source.hpp>
3031
#include <opencv2/highgui.hpp>
3132
#include <opencv2/imgproc.hpp>
@@ -135,7 +136,7 @@ int main(int argc, char* argv[]) {
135136
/** Configure networks **/
136137
// clang-format off
137138
auto person_detection =
138-
cv::gapi::ie::Params<nets::PersonDetection>{
139+
cv::gapi::ov::Params<nets::PersonDetection>{
139140
FLAGS_m_d, // path to model
140141
fileNameNoExt(FLAGS_m_d) + ".bin", // path to weights
141142
FLAGS_d_d // device to use
@@ -148,7 +149,7 @@ int main(int argc, char* argv[]) {
148149

149150
// clang-format off
150151
auto action_recognition =
151-
cv::gapi::ie::Params<nets::ActionRecognition>{
152+
cv::gapi::ov::Params<nets::ActionRecognition>{
152153
FLAGS_m_a, // path to model
153154
fileNameNoExt(FLAGS_m_a) + ".bin", // path to weights
154155
FLAGS_d_a // device to use

demos/tests/cases.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ def single_option_cases(key, *args):
170170

171171

172172
DEMOS = [
173-
# CppDemo(name='background_subtraction_demo', device_keys=['-d'], implementation='cpp_gapi', test_cases=combine_cases(
174-
# TestCase(options={'--no_show': None, '-at': 'maskrcnn',
175-
# **MONITORS,
176-
# '-i': DataPatternArg('coco128-subset-480x640x3'),
177-
# }),
178-
# single_option_cases('-m',
179-
# ModelArg('instance-segmentation-person-0007'),
180-
# ModelArg('instance-segmentation-security-0091')),
181-
# )),
173+
CppDemo(name='background_subtraction_demo', device_keys=['-d'], implementation='cpp_gapi', test_cases=combine_cases(
174+
TestCase(options={'--no_show': None, '-at': 'maskrcnn',
175+
**MONITORS,
176+
'-i': DataPatternArg('coco128-subset-480x640x3'),
177+
}),
178+
single_option_cases('-m',
179+
ModelArg('instance-segmentation-person-0007'),
180+
ModelArg('instance-segmentation-security-0091')),
181+
)),
182182

183183
CppDemo('classification_benchmark_demo', 'cpp_gapi', test_cases=combine_cases(
184184
single_option_cases(
@@ -254,8 +254,7 @@ def single_option_cases(key, *args):
254254
device_keys=['-d', '-d_fd', '-d_hp', '-d_lm', '-d_es'],
255255
test_cases=combine_cases(
256256
TestCase(options={'-no_show': None,
257-
**MONITORS,
258-
'-i': TestDataArg('coco128/images/train2017/')}),
257+
**MONITORS}),
259258
TestCase(options={
260259
'-m': ModelArg('gaze-estimation-adas-0002'),
261260
'-m_hp': ModelArg('head-pose-estimation-adas-0001'),
@@ -266,23 +265,27 @@ def single_option_cases(key, *args):
266265
'-m_fd',
267266
ModelArg('face-detection-adas-0001'),
268267
ModelArg('face-detection-retail-0004')),
268+
single_option_cases(
269+
'-i',
270+
str('/tmp/video.mp4'),
271+
DataPatternArg('coco128-every-480x640x3')),
269272
)),
270273

271-
CppDemo(name='gesture_recognition_demo', implementation='cpp_gapi',
272-
model_keys=['-m_a', '-m_d'],
273-
device_keys=['-d_a', '-d_d'],
274-
test_cases=combine_cases(
275-
TestCase(options={'--no_show': None,
276-
'-i': DataPatternArg('coco128-every-480x640x3'),
277-
'-m_d': ModelArg('person-detection-asl-0001')}),
278-
[
279-
TestCase(options={'-m_a': ModelArg('asl-recognition-0004'), '-c': str(OMZ_DIR / 'data/dataset_classes/msasl100.json')}),
280-
TestCase(options={'-m_a': ModelArg('common-sign-language-0001'),
281-
'-c': str(OMZ_DIR / 'data/dataset_classes/jester27.json')}),
282-
TestCase(options={'-m_a': ModelArg('common-sign-language-0002'),
283-
'-c': str(OMZ_DIR / 'data/dataset_classes/common_sign_language12.json')}),
284-
],
285-
)),
274+
# CppDemo(name='gesture_recognition_demo', implementation='cpp_gapi',
275+
# model_keys=['-m_a', '-m_d'],
276+
# device_keys=['-d_a', '-d_d'],
277+
# test_cases=combine_cases(
278+
# TestCase(options={'--no_show': None,
279+
# '-i': DataPatternArg('coco128-every-480x640x3'),
280+
# '-m_d': ModelArg('person-detection-asl-0001')}),
281+
# [
282+
# TestCase(options={'-m_a': ModelArg('asl-recognition-0004'), '-c': str(OMZ_DIR / 'data/dataset_classes/msasl100.json')}),
283+
# TestCase(options={'-m_a': ModelArg('common-sign-language-0001'),
284+
# '-c': str(OMZ_DIR / 'data/dataset_classes/jester27.json')}),
285+
# TestCase(options={'-m_a': ModelArg('common-sign-language-0002'),
286+
# '-c': str(OMZ_DIR / 'data/dataset_classes/common_sign_language12.json')}),
287+
# ],
288+
# )),
286289

287290
CppDemo(
288291
'interactive_face_detection_demo', 'cpp_gapi',

demos/tests/run_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@
5151
from cases import Demo
5252
from data_sequences import DATA_SEQUENCES
5353

54+
import shutil
55+
import requests
56+
5457
scopes = {
5558
'base': importlib.import_module('cases').DEMOS,
5659
'performance': importlib.import_module('performance_cases').DEMOS,
5760
}
5861
COCO128_URL = "https://ultralytics.com/assets/coco128.zip"
62+
VIDEO_URL = "https://storage.openvinotoolkit.org/data/test_data/videos/head-pose-face-detection-male.mp4"
5963

6064

6165
def parser_paths_list(supported_devices):
@@ -247,6 +251,16 @@ def main():
247251
with ZipFile(BytesIO(zipresp.read())) as zfile:
248252
zfile.extractall(args.test_data_dir)
249253

254+
try:
255+
r = requests.get(VIDEO_URL)
256+
with open("video.mp4", 'wb') as f:
257+
f.write(r.content)
258+
print('Video for demos downloaded successfully')
259+
shutil.copy("video.mp4", "/tmp/")
260+
except requests.exceptions.HTTPError as err:
261+
print(err)
262+
263+
250264
with temp_dir_as_path() as global_temp_dir:
251265
if args.models_dir:
252266
dl_dir = args.models_dir

0 commit comments

Comments
 (0)