Skip to content

Commit 1e28cb9

Browse files
committed
upd pedestrian trakcer demo
1 parent 1355b8e commit 1e28cb9

File tree

13 files changed

+577
-539
lines changed

13 files changed

+577
-539
lines changed

demos/pedestrian_tracker_demo/cpp/include/cnn.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44

55
#pragma once
66

7-
#include <map>
8-
#include <memory>
7+
#include <stddef.h>
8+
9+
#include <functional>
910
#include <string>
1011
#include <vector>
11-
#include <functional>
12-
#include <opencv2/opencv.hpp>
12+
13+
#include <opencv2/core.hpp>
1314
#include <openvino/openvino.hpp>
14-
#include <utils/ocv_common.hpp>
1515

1616
/**
1717
* @brief Base class of config for model
1818
*/
1919
struct ModelConfigTracker {
20-
explicit ModelConfigTracker(const std::string& path_to_model)
21-
: path_to_model(path_to_model) {}
20+
explicit ModelConfigTracker(const std::string& path_to_model) : path_to_model(path_to_model) {}
2221

2322
/** @brief Path to model description */
2423
std::string path_to_model;
@@ -36,9 +35,7 @@ class BaseModel {
3635
/**
3736
* @brief Constructor
3837
*/
39-
BaseModel(const Config& config,
40-
const ov::Core& core,
41-
const std::string & deviceName);
38+
BaseModel(const Config& config, const ov::Core& core, const std::string& deviceName);
4239

4340
/**
4441
* @brief Descructor
@@ -68,7 +65,7 @@ class BaseModel {
6865
ov::Core core;
6966
/** @brief device */
7067
std::string device_name;
71-
/** @brief Model input layout */
68+
/** @brief Model input layout */
7269
ov::Layout input_layout;
7370
/** @brief Compiled model */
7471
ov::CompiledModel compiled_model;
@@ -86,16 +83,16 @@ class BaseModel {
8683

8784
class VectorCNN : public BaseModel {
8885
public:
89-
VectorCNN(const ModelConfigTracker& config,
90-
const ov::Core & core,
91-
const std::string & deviceName);
86+
VectorCNN(const ModelConfigTracker& config, const ov::Core& core, const std::string& deviceName);
9287

93-
void Compute(const cv::Mat& image,
94-
cv::Mat* vector, cv::Size outp_shape = cv::Size()) const;
88+
void Compute(const cv::Mat& image, cv::Mat* vector, cv::Size outp_shape = cv::Size()) const;
9589
void Compute(const std::vector<cv::Mat>& images,
96-
std::vector<cv::Mat>* vectors, cv::Size outp_shape = cv::Size()) const;
90+
std::vector<cv::Mat>* vectors,
91+
cv::Size outp_shape = cv::Size()) const;
9792

98-
int size() const { return result_size; }
93+
int size() const {
94+
return result_size;
95+
}
9996

10097
private:
10198
int result_size; // Length of result

demos/pedestrian_tracker_demo/cpp/include/core.hpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44

55
#pragma once
66

7-
#include <opencv2/core.hpp>
8-
97
#include <deque>
108
#include <iostream>
119
#include <string>
1210
#include <unordered_map>
1311

12+
#include <opencv2/core.hpp>
13+
1414
///
1515
/// \brief The TrackedObject struct defines properties of detected object.
1616
///
1717
struct TrackedObject {
18-
cv::Rect rect; ///< Detected object ROI (zero area if N/A).
19-
double confidence; ///< Detection confidence level (-1 if N/A).
20-
int64_t frame_idx; ///< Frame index where object was detected (-1 if N/A).
21-
int object_id; ///< Unique object identifier (-1 if N/A).
18+
cv::Rect rect; ///< Detected object ROI (zero area if N/A).
19+
double confidence; ///< Detection confidence level (-1 if N/A).
20+
int64_t frame_idx; ///< Frame index where object was detected (-1 if N/A).
21+
int object_id; ///< Unique object identifier (-1 if N/A).
2222
uint64_t timestamp; ///< Timestamp in milliseconds.
2323

2424
///
2525
/// \brief Default constructor.
2626
///
27-
TrackedObject()
28-
: confidence(-1),
29-
frame_idx(-1),
30-
object_id(-1),
31-
timestamp(0) {}
27+
TrackedObject() : confidence(-1), frame_idx(-1), object_id(-1), timestamp(0) {}
3228

3329
///
3430
/// \brief Constructor with parameters.
@@ -37,13 +33,12 @@ struct TrackedObject {
3733
/// \param frame_idx Index of frame.
3834
/// \param object_id Object ID.
3935
///
40-
TrackedObject(const cv::Rect &rect, float confidence, int64_t frame_idx,
41-
int object_id)
36+
TrackedObject(const cv::Rect& rect, float confidence, int64_t frame_idx, int object_id)
4237
: rect(rect),
43-
confidence(confidence),
44-
frame_idx(frame_idx),
45-
object_id(object_id),
46-
timestamp(0) {}
38+
confidence(confidence),
39+
frame_idx(frame_idx),
40+
object_id(object_id),
41+
timestamp(0) {}
4742
};
4843

4944
using TrackedObjects = std::deque<TrackedObject>;

demos/pedestrian_tracker_demo/cpp/include/descriptor.hpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include <memory>
77
#include <string>
88
#include <vector>
9+
910
#include <opencv2/opencv.hpp>
1011
#include <openvino/openvino.hpp>
12+
1113
#include "cnn.hpp"
1214
#include "core.hpp"
1315
#include "logging.hpp"
@@ -29,20 +31,18 @@ class IImageDescriptor {
2931
/// \param[in] mat Color image.
3032
/// \param[out] descr Computed descriptor.
3133
///
32-
virtual void Compute(const cv::Mat &mat, cv::Mat *descr) = 0;
34+
virtual void Compute(const cv::Mat& mat, cv::Mat* descr) = 0;
3335

3436
///
3537
/// \brief Computes image descriptors in batches.
3638
/// \param[in] mats Images of interest.
3739
/// \param[out] descrs Matrices to store the computed descriptors.
3840
///
39-
virtual void Compute(const std::vector<cv::Mat> &mats,
40-
std::vector<cv::Mat> *descrs) = 0;
41+
virtual void Compute(const std::vector<cv::Mat>& mats, std::vector<cv::Mat>* descrs) = 0;
4142

4243
virtual ~IImageDescriptor() {}
4344
};
4445

45-
4646
///
4747
/// \brief Uses resized image as descriptor.
4848
///
@@ -53,25 +53,27 @@ class ResizedImageDescriptor : public IImageDescriptor {
5353
/// \param[in] descr_size Size of the descriptor (resized image).
5454
/// \param[in] interpolation Interpolation algorithm.
5555
///
56-
explicit ResizedImageDescriptor(const cv::Size &descr_size,
57-
const cv::InterpolationFlags interpolation)
58-
: descr_size_(descr_size), interpolation_(interpolation) {
59-
PT_CHECK_GT(descr_size.width, 0);
60-
PT_CHECK_GT(descr_size.height, 0);
61-
}
56+
explicit ResizedImageDescriptor(const cv::Size& descr_size, const cv::InterpolationFlags interpolation)
57+
: descr_size_(descr_size),
58+
interpolation_(interpolation) {
59+
PT_CHECK_GT(descr_size.width, 0);
60+
PT_CHECK_GT(descr_size.height, 0);
61+
}
6262

6363
///
6464
/// \brief Returns descriptor size.
6565
/// \return Number of elements in the descriptor.
6666
///
67-
cv::Size size() const override { return descr_size_; }
67+
cv::Size size() const override {
68+
return descr_size_;
69+
}
6870

6971
///
7072
/// \brief Computes image descriptor.
7173
/// \param[in] mat Frame containing the image of interest.
7274
/// \param[out] descr Matrix to store the computed descriptor.
7375
///
74-
void Compute(const cv::Mat &mat, cv::Mat *descr) override {
76+
void Compute(const cv::Mat& mat, cv::Mat* descr) override {
7577
PT_CHECK(descr != nullptr);
7678
PT_CHECK(!mat.empty());
7779
cv::resize(mat, *descr, descr_size_, 0, 0, interpolation_);
@@ -82,11 +84,10 @@ class ResizedImageDescriptor : public IImageDescriptor {
8284
/// \param[in] mats Frames containing images of interest.
8385
/// \param[out] descrs Matrices to store the computed descriptors.
8486
//
85-
void Compute(const std::vector<cv::Mat> &mats,
86-
std::vector<cv::Mat> *descrs) override {
87+
void Compute(const std::vector<cv::Mat>& mats, std::vector<cv::Mat>* descrs) override {
8788
PT_CHECK(descrs != nullptr);
8889
descrs->resize(mats.size());
89-
for (size_t i = 0; i < mats.size(); i++) {
90+
for (size_t i = 0; i < mats.size(); i++) {
9091
Compute(mats[i], &(descrs[i]));
9192
}
9293
}
@@ -97,16 +98,13 @@ class ResizedImageDescriptor : public IImageDescriptor {
9798
cv::InterpolationFlags interpolation_;
9899
};
99100

100-
101101
class Descriptor : public IImageDescriptor {
102102
private:
103103
VectorCNN handler;
104104

105105
public:
106-
Descriptor(const ModelConfigTracker& config,
107-
const ov::Core& core,
108-
const std::string& deviceName):
109-
handler(config, core, deviceName) {}
106+
Descriptor(const ModelConfigTracker& config, const ov::Core& core, const std::string& deviceName)
107+
: handler(config, core, deviceName) {}
110108

111109
///
112110
/// \brief Descriptor size getter.
@@ -121,7 +119,7 @@ class Descriptor : public IImageDescriptor {
121119
/// \param[in] mat Color image.
122120
/// \param[out] descr Computed descriptor.
123121
///
124-
void Compute(const cv::Mat &mat, cv::Mat *descr) override {
122+
void Compute(const cv::Mat& mat, cv::Mat* descr) override {
125123
handler.Compute(mat, descr);
126124
}
127125

@@ -130,8 +128,7 @@ class Descriptor : public IImageDescriptor {
130128
/// \param[in] mats Images of interest.
131129
/// \param[out] descrs Matrices to store the computed descriptors.
132130
///
133-
void Compute(const std::vector<cv::Mat> &mats,
134-
std::vector<cv::Mat> *descrs) override {
131+
void Compute(const std::vector<cv::Mat>& mats, std::vector<cv::Mat>* descrs) override {
135132
handler.Compute(mats, descrs);
136133
}
137134
};

demos/pedestrian_tracker_demo/cpp/include/distance.hpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#pragma once
66

7-
#include <memory>
87
#include <vector>
9-
#include <opencv2/core/core.hpp>
8+
9+
#include <opencv2/core.hpp>
1010
#include <opencv2/imgproc.hpp>
1111

1212
///
@@ -21,16 +21,15 @@ class IDescriptorDistance {
2121
/// \param[in] descr2 Second descriptor.
2222
/// \return Distance between two descriptors.
2323
///
24-
virtual float Compute(const cv::Mat &descr1, const cv::Mat &descr2) = 0;
24+
virtual float Compute(const cv::Mat& descr1, const cv::Mat& descr2) = 0;
2525

2626
///
2727
/// \brief Computes distances between two descriptors in batches.
2828
/// \param[in] descrs1 Batch of first descriptors.
2929
/// \param[in] descrs2 Batch of second descriptors.
3030
/// \return Distances between descriptors.
3131
///
32-
virtual std::vector<float> Compute(const std::vector<cv::Mat> &descrs1,
33-
const std::vector<cv::Mat> &descrs2) = 0;
32+
virtual std::vector<float> Compute(const std::vector<cv::Mat>& descrs1, const std::vector<cv::Mat>& descrs2) = 0;
3433

3534
virtual ~IDescriptorDistance() {}
3635
};
@@ -45,31 +44,28 @@ class CosDistance : public IDescriptorDistance {
4544
/// \brief CosDistance constructor.
4645
/// \param[in] descriptor_size Descriptor size.
4746
///
48-
explicit CosDistance(const cv::Size &descriptor_size);
47+
explicit CosDistance(const cv::Size& descriptor_size);
4948

5049
///
5150
/// \brief Computes distance between two descriptors.
5251
/// \param descr1 First descriptor.
5352
/// \param descr2 Second descriptor.
5453
/// \return Distance between two descriptors.
5554
///
56-
float Compute(const cv::Mat &descr1, const cv::Mat &descr2) override;
55+
float Compute(const cv::Mat& descr1, const cv::Mat& descr2) override;
5756

5857
///
5958
/// \brief Computes distances between two descriptors in batches.
6059
/// \param[in] descrs1 Batch of first descriptors.
6160
/// \param[in] descrs2 Batch of second descriptors.
6261
/// \return Distances between descriptors.
6362
///
64-
std::vector<float> Compute(
65-
const std::vector<cv::Mat> &descrs1,
66-
const std::vector<cv::Mat> &descrs2) override;
63+
std::vector<float> Compute(const std::vector<cv::Mat>& descrs1, const std::vector<cv::Mat>& descrs2) override;
6764

6865
private:
6966
cv::Size descriptor_size_;
7067
};
7168

72-
7369
///
7470
/// \brief Computes distance between images
7571
/// using MatchTemplate function from OpenCV library
@@ -88,30 +84,30 @@ class MatchTemplateDistance : public IDescriptorDistance {
8884
/// Final distance is computed as:
8985
/// scale * distance + offset.
9086
///
91-
MatchTemplateDistance(int type = cv::TemplateMatchModes::TM_CCORR_NORMED,
92-
float scale = -1, float offset = 1)
93-
: type_(type), scale_(scale), offset_(offset) {}
87+
MatchTemplateDistance(int type = cv::TemplateMatchModes::TM_CCORR_NORMED, float scale = -1, float offset = 1)
88+
: type_(type),
89+
scale_(scale),
90+
offset_(offset) {}
9491
///
9592
/// \brief Computes distance between image descriptors.
9693
/// \param[in] descr1 First image descriptor.
9794
/// \param[in] descr2 Second image descriptor.
9895
/// \return Distance between image descriptors.
9996
///
100-
float Compute(const cv::Mat &descr1, const cv::Mat &descr2) override;
97+
float Compute(const cv::Mat& descr1, const cv::Mat& descr2) override;
10198
///
10299
/// \brief Computes distances between two descriptors in batches.
103100
/// \param[in] descrs1 Batch of first descriptors.
104101
/// \param[in] descrs2 Batch of second descriptors.
105102
/// \return Distances between descriptors.
106103
///
107-
std::vector<float> Compute(const std::vector<cv::Mat> &descrs1,
108-
const std::vector<cv::Mat> &descrs2) override;
104+
std::vector<float> Compute(const std::vector<cv::Mat>& descrs1, const std::vector<cv::Mat>& descrs2) override;
109105
virtual ~MatchTemplateDistance() {}
110106

111107
private:
112-
int type_; ///< Method of MatchTemplate function computation.
113-
float scale_; ///< Scale parameter for the distance. Final distance is
114-
/// computed as: scale * distance + offset.
108+
int type_; ///< Method of MatchTemplate function computation.
109+
float scale_; ///< Scale parameter for the distance. Final distance is
110+
/// computed as: scale * distance + offset.
115111
float offset_; ///< Offset parameter for the distance. Final distance is
116112
/// computed as: scale * distance + offset.
117113
};

demos/pedestrian_tracker_demo/cpp/include/logging.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#define PT_CHECK(cond) IE_ASSERT(cond) << " "
1010

1111
#define PT_CHECK_BINARY(actual, expected, op) \
12-
IE_ASSERT(actual op expected) << ". " \
13-
<< actual << " vs " << expected << ". "
12+
IE_ASSERT(actual op expected) << ". " << actual << " vs " << expected << ". "
1413

1514
#define PT_CHECK_EQ(actual, expected) PT_CHECK_BINARY(actual, expected, ==)
1615
#define PT_CHECK_NE(actual, expected) PT_CHECK_BINARY(actual, expected, !=)

0 commit comments

Comments
 (0)