Skip to content

Commit c9f79ab

Browse files
authored
Merge branch 'openvinotoolkit:master' into master
2 parents 19a3139 + d6647c6 commit c9f79ab

File tree

30 files changed

+375
-414
lines changed

30 files changed

+375
-414
lines changed

demos/action_recognition_demo/python/action_recognition_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main():
8888
core = Core()
8989

9090
if 'MYRIAD' in args.device:
91-
myriad_config = {'VPU_HW_STAGES_OPTIMIZATION': 'YES'}
91+
myriad_config = {'MYRIAD_ENABLE_HW_ACCELERATION': 'YES'}
9292
core.set_config(myriad_config, 'MYRIAD')
9393

9494
decoder_target_device = 'CPU'

demos/background_subtraction_demo/cpp_gapi/main.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <utils/args_helper.hpp>
77
#include <utils_gapi/stream_source.hpp>
88
#include <utils/config_factory.h>
9+
#include <utils/ocv_common.hpp>
910

1011
#include <opencv2/gapi/streaming/cap.hpp>
1112
#include <opencv2/gapi/imgproc.hpp>
@@ -160,20 +161,13 @@ int main(int argc, char *argv[]) {
160161
cv::Size graphSize{static_cast<int>(frame_size.width / 4), 60};
161162
Presenter presenter(FLAGS_u, frame_size.height - graphSize.height - 10, graphSize);
162163

163-
/** Save output result **/
164-
cv::VideoWriter videoWriter;
165-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
166-
cap->fps(), frame_size)) {
167-
throw std::runtime_error("Can't open video writer");
168-
}
164+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
169165

170166
bool isStart = true;
171-
uint64_t curr_frame_num = 0;
172167
const auto startTime = std::chrono::steady_clock::now();
173168
pipeline.start();
174169

175170
while(pipeline.pull(cv::gout(output))) {
176-
++curr_frame_num;
177171
presenter.drawGraphs(output);
178172
if (isStart) {
179173
metrics.update(startTime, output, { 10, 22 }, cv::FONT_HERSHEY_COMPLEX,
@@ -185,10 +179,7 @@ int main(int argc, char *argv[]) {
185179
0.65, { 200, 10, 10 }, 2, PerformanceMetrics::MetricTypes::FPS);
186180
}
187181

188-
if (videoWriter.isOpened() &&
189-
(FLAGS_limit <= 0 || curr_frame_num <= FLAGS_limit)) {
190-
videoWriter.write(output);
191-
}
182+
videoWriter.write(output);
192183

193184
if (!FLAGS_no_show) {
194185
cv::imshow(windowName, output);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,23 @@ void logBasicModelInfo(const std::shared_ptr<ov::Model>& model) {
317317
ov::OutputVector outputs = model->outputs();
318318

319319
slog::info << "inputs: " << slog::endl;
320-
for (const ov::Output<ov::Node> input : inputs)
321-
{
320+
for (const ov::Output<ov::Node>& input : inputs) {
322321
const std::string name = input.get_any_name();
323322
const ov::element::Type type = input.get_element_type();
324323
const ov::PartialShape shape = input.get_partial_shape();
324+
const ov::Layout layout = ov::layout::get_layout(input);
325325

326-
slog::info << name << ", " << type << ", " << shape << slog::endl;
326+
slog::info << name << ", " << type << ", " << shape << ", " << layout.to_string() << slog::endl;
327327
}
328328

329329
slog::info << "outputs: " << slog::endl;
330-
for (const ov::Output<ov::Node> output : outputs)
331-
{
330+
for (const ov::Output<ov::Node>& output : outputs) {
332331
const std::string name = output.get_any_name();
333332
const ov::element::Type type = output.get_element_type();
334333
const ov::PartialShape shape = output.get_partial_shape();
334+
const ov::Layout layout = ov::layout::get_layout(output);
335335

336-
slog::info << name << ", " << type << ", " << shape << slog::endl;
336+
slog::info << name << ", " << type << ", " << shape << ", " << layout.to_string() << slog::endl;
337337
}
338338

339339
return;

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ inline void matToBlob(const cv::Mat& mat, const InferenceEngine::Blob::Ptr& blob
8787
*/
8888
static UNUSED void matToTensor(const cv::Mat& mat, const ov::Tensor& tensor, int batchIndex = 0) {
8989
ov::Shape tensorShape = tensor.get_shape();
90-
ov::Layout layout("NCHW");
90+
static const ov::Layout layout{"NCHW"};
9191
const size_t width = tensorShape[ov::layout::width_idx(layout)];
9292
const size_t height = tensorShape[ov::layout::height_idx(layout)];
9393
const size_t channels = tensorShape[ov::layout::channels_idx(layout)];
@@ -315,3 +315,28 @@ class InputTransform {
315315
cv::Scalar means;
316316
cv::Scalar stdScales;
317317
};
318+
319+
class LazyVideoWriter {
320+
cv::VideoWriter writer;
321+
unsigned nwritten;
322+
public:
323+
const std::string filenames;
324+
const double fps;
325+
const unsigned lim;
326+
327+
LazyVideoWriter(const std::string& filenames, double fps, unsigned lim) :
328+
nwritten{1}, filenames{filenames}, fps{fps}, lim{lim} {}
329+
void write(cv::InputArray im) {
330+
if (writer.isOpened() && (nwritten < lim || 0 == lim)) {
331+
writer.write(im);
332+
++nwritten;
333+
return;
334+
}
335+
if (!writer.isOpened() && !filenames.empty()) {
336+
if (!writer.open(filenames, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), fps, im.size())) {
337+
throw std::runtime_error("Can't open video writer");
338+
}
339+
writer.write(im);
340+
}
341+
}
342+
};

demos/crossroad_camera_demo/cpp/main.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ int main(int argc, char* argv[]) {
8888
throw std::logic_error("Can't read an image from the input");
8989
}
9090

91-
cv::VideoWriter videoWriter;
92-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
93-
cap->fps(), frame.size())) {
94-
throw std::runtime_error("Can't open video writer");
95-
}
96-
uint32_t framesProcessed = 0;
91+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
9792
cv::Size graphSize{frame.cols / 4, 60};
9893
Presenter presenter(FLAGS_u, frame.rows - graphSize.height - 10, graphSize);
9994

@@ -310,10 +305,7 @@ int main(int argc, char* argv[]) {
310305
}
311306
}
312307
}
313-
framesProcessed++;
314-
if (videoWriter.isOpened() && (FLAGS_limit == 0 || framesProcessed <= FLAGS_limit)) {
315-
videoWriter.write(frame);
316-
}
308+
videoWriter.write(frame);
317309
if (!FLAGS_no_show) {
318310
cv::imshow("Detection results", frame);
319311
const int key = cv::waitKey(1);

demos/face_detection_mtcnn_demo/cpp_gapi/main.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,7 @@ int main(int argc, char* argv[]) {
179179
cv::Size graphSize{static_cast<int>(frame_size.width / 4), 60};
180180
Presenter presenter(FLAGS_u, frame_size.height - graphSize.height - 10, graphSize);
181181

182-
/** Save output result **/
183-
cv::VideoWriter videoWriter;
184-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
185-
cap->fps(), frame_size)) {
186-
throw std::runtime_error("Can't open video writer");
187-
}
182+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
188183

189184
/** Output Mat for result **/
190185
cv::Mat out_image;
@@ -201,9 +196,7 @@ int main(int argc, char* argv[]) {
201196
metrics.update({}, out_image, { 10, 22 }, cv::FONT_HERSHEY_COMPLEX,
202197
0.65, { 200, 10, 10 }, 2, PerformanceMetrics::MetricTypes::FPS);
203198
}
204-
if (videoWriter.isOpened()) {
205-
videoWriter.write(out_image);
206-
}
199+
videoWriter.write(out_image);
207200
if (!FLAGS_no_show) {
208201
cv::imshow("Face detection mtcnn demo G-API", out_image);
209202
int key = cv::waitKey(1);

demos/gaze_estimation_demo/cpp/main.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ int main(int argc, char* argv[]) {
112112
throw std::runtime_error("Can't read an image from the input");
113113
}
114114

115-
cv::VideoWriter videoWriter;
116-
if (!FLAGS_o.empty() &&
117-
!videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), cap->fps(), frame.size()))
118-
{
119-
throw std::runtime_error("Can't open video writer");
120-
}
121-
uint32_t framesProcessed = 0;
115+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
122116
cv::Size graphSize{frame.cols / 4, 60};
123117
Presenter presenter(FLAGS_u, frame.rows - graphSize.height - 10, graphSize);
124118

@@ -148,10 +142,7 @@ int main(int argc, char* argv[]) {
148142
}
149143
}
150144

151-
framesProcessed++;
152-
if (videoWriter.isOpened() && (FLAGS_limit == 0 || framesProcessed <= FLAGS_limit)) {
153-
videoWriter.write(frame);
154-
}
145+
videoWriter.write(frame);
155146
if (!FLAGS_no_show) {
156147
cv::imshow(windowName, frame);
157148

demos/gaze_estimation_demo/cpp_gapi/main.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,7 @@ int main(int argc, char *argv[]) {
246246
cv::Size graphSize{static_cast<int>(frame_size.width / 4), 60};
247247
Presenter presenter(FLAGS_u, frame_size.height - graphSize.height - 10, graphSize);
248248

249-
/** Save output result **/
250-
cv::VideoWriter videoWriter;
251-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
252-
cap->fps(), frame_size)) {
253-
throw std::runtime_error("Can't open video writer");
254-
}
249+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
255250

256251
bool isStart = true;
257252
const auto startTime = std::chrono::steady_clock::now();
@@ -317,9 +312,7 @@ int main(int argc, char *argv[]) {
317312
}
318313
}
319314

320-
if (videoWriter.isOpened()) {
321-
videoWriter.write(frame);
322-
}
315+
videoWriter.write(frame);
323316
if (!FLAGS_no_show) {
324317
cv::imshow(windowName, frame);
325318
/** Controls the information being displayed while demo runs **/

demos/gesture_recognition_demo/cpp_gapi/main.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,7 @@ int main(int argc, char *argv[]) {
141141
cv::Size graphSize{static_cast<int>(frame_size.width / 4), 60};
142142
Presenter presenter(FLAGS_u, frame_size.height - graphSize.height - 10, graphSize);
143143

144-
/** Save output result **/
145-
cv::VideoWriter videoWriter;
146-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
147-
cap->fps(), frame_size)) {
148-
throw std::runtime_error("Can't open video writer");
149-
}
144+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
150145

151146
/** Fill labels container from file with classes **/
152147
const auto labels = fill_labels(FLAGS_c);
@@ -177,9 +172,7 @@ int main(int argc, char *argv[]) {
177172
visualizer.show(out_frame, out_detections, out_label_number, current_id, gesture);
178173
gesture = 0;
179174

180-
if (videoWriter.isOpened()) {
181-
videoWriter.write(out_frame);
182-
}
175+
videoWriter.write(out_frame);
183176

184177
/** Controls **/
185178
int key = cv::waitKey(1);

demos/human_pose_estimation_demo/cpp/main.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
223223
throw std::logic_error("Can't read an image from the input");
224224
}
225225

226-
cv::VideoWriter videoWriter;
226+
LazyVideoWriter videoWriter{FLAGS_o, cap->fps(), FLAGS_limit};
227227

228228
OutputTransform outputTransform = OutputTransform();
229229
cv::Size outputResolution = curr_frame.size();
@@ -236,10 +236,6 @@ int main(int argc, char *argv[]) {
236236
outputTransform = OutputTransform(curr_frame.size(), outputResolution);
237237
outputResolution = outputTransform.computeResolution();
238238
}
239-
if (!FLAGS_o.empty() && !videoWriter.open(FLAGS_o, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
240-
cap->fps(), outputResolution)) {
241-
throw std::runtime_error("Can't open video writer");
242-
}
243239

244240
//------------------------------ Running Human Pose Estimation routines ----------------------------------------------
245241

@@ -302,9 +298,7 @@ int main(int argc, char *argv[]) {
302298
renderMetrics.update(renderingStart);
303299
metrics.update(result->metaData->asRef<ImageMetaData>().timeStamp,
304300
outFrame, { 10, 22 }, cv::FONT_HERSHEY_COMPLEX, 0.65);
305-
if (videoWriter.isOpened() && (FLAGS_limit == 0 || framesProcessed <= FLAGS_limit - 1)) {
306-
videoWriter.write(outFrame);
307-
}
301+
videoWriter.write(outFrame);
308302
framesProcessed++;
309303
if (!FLAGS_no_show) {
310304
cv::imshow("Human Pose Estimation Results", outFrame);
@@ -331,9 +325,7 @@ int main(int argc, char *argv[]) {
331325
renderMetrics.update(renderingStart);
332326
metrics.update(result->metaData->asRef<ImageMetaData>().timeStamp,
333327
outFrame, { 10, 22 }, cv::FONT_HERSHEY_COMPLEX, 0.65);
334-
if (videoWriter.isOpened() && (FLAGS_limit == 0 || framesProcessed <= FLAGS_limit - 1)) {
335-
videoWriter.write(outFrame);
336-
}
328+
videoWriter.write(outFrame);
337329
if (!FLAGS_no_show) {
338330
cv::imshow("Human Pose Estimation Results", outFrame);
339331
//--- Updating output window

0 commit comments

Comments
 (0)