Skip to content

Commit 78201d4

Browse files
authored
demos: fix warnings (#3847)
1 parent f08b9b0 commit 78201d4

File tree

12 files changed

+39
-78
lines changed

12 files changed

+39
-78
lines changed

.github/workflows/cpp_gapi-demos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: build_demos.sh
4444
run: |
4545
source ov/setupvars.sh
46-
OpenCV_DIR=$GITHUB_WORKSPACE/cache/opencv/build CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_CXX_LINKER_LAUNCHER=ccache ./demos/build_demos.sh --build_dir=build
46+
OpenCV_DIR=$GITHUB_WORKSPACE/cache/opencv/build CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_CXX_LINKER_LAUNCHER=ccache ./demos/build_demos.sh --build_dir=build # TODO: add CMAKE_CXX_FLAGS=-Werror after background_subtraction_demo/cpp_gapi is updated to ov2.0
4747
- uses: actions/setup-python@v4
4848
with:
4949
python-version: 3.11

ci/dependencies.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openvino_linux: 'l_openvino_toolkit_ubuntu20_2023.1.0.dev20230623_x86_64'
2-
openvino_windows: 'w_openvino_toolkit_windows_2023.1.0.dev20230623_x86_64'
3-
wheel_linux: '2023.0.0-10926'
4-
wheel_windows: '2023.1.0.dev20230623'
1+
openvino_linux: 'https://storage.openvinotoolkit.org/repositories/openvino/packages/master/2023.1.0.dev20230811/l_openvino_toolkit_ubuntu20_2023.1.0.dev20230811_x86_64.tgz'
2+
openvino_windows: 'https://storage.openvinotoolkit.org/repositories/openvino/packages/master/2023.1.0.dev20230811/w_openvino_toolkit_windows_2023.1.0.dev20230811_x86_64.zip'
3+
wheel_linux: '2023.1.0.dev20230811'
4+
wheel_windows: '2023.1.0.dev20230811'

demos/classification_benchmark_demo/cpp_gapi/include/custom_kernels.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <string>
1010
#include <vector>
1111

12-
#include <ie_allocator.hpp>
13-
#include <ie_common.h>
14-
#include <ie_input_info.hpp>
1512
#include <opencv2/core.hpp>
1613
#include <opencv2/gapi/gkernel.hpp>
1714
#include <opencv2/gapi/gmat.hpp>

demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,11 @@ void ModelYoloV3ONNX::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
107107
std::shared_ptr<InternalModelData> ModelYoloV3ONNX::preprocess(const InputData& inputData,
108108
ov::InferRequest& request) {
109109
const auto& origImg = inputData.asRef<ImageInputData>().inputImage;
110-
111-
cv::Mat info(cv::Size(1, 2), CV_32SC1);
112-
info.at<int>(0, 0) = origImg.rows;
113-
info.at<int>(0, 1) = origImg.cols;
114-
auto allocator = std::make_shared<SharedTensorAllocator>(info);
115-
ov::Tensor infoInput = ov::Tensor(ov::element::i32, ov::Shape({1, 2}), ov::Allocator(allocator));
116-
117-
request.set_tensor(inputsNames[1], infoInput);
118-
110+
ov::Tensor info{ov::element::i32, ov::Shape({1, 2})};
111+
int32_t* data = info.data<int32_t>();
112+
data[0] = origImg.rows;
113+
data[1] = origImg.cols;
114+
request.set_tensor(inputsNames[1], info);
119115
return ImageModel::preprocess(inputData, request);
120116
}
121117

demos/common/cpp/utils/include/utils/ocv_common.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ static UNUSED ov::Tensor wrapMat2Tensor(const cv::Mat& mat) {
9696
throw std::runtime_error("Doesn't support conversion from not dense cv::Mat");
9797
}
9898
auto precision = isMatFloat ? ov::element::f32 : ov::element::u8;
99-
auto allocator = std::make_shared<SharedTensorAllocator>(mat);
100-
return ov::Tensor(precision, ov::Shape{ 1, height, width, channels }, ov::Allocator(allocator));
99+
return ov::Tensor(precision, ov::Shape{ 1, height, width, channels }, SharedMatAllocator{mat});
101100
}
102101

103102
static inline void resize2tensor(const cv::Mat& mat, const ov::Tensor& tensor) {

demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,10 @@
1717
#pragma once
1818

1919
#include <opencv2/core.hpp>
20-
#include <openvino/runtime/allocator.hpp>
2120

22-
// To prevent false-positive clang compiler warning
23-
// (https://github.com/openvinotoolkit/openvino/pull/11092#issuecomment-1073846256):
24-
// warning: destructor called on non-final 'SharedTensorAllocator' that has virtual functions
25-
// but non-virtual destructor [-Wdelete-non-abstract-non-virtual-dtor]
26-
// SharedTensorAllocator class declared as final
27-
28-
class SharedTensorAllocator final : public ov::AllocatorImpl {
29-
public:
30-
SharedTensorAllocator(const cv::Mat& img) : img(img) {}
31-
32-
~SharedTensorAllocator() = default;
33-
34-
void* allocate(const size_t bytes, const size_t) override {
35-
return bytes <= img.rows * img.step[0] ? img.data : nullptr;
36-
}
37-
38-
void deallocate(void* handle, const size_t bytes, const size_t) override {}
39-
40-
bool is_equal(const AllocatorImpl& other) const override {
41-
auto other_tensor_allocator = dynamic_cast<const SharedTensorAllocator*>(&other);
42-
return other_tensor_allocator != nullptr && other_tensor_allocator == this;
43-
}
44-
45-
private:
46-
const cv::Mat img;
21+
struct SharedMatAllocator {
22+
const cv::Mat mat;
23+
void* allocate(size_t bytes, size_t) {return bytes <= mat.rows * mat.step[0] ? mat.data : nullptr;}
24+
void deallocate(void*, size_t, size_t) {}
25+
bool is_equal(const SharedMatAllocator& other) const noexcept {return this == &other;}
4726
};

demos/gaze_estimation_demo/cpp_gapi/main.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
#include <utility>
1919
#include <vector>
2020

21-
#include <cpp/ie_cnn_network.h>
2221
#include <gflags/gflags.h>
23-
#include <ie_core.hpp>
24-
#include <ie_input_info.hpp>
25-
#include <ie_layouts.h>
2622
#include <opencv2/core.hpp>
2723
#include <opencv2/gapi/core.hpp>
2824
#include <opencv2/gapi/garg.hpp>
@@ -205,19 +201,16 @@ int main(int argc, char* argv[]) {
205201
stringToSize(FLAGS_res));
206202

207203
if (FLAGS_fd_reshape) {
208-
InferenceEngine::Core core;
209-
const auto network = core.ReadNetwork(FLAGS_m_fd);
210-
const auto layerName = network.getInputsInfo().begin()->first;
211-
const auto layerData = network.getInputsInfo().begin()->second;
212-
auto layerDims = layerData->getTensorDesc().getDims();
204+
ov::Output<const ov::Node> input = ov::Core{}.read_model(FLAGS_m_fd)->input();
205+
ov::Shape inShape = input.get_shape();
213206

214207
const double imageAspectRatio = std::round(100. * frame_size.width / frame_size.height) / 100.;
215-
const double networkAspectRatio = std::round(100. * layerDims[3] / layerDims[2]) / 100.;
208+
const double networkAspectRatio = std::round(100. * inShape[3] / inShape[2]) / 100.;
216209
const double aspectRatioThreshold = 0.01;
217210

218211
if (std::fabs(imageAspectRatio - networkAspectRatio) > aspectRatioThreshold) {
219-
layerDims[3] = static_cast<unsigned long>(layerDims[2] * imageAspectRatio);
220-
face_net.cfgInputReshape(layerName, layerDims);
212+
inShape[3] = static_cast<unsigned long>(inShape[2] * imageAspectRatio);
213+
face_net.cfgInputReshape(input.get_any_name(), inShape);
221214
}
222215
}
223216
auto head_net =

demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
#include <stdexcept>
1212
#include <utility>
1313

14-
#include <cpp/ie_cnn_network.h>
15-
#include <ie_core.hpp>
16-
#include <ie_input_info.hpp>
17-
#include <ie_layouts.h>
14+
#include <openvino/openvino.hpp>
1815

1916
#define _USE_MATH_DEFINES
2017

2118
cv::Scalar getNetShape(const std::string& path) {
22-
const auto network = InferenceEngine::Core{}.ReadNetwork(path);
23-
const auto layerData = network.getInputsInfo().begin()->second;
24-
const auto layerDims = layerData->getTensorDesc().getDims();
25-
26-
const int step = layerDims.size() == 5 ? 1 : 0;
27-
return cv::Scalar(static_cast<double>(layerDims[0 + step]),
28-
static_cast<double>(layerDims[1 + step]),
29-
static_cast<double>(layerDims[2 + step]),
30-
static_cast<double>(layerDims[3 + step]));
19+
ov::Shape shape = ov::Core{}.read_model(path)->input().get_shape();
20+
const int step = shape.size() == 5 ? 1 : 0;
21+
return cv::Scalar(static_cast<double>(shape[0 + step]),
22+
static_cast<double>(shape[1 + step]),
23+
static_cast<double>(shape[2 + step]),
24+
static_cast<double>(shape[3 + step]));
3125
}
3226

3327
void erase(std::string& str, const char symbol) {

demos/pedestrian_tracker_demo/cpp/include/logging.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#include <details/ie_exception.hpp>
7+
#include <opencv2/core.hpp>
88

99
#define PT_CHECK(cond) CV_Assert(cond);
1010

demos/smart_classroom_demo/cpp_gapi/src/logger.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <memory>
1010
#include <utility>
1111

12-
#include <ie_common.h>
13-
1412
#include "tracker.hpp"
1513

1614
namespace {

0 commit comments

Comments
 (0)