Skip to content

Commit b04405f

Browse files
committed
fix 1 part of remaining demos
1 parent 10f54a1 commit b04405f

40 files changed

+1123
-776
lines changed

demos/crossroad_camera_demo/cpp/crossroad_camera_demo.hpp

+38-28
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,50 @@
44

55
///////////////////////////////////////////////////////////////////////////////////////////////////
66
#pragma once
7+
#include <iostream>
78

8-
#include "gflags/gflags.h"
9-
#include "utils/default_flags.hpp"
9+
#include <gflags/gflags.h>
10+
11+
#include <utils/default_flags.hpp>
1012

1113
DEFINE_INPUT_FLAGS
1214
DEFINE_OUTPUT_FLAGS
1315

1416
static const char help_message[] = "Print a usage message.";
15-
static const char person_vehicle_bike_detection_model_message[] = "Required. Path to the Person/Vehicle/Bike Detection Crossroad model (.xml) file.";
16-
static const char person_attribs_model_message[] = "Optional. Path to the Person Attributes Recognition Crossroad model (.xml) file.";
17-
static const char person_reid_model_message[] = "Optional. Path to the Person Reidentification Retail model (.xml) file.";
18-
static const char target_device_message[] = "Optional. Specify the target device for Person/Vehicle/Bike Detection. "
19-
"The list of available devices is shown below. Default value is CPU. "
20-
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
21-
"The application looks for a suitable plugin for the specified device.";
22-
static const char target_device_message_person_attribs[] = "Optional. Specify the target device for Person Attributes Recognition. "
23-
"The list of available devices is shown below. Default value is CPU. "
24-
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
25-
"The application looks for a suitable plugin for the specified device.";
26-
static const char target_device_message_person_reid[] = "Optional. Specify the target device for Person Reidentification Retail. "
27-
"The list of available devices is shown below. Default value is CPU. "
28-
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
29-
"The application looks for a suitable plugin for the specified device.";
30-
static const char threshold_output_message[] = "Optional. Probability threshold for person/vehicle/bike crossroad detections.";
31-
static const char threshold_output_message_person_reid[] = "Optional. Cosine similarity threshold between two vectors for person reidentification.";
17+
static const char person_vehicle_bike_detection_model_message[] =
18+
"Required. Path to the Person/Vehicle/Bike Detection Crossroad model (.xml) file.";
19+
static const char person_attribs_model_message[] =
20+
"Optional. Path to the Person Attributes Recognition Crossroad model (.xml) file.";
21+
static const char person_reid_model_message[] =
22+
"Optional. Path to the Person Reidentification Retail model (.xml) file.";
23+
static const char target_device_message[] =
24+
"Optional. Specify the target device for Person/Vehicle/Bike Detection. "
25+
"The list of available devices is shown below. Default value is CPU. "
26+
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
27+
"The application looks for a suitable plugin for the specified device.";
28+
static const char target_device_message_person_attribs[] =
29+
"Optional. Specify the target device for Person Attributes Recognition. "
30+
"The list of available devices is shown below. Default value is CPU. "
31+
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
32+
"The application looks for a suitable plugin for the specified device.";
33+
static const char target_device_message_person_reid[] =
34+
"Optional. Specify the target device for Person Reidentification Retail. "
35+
"The list of available devices is shown below. Default value is CPU. "
36+
"Use \"-d HETERO:<comma-separated_devices_list>\" format to specify HETERO plugin. "
37+
"The application looks for a suitable plugin for the specified device.";
38+
static const char threshold_output_message[] =
39+
"Optional. Probability threshold for person/vehicle/bike crossroad detections.";
40+
static const char threshold_output_message_person_reid[] =
41+
"Optional. Cosine similarity threshold between two vectors for person reidentification.";
3242
static const char raw_output_message[] = "Optional. Output Inference results as raw values.";
3343
static const char no_show_message[] = "Optional. Don't show output.";
34-
static const char input_resizable_message[] = "Optional. Enables resizable input with support of ROI crop & auto resize.";
44+
static const char input_resizable_message[] =
45+
"Optional. Enables resizable input with support of ROI crop & auto resize.";
3546
static const char utilization_monitors_message[] = "Optional. List of monitors to show initially.";
36-
static const char person_label_message[] = "Optional. The integer index of the objects' category corresponding to persons "
37-
"(as it is returned from the detection network, may vary from one network to another). "
38-
"The default value is 1.";
39-
47+
static const char person_label_message[] =
48+
"Optional. The integer index of the objects' category corresponding to persons "
49+
"(as it is returned from the detection network, may vary from one network to another). "
50+
"The default value is 1.";
4051

4152
DEFINE_bool(h, false, help_message);
4253
DEFINE_string(m, "", person_vehicle_bike_detection_model_message);
@@ -53,10 +64,9 @@ DEFINE_bool(auto_resize, false, input_resizable_message);
5364
DEFINE_string(u, "", utilization_monitors_message);
5465
DEFINE_int32(person_label, 1, person_label_message);
5566

56-
5767
/**
58-
* @brief This function show a help message
59-
*/
68+
* @brief This function show a help message
69+
*/
6070
static void showUsage() {
6171
std::cout << std::endl;
6272
std::cout << "crossroad_camera_demo [OPTION]" << std::endl;
@@ -67,7 +77,7 @@ static void showUsage() {
6777
std::cout << " -loop " << loop_message << std::endl;
6878
std::cout << " -o \"<path>\" " << output_message << std::endl;
6979
std::cout << " -limit \"<num>\" " << limit_message << std::endl;
70-
std::cout << " -m \"<path>\" " << person_vehicle_bike_detection_model_message<< std::endl;
80+
std::cout << " -m \"<path>\" " << person_vehicle_bike_detection_model_message << std::endl;
7181
std::cout << " -m_pa \"<path>\" " << person_attribs_model_message << std::endl;
7282
std::cout << " -m_reid \"<path>\" " << person_reid_model_message << std::endl;
7383
std::cout << " -d \"<device>\" " << target_device_message << std::endl;

demos/crossroad_camera_demo/cpp/detection_base.hpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//
44

5+
#include <memory>
56
#include <string>
6-
#include "openvino/openvino.hpp"
7-
#include "utils/slog.hpp"
7+
8+
#include <opencv2/core/types.hpp>
9+
#include <openvino/openvino.hpp>
10+
11+
#include <utils/ocv_common.hpp>
12+
#include <utils/slog.hpp>
813

914
#pragma once
1015

@@ -17,8 +22,9 @@ struct BaseDetection {
1722
std::string m_inputName;
1823
std::string m_outputName;
1924

20-
BaseDetection(std::string& commandLineFlag, const std::string& detectorName) :
21-
m_commandLineFlag(commandLineFlag), m_detectorName(detectorName) {}
25+
BaseDetection(std::string& commandLineFlag, const std::string& detectorName)
26+
: m_commandLineFlag(commandLineFlag),
27+
m_detectorName(detectorName) {}
2228

2329
ov::CompiledModel* operator->() {
2430
return &m_compiled_model;
@@ -53,7 +59,7 @@ struct BaseDetection {
5359
}
5460

5561
virtual void wait() {
56-
if (!enabled()|| !m_infer_request)
62+
if (!enabled() || !m_infer_request)
5763
return;
5864

5965
m_infer_request.wait();
@@ -62,7 +68,7 @@ struct BaseDetection {
6268
mutable bool m_enablingChecked = false;
6369
mutable bool m_enabled = false;
6470

65-
bool enabled() const {
71+
bool enabled() const {
6672
if (!m_enablingChecked) {
6773
m_enabled = !m_commandLineFlag.empty();
6874
if (!m_enabled) {
@@ -81,7 +87,10 @@ struct Load {
8187
void into(ov::Core& core, const std::string& deviceName) const {
8288
if (m_detector.enabled()) {
8389
m_detector.m_compiled_model = core.compile_model(m_detector.read(core), deviceName);
84-
logCompiledModelInfo(m_detector.m_compiled_model, m_detector.m_commandLineFlag, deviceName, m_detector.m_detectorName);
90+
logCompiledModelInfo(m_detector.m_compiled_model,
91+
m_detector.m_commandLineFlag,
92+
deviceName,
93+
m_detector.m_detectorName);
8594
}
8695
}
8796
};

demos/crossroad_camera_demo/cpp/detection_person.hpp

+24-22
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//
44

5+
#include <memory>
56
#include <string>
7+
#include <vector>
68

7-
#include "openvino/openvino.hpp"
9+
#include <gflags/gflags.h>
10+
#include <openvino/openvino.hpp>
11+
12+
#include <utils/slog.hpp>
813

9-
#include "gflags/gflags.h"
10-
#include "utils/slog.hpp"
11-
#include "detection_base.hpp"
1214
#include "crossroad_camera_demo.hpp"
15+
#include "detection_base.hpp"
1316

1417
struct PersonDetection : BaseDetection {
1518
size_t maxProposalCount;
@@ -86,25 +89,25 @@ struct PersonDetection : BaseDetection {
8689
throw std::logic_error("Incorrect output dimensions for SSD");
8790
}
8891

89-
const ov::Layout tensor_layout{ "NHWC" };
92+
const ov::Layout tensor_layout{"NHWC"};
9093

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

9396
if (FLAGS_auto_resize) {
94-
ppp.input().tensor().
95-
set_element_type(ov::element::u8).
96-
set_spatial_dynamic_shape().
97-
set_layout(tensor_layout);
98-
ppp.input().preprocess().
99-
convert_element_type(ov::element::f32).
100-
convert_layout("NCHW").
101-
resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
97+
ppp.input()
98+
.tensor()
99+
.set_element_type(ov::element::u8)
100+
.set_spatial_dynamic_shape()
101+
.set_layout(tensor_layout);
102+
ppp.input()
103+
.preprocess()
104+
.convert_element_type(ov::element::f32)
105+
.convert_layout("NCHW")
106+
.resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
102107
ppp.input().model().set_layout("NCHW");
103108
ppp.output().tensor().set_element_type(ov::element::f32);
104109
} else {
105-
ppp.input().tensor().
106-
set_element_type(ov::element::u8).
107-
set_layout({ "NCHW" });
110+
ppp.input().tensor().set_element_type(ov::element::u8).set_layout({"NCHW"});
108111
}
109112

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

147150
if (FLAGS_r) {
148-
slog::debug <<
149-
"[" << i << "," << r.label << "] element, prob = " << r.confidence <<
150-
" (" << r.location.x << "," << r.location.y <<
151-
")-(" << r.location.width << "," << r.location.height << ")" <<
152-
((r.confidence > FLAGS_t) ? " WILL BE RENDERED!" : "") << slog::endl;
151+
slog::debug << "[" << i << "," << r.label << "] element, prob = " << r.confidence << " ("
152+
<< r.location.x << "," << r.location.y << ")-(" << r.location.width << ","
153+
<< r.location.height << ")" << ((r.confidence > FLAGS_t) ? " WILL BE RENDERED!" : "")
154+
<< slog::endl;
153155
}
154156
results.push_back(r);
155157
}

demos/crossroad_camera_demo/cpp/detection_person_attr.hpp

+46-34
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//
44

5+
#include <algorithm>
6+
#include <memory>
57
#include <string>
8+
#include <vector>
69

7-
#include "openvino/openvino.hpp"
10+
#include <gflags/gflags.h>
11+
#include <openvino/openvino.hpp>
12+
13+
#include <utils/slog.hpp>
814

9-
#include "gflags/gflags.h"
10-
#include "utils/slog.hpp"
1115
#include "detection_base.hpp"
1216

1317
struct PersonAttribsDetection : BaseDetection {
@@ -16,7 +20,6 @@ struct PersonAttribsDetection : BaseDetection {
1620
std::string outputNameForBottomColorPoint;
1721
bool hasTopBottomColor;
1822

19-
2023
PersonAttribsDetection() : BaseDetection(FLAGS_m_pa, "Person Attributes Recognition"), hasTopBottomColor(false) {}
2124

2225
struct AttributesAndColorPoints {
@@ -37,8 +40,13 @@ struct PersonAttribsDetection : BaseDetection {
3740
image.convertTo(image32f, CV_32F);
3841
image32f = image32f.reshape(1, image32f.rows * image32f.cols);
3942
clusterCount = std::min(clusterCount, image32f.rows);
40-
cv::kmeans(image32f, clusterCount, labels, cv::TermCriteria(cv::TermCriteria::EPS+cv::TermCriteria::MAX_ITER, 10, 1.0),
41-
10, cv::KMEANS_RANDOM_CENTERS, centers);
43+
cv::kmeans(image32f,
44+
clusterCount,
45+
labels,
46+
cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 10, 1.0),
47+
10,
48+
cv::KMEANS_RANDOM_CENTERS,
49+
centers);
4250
centers.convertTo(centers, CV_8U);
4351
centers = centers.reshape(3, clusterCount);
4452
std::vector<int> freq(clusterCount);
@@ -53,12 +61,16 @@ struct PersonAttribsDetection : BaseDetection {
5361
}
5462

5563
AttributesAndColorPoints GetPersonAttributes() {
56-
static const char* const attributeStringsFor7Attributes[] = {
57-
"is male", "has_bag", "has hat", "has longsleeves", "has longpants", "has longhair", "has coat_jacket"
58-
};
59-
static const char* const attributeStringsFor8Attributes[] = {
60-
"is male", "has_bag", "has_backpack" , "has hat", "has longsleeves", "has longpants", "has longhair", "has coat_jacket"
61-
};
64+
static const char* const attributeStringsFor7Attributes[] =
65+
{"is male", "has_bag", "has hat", "has longsleeves", "has longpants", "has longhair", "has coat_jacket"};
66+
static const char* const attributeStringsFor8Attributes[] = {"is male",
67+
"has_bag",
68+
"has_backpack",
69+
"has hat",
70+
"has longsleeves",
71+
"has longpants",
72+
"has longhair",
73+
"has coat_jacket"};
6274

6375
ov::Tensor attribsTensor = m_infer_request.get_tensor(outputNameForAttributes);
6476
size_t numOfAttrChannels = attribsTensor.get_shape()[1];
@@ -69,12 +81,12 @@ struct PersonAttribsDetection : BaseDetection {
6981
} else if (numOfAttrChannels == arraySize(attributeStringsFor8Attributes)) {
7082
attributeStrings = attributeStringsFor8Attributes;
7183
} else {
72-
throw std::logic_error("Output size (" + std::to_string(numOfAttrChannels) + ") of the "
84+
throw std::logic_error("Output size (" + std::to_string(numOfAttrChannels) +
85+
") of the "
7386
"Person Attributes Recognition network is not equal to expected "
74-
"number of attributes ("
75-
+ std::to_string(arraySize(attributeStringsFor7Attributes))
76-
+ " or "
77-
+ std::to_string(arraySize(attributeStringsFor7Attributes)) + ")");
87+
"number of attributes (" +
88+
std::to_string(arraySize(attributeStringsFor7Attributes)) + " or " +
89+
std::to_string(arraySize(attributeStringsFor7Attributes)) + ")");
7890
}
7991

8092
AttributesAndColorPoints returnValue;
@@ -92,11 +104,13 @@ struct PersonAttribsDetection : BaseDetection {
92104
size_t numOfTCPointChannels = topColorPointTensor.get_shape()[1];
93105
size_t numOfBCPointChannels = bottomColorPointTensor.get_shape()[1];
94106
if (numOfTCPointChannels != 2) {
95-
throw std::logic_error("Output size (" + std::to_string(numOfTCPointChannels) + ") of the "
107+
throw std::logic_error("Output size (" + std::to_string(numOfTCPointChannels) +
108+
") of the "
96109
"Person Attributes Recognition network is not equal to point coordinates(2)");
97110
}
98111
if (numOfBCPointChannels != 2) {
99-
throw std::logic_error("Output size (" + std::to_string(numOfBCPointChannels) + ") of the "
112+
throw std::logic_error("Output size (" + std::to_string(numOfBCPointChannels) +
113+
") of the "
100114
"Person Attributes Recognition network is not equal to point coordinates (2)");
101115
}
102116

@@ -118,8 +132,9 @@ struct PersonAttribsDetection : BaseDetection {
118132
}
119133

120134
bool CheckOutputNameExist(const ov::OutputVector& outputs, const std::string name) {
121-
if (std::find_if(outputs.begin(), outputs.end(),
122-
[&](const ov::Output<ov::Node>& output) {return output.get_any_name() == name; }) == outputs.end()) {
135+
if (std::find_if(outputs.begin(), outputs.end(), [&](const ov::Output<ov::Node>& output) {
136+
return output.get_any_name() == name;
137+
}) == outputs.end()) {
123138
return false;
124139
}
125140
return true;
@@ -144,19 +159,15 @@ struct PersonAttribsDetection : BaseDetection {
144159
ov::preprocess::PrePostProcessor ppp = ov::preprocess::PrePostProcessor(model);
145160

146161
if (FLAGS_auto_resize) {
147-
ppp.input().tensor().
148-
set_element_type(ov::element::u8).
149-
set_spatial_dynamic_shape().
150-
set_layout({ "NHWC" });
151-
ppp.input().preprocess().
152-
convert_element_type(ov::element::f32).
153-
convert_layout("NCHW").
154-
resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
162+
ppp.input().tensor().set_element_type(ov::element::u8).set_spatial_dynamic_shape().set_layout({"NHWC"});
163+
ppp.input()
164+
.preprocess()
165+
.convert_element_type(ov::element::f32)
166+
.convert_layout("NCHW")
167+
.resize(ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
155168
ppp.input().model().set_layout("NCHW");
156169
} else {
157-
ppp.input().tensor().
158-
set_element_type(ov::element::u8).
159-
set_layout({ "NCHW" });
170+
ppp.input().tensor().set_element_type(ov::element::u8).set_layout({"NCHW"});
160171
}
161172

162173
model = ppp.build();
@@ -189,8 +200,9 @@ struct PersonAttribsDetection : BaseDetection {
189200
}
190201
hasTopBottomColor = true;
191202
} else {
192-
throw std::logic_error("Person Attribs Network expects either a network having one output (person attributes), "
193-
"or a network having three outputs (person attributes, top color point, bottom color point)");
203+
throw std::logic_error(
204+
"Person Attribs Network expects either a network having one output (person attributes), "
205+
"or a network having three outputs (person attributes, top color point, bottom color point)");
194206
}
195207

196208
m_enabled = true;

0 commit comments

Comments
 (0)