//
|
// Created by basic on 18-8-24.
|
//
|
|
#include "JudgmentRetrogradeTool.h"
|
#include <basic/util/opencv/CvMath.hpp>
|
#include <QtCore/QDebug>
|
|
JudgmentRetrogradeTool::JudgmentRetrogradeTool():
|
TimerElement(1000),
|
m_triggerElement(0,50)
|
{
|
|
}
|
|
JudgmentRetrogradeTool::~JudgmentRetrogradeTool() {
|
|
}
|
|
bool JudgmentRetrogradeTool::init(QString area,QString line) {
|
//#todo string ->json
|
QJsonArray arrayAreas = getJsonArrayFromQString(area);
|
if(arrayAreas.isEmpty())
|
{
|
return false;//do not detect
|
}
|
QVector<QPoint> vec;
|
for(int i = 0;i < arrayAreas.size();++i){
|
QJsonValue jsonValue = arrayAreas[i];
|
QJsonObject obj = jsonValue.toObject();
|
int x = obj.value("x").toInt()*2 ;
|
int y = obj.value("y").toInt()*2 ;
|
vec.push_back(QPoint(x,y));
|
}
|
|
|
m_polygon = std::move(QPolygon(vec));
|
// QPoint left[]={QPoint(100,6),QPoint(100,1200),QPoint(850,1200),QPoint(850,6)} ;
|
// QPoint right[]={QPoint(850,6),QPoint(1800,6),QPoint(1800,1200),QPoint(850,1200)} ;
|
// for(auto &item:left)
|
// {
|
// m_UpPolygon<<(item);
|
// }
|
// for(auto &item:right)
|
// {
|
// m_DownPolygon<<(item);
|
// }
|
|
cv::Point start, end;
|
QJsonArray arrayLine = getJsonArrayFromQString(line);
|
if(arrayLine.size() == 2){
|
QJsonValue jsonValue = arrayLine[0];
|
QJsonObject obj = jsonValue.toObject();
|
start.x = obj.value("x").toInt() ;
|
start.y = obj.value("y").toInt() ;
|
|
|
QJsonValue jsonValue2 = arrayLine[1];
|
QJsonObject obj2 = jsonValue2.toObject();
|
end.x = obj2.value("x").toInt() ;
|
end.y = obj2.value("y").toInt() ;
|
|
}else{
|
return false;
|
}
|
setUpBaseline(start,end);
|
|
//setDownBaseline(start,end);
|
// setUpBaseline();
|
// setUpDetectionArea();
|
return true;
|
}
|
|
void JudgmentRetrogradeTool::setYoloObjects(std::vector<ScoredRect> value)
|
{
|
mObjs=value;
|
for(auto & item :value){
|
setPerRect(item.id,item.rect);
|
}
|
}
|
|
|
void JudgmentRetrogradeTool::setPerRect(const long& id,cv::Rect rect){
|
setPerPoint(id,getCenterPoint(rect));
|
}
|
|
void JudgmentRetrogradeTool::setPerPoint(const long &id, cv::Point2f result) {
|
auto &listCache = m_mapPerPoint[id];
|
cv::Point2f vp;
|
vp.x = result.x;
|
vp.y = result.y;
|
listCache.push_back(vp);
|
if (listCache.size() >= 2) {
|
VectorPoint tt;
|
tt.start_Point = listCache.front();
|
tt.end_Point = listCache.back();
|
auto &temp = m_mapPerDirection[id];
|
//#TODO tt.end_Point in UP Area
|
QPoint center(tt.end_Point.x,tt.end_Point.y);
|
if(m_polygon.containsPoint(center,Qt::OddEvenFill)){
|
temp.push_back(JRTOOL::low_filter(temp.back(), getTheta(m_UpBaseLine, tt)));
|
//DBG("ID="<<id<<" left getTheta="<<getTheta(m_DownBaseLine, tt));
|
}
|
else
|
{
|
temp.clear();
|
}
|
listCache.clear();
|
}
|
}
|
|
bool JudgmentRetrogradeTool::getPerRet(const long &id) {
|
bool ret = (m_mapPerRet.find(id) == m_mapPerRet.end()) ? true : m_mapPerRet[id];
|
return ret;
|
}
|
|
void JudgmentRetrogradeTool::setUpBaseline(cv::Point start, cv::Point end) {
|
m_UpBaseLine.start_Point = start;
|
m_UpBaseLine.end_Point = end;
|
}
|
|
|
void JudgmentRetrogradeTool::setDownBaseline(cv::Point start, cv::Point end) {
|
m_DownBaseLine.start_Point = start;
|
m_DownBaseLine.end_Point = end;
|
}
|
|
float JudgmentRetrogradeTool::getTheta(BaseLine &directionVectorPoint, VectorPoint &point) {
|
return JRTOOL::getAngelOfTwoVector(directionVectorPoint, point);
|
}
|
|
void JudgmentRetrogradeTool::timerFunc()
|
{
|
func();
|
fireConnectors();
|
}
|
|
void JudgmentRetrogradeTool::func() {
|
for (auto &item : m_mapPerDirection) {
|
int a = 0;
|
int b = 0;
|
auto &temp = item.second;
|
for (auto &item2 : temp) {
|
if (item2 > 100) {
|
b++;
|
} else if (item2 < 80) {
|
a++;
|
}
|
}
|
// DBG("id="<<item.first<<" a="<<a<<" b="<<b);
|
bool ret = a >= b ? true : false;
|
m_mapPerRet[item.first] = ret;
|
if (temp.size() > 9) {
|
temp.pop_front();
|
}
|
}
|
|
for (auto scoredRect:mObjs) {
|
if (!getPerRet(scoredRect.id))//judgment.bool
|
{
|
m_triggerElement.setState(true);
|
break;
|
}
|
else
|
{
|
m_triggerElement.setState(false);
|
|
}
|
}
|
m_triggerElement.triggerOnce();
|
}
|
|
QJsonArray JudgmentRetrogradeTool::getJsonArrayFromQString(const QString strJson)
|
{
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(strJson.toLocal8Bit());
|
if( jsonDocument.isNull() ){
|
qDebug()<< "please check the string"<< strJson.toLocal8Bit();
|
return QJsonArray();
|
}
|
QJsonArray jsonArray = jsonDocument.array();
|
return jsonArray;
|
}
|
|
void JudgmentRetrogradeTool::setUpDetectionArea()
|
{
|
|
}
|
void JudgmentRetrogradeTool::setDownDetectionArea()
|
{
|
|
}
|
bool JudgmentRetrogradeTool::getTriggerState() const {
|
return m_triggerElement.getTriggerState();
|
}
|