9 #ifndef CscDetectorEnginePersonPose_h
10 #define CscDetectorEnginePersonPose_h
15 #include <opencv2/opencv.hpp>
24 ENUM(CscDetectedPersonPose,
41 optional<cv::Size> minSize = {},
42 optional<cv::Size> maxSize = {}): drawPredictionOnImage(drawPredictionOnImage), minSize(minSize), maxSize(maxSize) {}
45 CscDetectorEnginePersonPose(
ptr<CscDNNPool> dnnPool,
const Configuration &configuration = Configuration());
51 virtual bool equals(CscDetectorEngine *)
const override;
55 bool drawPredictionOnImage;
57 optional<cv::Size> minSize;
58 optional<cv::Size> maxSize;
62 static constexpr
float standingPersonMaxWidth = 200;
63 static constexpr
float standingPersonMinHeight = 360;
64 static constexpr
float standingPersonMaxVerticalAngleRadians = .3;
66 static constexpr
float maxBoundingBoxArea = 600 * 500;
68 static constexpr
float maxDistanceBetweenDots = 320;
75 const int NET_INPUT_SIZE = 368;
77 std::unique_ptr<CscLogger>
logger;
80 KeyPoint(cv::Point point,
float probability){
83 this->probability = probability;
93 ValidPair(
int aId,
int bId,
float score){
106 const KeyPoint *pointA;
107 const KeyPoint *pointB;
113 Person(
int id,
const vector<PersonPair *> &pairs);
117 bool hasInvalidPair()
const;
119 optional<cv::Point> getLegsBottomPoint()
const {
return legsBottomPoint; }
120 optional<CscPoint2d> getTopAverage()
const {
return topAverage; }
121 optional<CscPoint2d> getMiddleAverage()
const {
return middleAverage; }
122 optional<CscPoint2d> getBottomAverage()
const {
return bottomAverage; }
123 optional<cv::Rect> getBoundingBox()
const {
return boundingBox; }
124 optional<cv::Rect> getBodyBoundingBox()
const {
return bodyBoundingBox; }
125 bool isBottomToMiddleLinkFound()
const {
return bottomToMiddleLinkFound; }
126 bool isTopToMiddleLinkFound()
const {
return topToMiddleLinkFound; }
127 bool getTopPointsCount()
const {
return topCount; }
128 bool getMiddlePointsCount()
const {
return middleCount; }
129 bool getBottomPointsCount()
const {
return bottomCount; }
131 void drawPoints(Mat &imageMatrix,
const cv::Scalar &color)
const;
132 void registerPublicAIData(map<string, CscPublicAIData*> &skeletonPublicAIData,
double imageHeight)
const;
134 bool areLegsParallelAndStraight()
const;
137 optional<double> getRightAnkleKneeAngle()
const {
return rightKneeFootAngle; }
138 optional<double> getLeftAnkleKneeAngle()
const {
return leftKneeFootAngle; }
147 optional<cv::Point> getMiddleHipPoint()
const;
148 optional<cv::Point> getLeftHipPoint()
const;
149 optional<cv::Point> getRightHipPoint()
const;
151 optional<cv::Point> getTorsoTopPoint()
const;
153 optional<cv::Point> getLeftFootPoint()
const;
154 optional<cv::Point> getRightFootPoint()
const;
156 optional<cv::Point> getLeftKneePoint()
const;
157 optional<cv::Point> getRightKneePoint()
const;
158 optional<cv::Point> getLeftWristPoint()
const;
159 optional<cv::Point> getRightWristPoint()
const;
162 map<string, const KeyPoint *> points;
163 const KeyPoint *getPointOrNull(
const string &name)
const;
165 template <
class ... FallbackNames>
166 const KeyPoint *getPointOrOtherOrNull(
const char *name, FallbackNames ... otherNames)
const {
167 const auto list = {name, otherNames...};
169 for (
const char *requestedName : list) {
170 const KeyPoint *result = getPointOrNull(
string(requestedName));
171 if (result !=
nullptr) {
179 const vector<PersonPair *> pairs;
180 bool topToMiddleLinkFound =
false;
181 bool bottomToMiddleLinkFound =
false;
182 bool hasInvalidPairValue =
false;
183 optional<CscPoint2d> topAverage = {};
184 optional<CscPoint2d> middleAverage = {};
185 optional<CscPoint2d> bottomAverage = {};
186 optional<cv::Point> legsBottomPoint = {};
187 optional<cv::Rect> boundingBox = {};
188 optional<cv::Rect> bodyBoundingBox = {};
210 vector<cv::Mat> splitNetOutputBlobToParts(cv::Mat& netOutputBlob,
const cv::Size& targetSize)
const;
211 vector<vector<int>> getPersonwiseKeypoints(
const std::vector<std::vector<ValidPair>>& validPairs,
const std::set<int>& invalidPairs)
const;
212 vector<KeyPoint *> getKeyPoints(cv::Mat& probMap,
double threshold)
const;
213 void getValidPairs(
const vector<cv::Mat>& netOutputParts,
214 const vector<vector<KeyPoint *>>& detectedKeypoints,
215 vector<vector<ValidPair>>& validPairs,
216 std::set<int>& invalidPairs)
const;
218 CscDetectedPersonPose isPersonLyingOrStandingUp(
const Mat &originalImage, Mat &resultingImage,
Person *person,
const map<
string, vector<cv::Point2f>> &ignoredZones);