Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code style for remaining demos (1 part) #3437

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/common/cpp/pipelines/include/pipelines/metadata.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
// Copyright (C) 2018-2020 Intel Corporation
// Copyright (C) 2020-2022 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
66 changes: 38 additions & 28 deletions demos/crossroad_camera_demo/cpp/crossroad_camera_demo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,50 @@

///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <iostream>

#include "gflags/gflags.h"
#include "utils/default_flags.hpp"
#include <gflags/gflags.h>

#include <utils/default_flags.hpp>

DEFINE_INPUT_FLAGS
DEFINE_OUTPUT_FLAGS

static const char help_message[] = "Print a usage message.";
static const char person_vehicle_bike_detection_model_message[] = "Required. Path to the Person/Vehicle/Bike Detection Crossroad model (.xml) file.";
static const char person_attribs_model_message[] = "Optional. Path to the Person Attributes Recognition Crossroad model (.xml) file.";
static const char person_reid_model_message[] = "Optional. Path to the Person Reidentification Retail model (.xml) file.";
static const char target_device_message[] = "Optional. Specify the target device for Person/Vehicle/Bike Detection. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char target_device_message_person_attribs[] = "Optional. Specify the target device for Person Attributes Recognition. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char target_device_message_person_reid[] = "Optional. Specify the target device for Person Reidentification Retail. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char threshold_output_message[] = "Optional. Probability threshold for person/vehicle/bike crossroad detections.";
static const char threshold_output_message_person_reid[] = "Optional. Cosine similarity threshold between two vectors for person reidentification.";
static const char person_vehicle_bike_detection_model_message[] =
"Required. Path to the Person/Vehicle/Bike Detection Crossroad model (.xml) file.";
static const char person_attribs_model_message[] =
"Optional. Path to the Person Attributes Recognition Crossroad model (.xml) file.";
static const char person_reid_model_message[] =
"Optional. Path to the Person Reidentification Retail model (.xml) file.";
static const char target_device_message[] =
"Optional. Specify the target device for Person/Vehicle/Bike Detection. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char target_device_message_person_attribs[] =
"Optional. Specify the target device for Person Attributes Recognition. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char target_device_message_person_reid[] =
"Optional. Specify the target device for Person Reidentification Retail. "
"The list of available devices is shown below. Default value is CPU. "
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.";
static const char threshold_output_message[] =
"Optional. Probability threshold for person/vehicle/bike crossroad detections.";
static const char threshold_output_message_person_reid[] =
"Optional. Cosine similarity threshold between two vectors for person reidentification.";
static const char raw_output_message[] = "Optional. Output Inference results as raw values.";
static const char no_show_message[] = "Optional. Don't show output.";
static const char input_resizable_message[] = "Optional. Enables resizable input with support of ROI crop & auto resize.";
static const char input_resizable_message[] =
"Optional. Enables resizable input with support of ROI crop & auto resize.";
static const char utilization_monitors_message[] = "Optional. List of monitors to show initially.";
static const char person_label_message[] = "Optional. The integer index of the objects' category corresponding to persons "
"(as it is returned from the detection network, may vary from one network to another). "
"The default value is 1.";

static const char person_label_message[] =
"Optional. The integer index of the objects' category corresponding to persons "
"(as it is returned from the detection network, may vary from one network to another). "
"The default value is 1.";

DEFINE_bool(h, false, help_message);
DEFINE_string(m, "", person_vehicle_bike_detection_model_message);
Expand All @@ -53,10 +64,9 @@ DEFINE_bool(auto_resize, false, input_resizable_message);
DEFINE_string(u, "", utilization_monitors_message);
DEFINE_int32(person_label, 1, person_label_message);


/**
* @brief This function show a help message
*/
* @brief This function show a help message
*/
static void showUsage() {
std::cout << std::endl;
std::cout << "crossroad_camera_demo [OPTION]" << std::endl;
Expand All @@ -67,7 +77,7 @@ static void showUsage() {
std::cout << " -loop " << loop_message << std::endl;
std::cout << " -o \"<path>\" " << output_message << std::endl;
std::cout << " -limit \"<num>\" " << limit_message << std::endl;
std::cout << " -m \"<path>\" " << person_vehicle_bike_detection_model_message<< std::endl;
std::cout << " -m \"<path>\" " << person_vehicle_bike_detection_model_message << std::endl;
std::cout << " -m_pa \"<path>\" " << person_attribs_model_message << std::endl;
std::cout << " -m_reid \"<path>\" " << person_reid_model_message << std::endl;
std::cout << " -d \"<device>\" " << target_device_message << std::endl;
Expand Down
23 changes: 16 additions & 7 deletions demos/crossroad_camera_demo/cpp/detection_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <memory>
#include <string>
#include "openvino/openvino.hpp"
#include "utils/slog.hpp"

#include <opencv2/core/types.hpp>
#include <openvino/openvino.hpp>

#include <utils/ocv_common.hpp>
#include <utils/slog.hpp>

#pragma once

Expand All @@ -17,8 +22,9 @@ struct BaseDetection {
std::string m_inputName;
std::string m_outputName;

BaseDetection(std::string& commandLineFlag, const std::string& detectorName) :
m_commandLineFlag(commandLineFlag), m_detectorName(detectorName) {}
BaseDetection(std::string& commandLineFlag, const std::string& detectorName)
: m_commandLineFlag(commandLineFlag),
m_detectorName(detectorName) {}

ov::CompiledModel* operator->() {
return &m_compiled_model;
Expand Down Expand Up @@ -53,7 +59,7 @@ struct BaseDetection {
}

virtual void wait() {
if (!enabled()|| !m_infer_request)
if (!enabled() || !m_infer_request)
return;

m_infer_request.wait();
Expand All @@ -62,7 +68,7 @@ struct BaseDetection {
mutable bool m_enablingChecked = false;
mutable bool m_enabled = false;

bool enabled() const {
bool enabled() const {
if (!m_enablingChecked) {
m_enabled = !m_commandLineFlag.empty();
if (!m_enabled) {
Expand All @@ -81,7 +87,10 @@ struct Load {
void into(ov::Core& core, const std::string& deviceName) const {
if (m_detector.enabled()) {
m_detector.m_compiled_model = core.compile_model(m_detector.read(core), deviceName);
logCompiledModelInfo(m_detector.m_compiled_model, m_detector.m_commandLineFlag, deviceName, m_detector.m_detectorName);
logCompiledModelInfo(m_detector.m_compiled_model,
m_detector.m_commandLineFlag,
deviceName,
m_detector.m_detectorName);
}
}
};
46 changes: 24 additions & 22 deletions demos/crossroad_camera_demo/cpp/detection_person.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <memory>
#include <string>
#include <vector>

#include "openvino/openvino.hpp"
#include <gflags/gflags.h>
#include <openvino/openvino.hpp>

#include <utils/slog.hpp>

#include "gflags/gflags.h"
#include "utils/slog.hpp"
#include "detection_base.hpp"
#include "crossroad_camera_demo.hpp"
#include "detection_base.hpp"

struct PersonDetection : BaseDetection {
size_t maxProposalCount;
Expand Down Expand Up @@ -86,25 +89,25 @@ struct PersonDetection : BaseDetection {
throw std::logic_error("Incorrect output dimensions for SSD");
}

const ov::Layout tensor_layout{ "NHWC" };
const ov::Layout tensor_layout{"NHWC"};

ov::preprocess::PrePostProcessor ppp = ov::preprocess::PrePostProcessor(model);

if (FLAGS_auto_resize) {
ppp.input().tensor().
set_element_type(ov::element::u8).
set_spatial_dynamic_shape().
set_layout(tensor_layout);
ppp.input().preprocess().
convert_element_type(ov::element::f32).
convert_layout("NCHW").
resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
ppp.input()
.tensor()
.set_element_type(ov::element::u8)
.set_spatial_dynamic_shape()
.set_layout(tensor_layout);
ppp.input()
.preprocess()
.convert_element_type(ov::element::f32)
.convert_layout("NCHW")
.resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
ppp.input().model().set_layout("NCHW");
ppp.output().tensor().set_element_type(ov::element::f32);
} else {
ppp.input().tensor().
set_element_type(ov::element::u8).
set_layout({ "NCHW" });
ppp.input().tensor().set_element_type(ov::element::u8).set_layout({"NCHW"});
}

model = ppp.build();
Expand All @@ -125,7 +128,7 @@ struct PersonDetection : BaseDetection {
const float* detections = m_infer_request.get_output_tensor().data<float>();
// pretty much regular SSD post-processing
for (size_t i = 0; i < maxProposalCount; i++) {
float image_id = detections[i * objectSize + 0]; // in case of batch
float image_id = detections[i * objectSize + 0]; // in case of batch
if (image_id < 0) {
// end of detections
break;
Expand All @@ -145,11 +148,10 @@ struct PersonDetection : BaseDetection {
}

if (FLAGS_r) {
slog::debug <<
"[" << i << "," << r.label << "] element, prob = " << r.confidence <<
" (" << r.location.x << "," << r.location.y <<
")-(" << r.location.width << "," << r.location.height << ")" <<
((r.confidence > FLAGS_t) ? " WILL BE RENDERED!" : "") << slog::endl;
slog::debug << "[" << i << "," << r.label << "] element, prob = " << r.confidence << " ("
<< r.location.x << "," << r.location.y << ")-(" << r.location.width << ","
<< r.location.height << ")" << ((r.confidence > FLAGS_t) ? " WILL BE RENDERED!" : "")
<< slog::endl;
}
results.push_back(r);
}
Expand Down
Loading