plugin  0.1.0
associative_embedding_decoder.h
1 /*
2 // Copyright (C) 2021-2024 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include <stddef.h>
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <opencv2/core.hpp>
24 
25 struct Peak {
26  explicit Peak(const cv::Point2f& keypoint = cv::Point2f(-1, -1), const float score = 0.0f, const float tag = 0.0f)
27  : keypoint(keypoint),
28  score(score),
29  tag(tag) {}
30 
31  cv::Point2f keypoint;
32  float score;
33  float tag;
34 };
35 
36 class Pose {
37 public:
38  explicit Pose(size_t numJoints) : peaks(numJoints) {}
39 
40  void add(size_t index, Peak peak) {
41  peaks[index] = peak;
42  sum += peak.score;
43  poseTag = poseTag * static_cast<float>(validPointsNum) + peak.tag;
44  poseCenter = poseCenter * static_cast<float>(validPointsNum) + peak.keypoint;
45  validPointsNum += 1;
46  poseTag = poseTag / static_cast<float>(validPointsNum);
47  poseCenter = poseCenter / static_cast<float>(validPointsNum);
48  }
49 
50  float getPoseTag() const {
51  return poseTag;
52  }
53 
54  float getMeanScore() const {
55  return sum / static_cast<float>(size());
56  }
57 
58  Peak& getPeak(size_t index) {
59  return peaks[index];
60  }
61 
62  cv::Point2f& getPoseCenter() {
63  return poseCenter;
64  }
65 
66  size_t size() const {
67  return peaks.size();
68  }
69 
70 private:
71  std::vector<Peak> peaks;
72  cv::Point2f poseCenter = cv::Point2f(0.f, 0.f);
73  int validPointsNum = 0;
74  float poseTag = 0;
75  float sum = 0;
76 };
77 
78 void findPeaks(const std::vector<cv::Mat>& nmsHeatMaps,
79  const std::vector<cv::Mat>& aembdsMaps,
80  std::vector<std::vector<Peak>>& allPeaks,
81  size_t jointId,
82  size_t maxNumPeople,
83  float detectionThreshold);
84 
85 std::vector<Pose> matchByTag(std::vector<std::vector<Peak>>& allPeaks,
86  size_t maxNumPeople,
87  size_t numJoints,
88  float tagThreshold);
89 
90 void adjustAndRefine(std::vector<Pose>& allPoses,
91  const std::vector<cv::Mat>& heatMaps,
92  const std::vector<cv::Mat>& aembdsMaps,
93  int poseId,
94  float delta);
Definition: associative_embedding_decoder.h:36
Definition: associative_embedding_decoder.h:25