派生自 development/c++

pansen
2019-03-07 d3b7bbe7102cd089680a828f5d8f6402c8cf6342
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Created by basic on 18-8-24.
//
 
#ifndef JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H
#define JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H
 
#include "SaveVideoRpc.h"
#include <iostream>
#include <map>
#include <list>
#include <opencv2/opencv.hpp>
#include <basic/util/app/AppPreference.hpp>
//#include <basic/pipe/TimerElement.h>
#include "YoloRpcElement.h"
#include <QSharedMemory>
#include <QString>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QtGui/QPolygon>
#include "DBStruct.h"
#include <basic/db/Elasticsearch/EsDBTool.h>
#include <jsoncpp/json/json.h>
#include <basic/pipe/PipeElement.h>
struct VectorPoint {
    cv::Point2i start_Point;
    cv::Point2i end_Point;
};
 
typedef VectorPoint BaseLine;
namespace JRTOOL {
//以pt1为基准
//计算两个向量的夹角,0~90之间为正常,90~180为逆行
    static float getAngelOfTwoVector(VectorPoint &pt1, VectorPoint &pt2) {
        float theta = atan2(pt1.end_Point.x - pt1.start_Point.x, pt1.end_Point.y - pt1.start_Point.y)
                      - atan2(pt2.end_Point.x - pt2.start_Point.x, pt2.end_Point.y - pt2.start_Point.y);
        if (theta > CV_PI)
            theta -= 2 * CV_PI;
        if (theta < -CV_PI)
            theta += 2 * CV_PI;
        theta = theta * 180.0 / CV_PI;
        return abs(theta);
    }
 
//滤波
    static float low_filter(float a, float b) {
        float sample_value;
        float X = 0.1;
        sample_value = (1 - X) * b + X * a;
        return (sample_value);
    }
}
 
 
class JudgmentRetrogradeTool  : public basic::PipeElement{
public:
    JudgmentRetrogradeTool():m_rpcClient("RtspAnalysServer", "127.0.0.1",appPref.getIntData("RpcServerPort"),"tcp") {}
 
    JudgmentRetrogradeTool(const SdkRule &rule);
    //JudgmentRetrogradeTool(const SdkRule &rule,SaveVideoRpcClient_t& rpcClient);
 
    virtual ~JudgmentRetrogradeTool();
 
    bool init(QString area, QString line);
 
    void setYoloObjects(std::vector<ScoredRect> value);
 
    bool getPerRet(const long &);
 
    bool getTriggerState() const;
 
    void setFdfs(FastFdsWithLock *p_fdfsClient) {
        fdfsClient = p_fdfsClient;
    }
 
    void setImage(const cv::Mat &value);
 
private:
 
    bool setMask(QString area, QString line);
 
    void setPerPoint(const long &, cv::Point2f);
 
    void setPerRect(const long &, cv::Rect rect);
 
    //设置上行的运动基准线
    void setUpBaseline(cv::Point start, cv::Point end);
 
    //设置上行检测区域
    void setUpDetectionArea();
 
    //设置下行的运动基准线
    void setDownBaseline(cv::Point start, cv::Point end);
 
    //设置下行检测区域
    void setDownDetectionArea();
 
 
    void func();
 
    float getTheta(BaseLine &, VectorPoint &);
 
    QJsonArray getJsonArrayFromQString(const QString strJson);
 
    std::string uploadImgToFdfs(cv::Mat &image);
 
    bool saveInfoToEs(const std::string &imgUrl, const ScoredRect &obj);
 
    bool isInWeek(const std::vector<LActRuleWeekRecord> &ruleWeek);
 
private:
    //    virtual void threadInitial() override;
       virtual void threadFunc()override;
   // virtual void timerFunc() override;
    //    virtual void threadClosing()override;
 
private:
 
    //基准线向量
    BaseLine m_UpBaseLine;
    BaseLine m_DownBaseLine;
 
    //人员运动轨迹
    //跟踪id,运动中心点
    std::map<long, std::vector<cv::Point2f>> m_mapPerPoint;
 
    //跟踪id,与基准线的夹角列表
    std::map<long, std::list<float>> m_mapPerDirection;
 
    //跟踪id,逆行状态
 //  std::map<long, bool> m_mapPerRet;
     std::map<long, int> m_mapPerRet;
 
    QPolygon m_polygon;
 
    TriggerElement m_triggerElement;
 
    std::vector<ScoredRect> mObjs;
 
    const SdkRule m_sdkRule;
 
    FastFdsWithLock *fdfsClient;
 
    cv::Mat image;
    EsDBTool *pManagerEsDB;
    cv::Point2i* pointArray;
 
    int npts;
    QString m_area;
    QString m_line;
    bool m_bSetWH;
    SaveVideoRpcClient_t m_rpcClient;
};
 
 
#endif //JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H