派生自 development/c++

pansen
2018-12-17 ac00f7d508e020e2e5d1a0d497f43155ed34e6a6
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
//
// Created by basic on 18-8-24.
//
 
#ifndef JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H
#define JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H
 
#include <iostream>
#include <map>
#include <list>
#include <opencv2/opencv.hpp>
#include <basic/pipe/TimerElement.h>
#include "YoloRpcElement.h"
#include <QSharedMemory>
#include <QString>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QtGui/QPolygon>
 
struct VectorPoint{
    cv::Point2f start_Point;
    cv::Point2f 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 TimerElement {
public:
    JudgmentRetrogradeTool();
 
    virtual ~JudgmentRetrogradeTool();
 
    bool init(QString area,QString line);
 
    void setYoloObjects(std::vector<ScoredRect> value);
 
    bool getPerRet(const long&);
 
     bool getTriggerState() const;
 
private:
    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);
 
 
private:
    //    virtual void threadInitial() 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;
 
    QPolygon m_polygon;
 
    TriggerElement m_triggerElement;
 
    std::vector<ScoredRect> mObjs;
};
 
 
#endif //JUDGINGRETROGRADE_JUDGMENTRETROGRADETOOL_H