//
|
// 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
|