1、优化识别切分效果,增加报警信息
This commit is contained in:
parent
d72bd78b59
commit
f18e10f8f3
236
CMakeLists.txt
236
CMakeLists.txt
File diff suppressed because one or more lines are too long
|
|
@ -114,7 +114,7 @@ model:
|
||||||
|
|
||||||
gc_http_open: 1
|
gc_http_open: 1
|
||||||
username: "guest_01"
|
username: "guest_01"
|
||||||
password: "d55b0f642e817eea24725d2f2a31dd08" # 神东
|
password: "0a1688bce402a5f6a4279abbfc89c203" # 神东 d55b0f642e817eea24725d2f2a31dd08
|
||||||
gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
||||||
gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
||||||
gc_image_srv: "http://192.168.2.211:9010/"
|
gc_image_srv: "http://192.168.2.211:9010/"
|
||||||
|
|
@ -182,5 +182,5 @@ gc_c_space_frame_width: 500
|
||||||
# 是否识别车头
|
# 是否识别车头
|
||||||
gc_train_heard_detect: true
|
gc_train_heard_detect: true
|
||||||
|
|
||||||
#过期文件夹天数
|
# 识别结果保存天数
|
||||||
gc_days_for_result_expire_folder: 3
|
gc_days_for_result_expire_folder: 3
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -459,10 +459,10 @@ typedef struct
|
||||||
std::shared_ptr<void> pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1
|
std::shared_ptr<void> pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
Step1Location step1Location; //step2 use
|
Step1Location step1Location; //step2 use
|
||||||
int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱)
|
int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱)
|
||||||
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
||||||
int iCarXH = 0; //当前大框所属车厢
|
int iCarXH = 0; //当前大框所属车厢
|
||||||
|
|
||||||
} InferenceData;
|
} InferenceData;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -491,7 +491,7 @@ typedef struct
|
||||||
std::shared_ptr<void> pData = nullptr; // Smart pointer of data
|
std::shared_ptr<void> pData = nullptr; // Smart pointer of data
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
bool bHostMemory = false; //数据解码后内存是否在Host侧
|
bool bHostMemory = false; //数据解码后内存是否在Host侧
|
||||||
std::string strPicFilePath;
|
std::string strPicFilePath;
|
||||||
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
||||||
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
||||||
bool bIsEnd = false; //列车结束标识
|
bool bIsEnd = false; //列车结束标识
|
||||||
|
|
@ -756,7 +756,7 @@ typedef struct
|
||||||
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
||||||
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
||||||
std::string strContainerNo; //集装箱号
|
std::string strContainerNo; //集装箱号
|
||||||
std::string strBestImg; //集装箱最优图
|
std::string strBestImg; //集装箱最优图
|
||||||
float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用
|
float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用
|
||||||
uint64_t i64TimeStamp = 0; //集装箱最优图时间戳
|
uint64_t i64TimeStamp = 0; //集装箱最优图时间戳
|
||||||
Step1Location step1Location; //原图上大框坐标
|
Step1Location step1Location; //原图上大框坐标
|
||||||
|
|
@ -832,30 +832,30 @@ typedef struct imganalyse
|
||||||
{
|
{
|
||||||
// from file
|
// from file
|
||||||
/////////下述设定取自csv文件
|
/////////下述设定取自csv文件
|
||||||
int nType; //算法目的 0:动态检测 1:车厢划分
|
int nType; //算法目的 0:动态检测 1:车厢划分
|
||||||
int nAreaX1; //算法监测区域 开始位置x坐标
|
int nAreaX1; //算法监测区域 开始位置x坐标
|
||||||
int nAreaY1; //算法监测区域 开始位置y坐标
|
int nAreaY1; //算法监测区域 开始位置y坐标
|
||||||
int nAreaX2; //算法监测区域 结束位置x坐标
|
int nAreaX2; //算法监测区域 结束位置x坐标
|
||||||
int nAreaY2; //算法监测区域 结束位置y坐标
|
int nAreaY2; //算法监测区域 结束位置y坐标
|
||||||
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
|
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
|
||||||
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件
|
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件
|
||||||
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效)
|
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效)
|
||||||
double dSameThresholdVal; //判定匹配相同的阈值
|
double dSameThresholdVal; //判定匹配相同的阈值
|
||||||
double dDiffThresholdVal; //判定匹配不同的阈值
|
double dDiffThresholdVal; //判定匹配不同的阈值
|
||||||
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
|
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
|
||||||
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
|
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
|
||||||
int templemethod; //模型比对模式
|
int templemethod; //模型比对模式
|
||||||
int histmethod; //直方图比对模式
|
int histmethod; //直方图比对模式
|
||||||
int specmethod; //自定义比对模式
|
int specmethod; //自定义比对模式
|
||||||
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
|
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
|
||||||
std::string baseImagePath; //基准图片路径
|
std::string baseImagePath; //基准图片路径
|
||||||
/////////下述设定为处理识别变量
|
/////////下述设定为处理识别变量
|
||||||
double dComparePoint; //比对值
|
double dComparePoint; //比对值
|
||||||
double dPreComparePoint; //比对值
|
double dPreComparePoint; //比对值
|
||||||
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
|
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
|
||||||
bool bPreChanged; //上一帧与基准图对比值
|
bool bPreChanged; //上一帧与基准图对比值
|
||||||
bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志
|
bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志
|
||||||
int nSameCount; //比对值没有发生变化的计数
|
int nSameCount; //比对值没有发生变化的计数
|
||||||
int iIndex; //第几个配置项
|
int iIndex; //第几个配置项
|
||||||
}AnalyseInfo;
|
}AnalyseInfo;
|
||||||
|
|
||||||
|
|
@ -866,25 +866,25 @@ typedef struct trainpartion
|
||||||
{
|
{
|
||||||
std::string strTrainDate;
|
std::string strTrainDate;
|
||||||
std::string strTrainName;
|
std::string strTrainName;
|
||||||
int nindex; //车厢顺位
|
int nindex; //车厢顺位
|
||||||
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
|
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
|
||||||
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
|
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
|
||||||
float fspeed; //当节车厢的车速
|
float fspeed; //当节车厢的车速
|
||||||
int startframe; //当节车厢出现的开始帧帧号
|
int startframe; //当节车厢出现的开始帧帧号
|
||||||
int endframe; //当节车厢出现的结束帧帧号
|
int endframe; //当节车厢出现的结束帧帧号
|
||||||
int modelSpaceFrame;
|
int modelSpaceFrame;
|
||||||
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
|
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
|
||||||
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
|
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
|
||||||
float fLTX; //车钩开始位置X值
|
float fLTX; //车钩开始位置X值
|
||||||
float fLTY; //车钩开始位置y值
|
float fLTY; //车钩开始位置y值
|
||||||
float fRBX; //车钩结束位置X值
|
float fRBX; //车钩结束位置X值
|
||||||
float fRBY; //车钩结束位置y值
|
float fRBY; //车钩结束位置y值
|
||||||
bool bIsEnd = false; //是否最后一节
|
bool bIsEnd = false; //是否最后一节
|
||||||
int nStatus; //方向(0:未知,1:向左行驶,2:向右行驶)
|
int nStatus; //方向(0:未知,1:向左行驶,2:向右行驶)
|
||||||
int iRate; //帧率
|
int iRate; //帧率
|
||||||
}PartionInfo;
|
}PartionInfo;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
std::shared_ptr<ProcessData> processData;
|
std::shared_ptr<ProcessData> processData;
|
||||||
std::string strAllClassType;
|
std::string strAllClassType;
|
||||||
|
|
@ -895,7 +895,8 @@ typedef struct
|
||||||
{
|
{
|
||||||
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
||||||
uint32_t iFrameId = 0; //帧号
|
uint32_t iFrameId = 0; //帧号
|
||||||
float fCenterX; //第一步识别目标中心点X坐标
|
float fCenterX; //第一步识别目标中心点X坐标
|
||||||
|
float fTargetWidth; // 第一步识别目标X坐标宽度
|
||||||
} CalculateInfo;
|
} CalculateInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -50,6 +50,7 @@ private:
|
||||||
std::map<int, std::vector<std::string>> mapSourcePushPort_;
|
std::map<int, std::vector<std::string>> mapSourcePushPort_;
|
||||||
|
|
||||||
MoveData moveData_;
|
MoveData moveData_;
|
||||||
|
std::queue<MoveData> queuwMoveData_;
|
||||||
std::string strDataDir_;
|
std::string strDataDir_;
|
||||||
|
|
||||||
uint32_t iOrigDataNO_; //原过车数据个数
|
uint32_t iOrigDataNO_; //原过车数据个数
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -9,7 +9,7 @@
|
||||||
#include "AppCommon.h"
|
#include "AppCommon.h"
|
||||||
|
|
||||||
|
|
||||||
//编译器这部分代码按C语言(而不是C++)的方式进行编译
|
//编译器这部分代码按C语言(而不是C++)的方式进行编译
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +65,8 @@ private:
|
||||||
int nDelayTime;
|
int nDelayTime;
|
||||||
bool bIsAvc_ = false;
|
bool bIsAvc_ = false;
|
||||||
int iAudioStream_ = -1;
|
int iAudioStream_ = -1;
|
||||||
|
|
||||||
|
bool bCameraError_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ENGINE_REGIST(CameraEngine)
|
ENGINE_REGIST(CameraEngine)
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ APP_ERROR ReadImgEngine::Process()
|
||||||
{
|
{
|
||||||
std::string strFilePath = vecFiles_.at(iFileIndex);
|
std::string strFilePath = vecFiles_.at(iFileIndex);
|
||||||
cv::Mat matBGR = cv::imread(strFilePath);
|
cv::Mat matBGR = cv::imread(strFilePath);
|
||||||
|
|
||||||
//组织数据
|
//组织数据
|
||||||
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
|
||||||
pProcessData->iWidth = matBGR.cols;
|
pProcessData->iWidth = matBGR.cols;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -48,6 +48,7 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string strResultPath_;
|
std::string strResultPath_;
|
||||||
|
std::string strLogBakPath_;
|
||||||
|
|
||||||
int iDaysNumber_;
|
int iDaysNumber_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -58,11 +58,11 @@ private:
|
||||||
int iChkStopPX_;
|
int iChkStopPX_;
|
||||||
int iChkStopCount_;
|
int iChkStopCount_;
|
||||||
int iDirection_; //方向
|
int iDirection_; //方向
|
||||||
int iPushDirection_; //需要识别的方向
|
int iPushDirection_; //需要识别的方向
|
||||||
int rightFirst_; // 向右行驶的在前大框类型
|
int rightFirst_; // 向右行驶的在前大框类型
|
||||||
int leftFirst_; // 向左行驶的在前大框类型
|
int leftFirst_; // 向左行驶的在前大框类型
|
||||||
int iPartitionFrameNum_; //满足跨车厢的帧间隔
|
int iPartitionFrameNum_; //满足跨车厢的帧间隔
|
||||||
int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值
|
int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值
|
||||||
std::map<int, PostData> mapPostDataFrist_; //[key-数据源id, value-第一步识别信息]
|
std::map<int, PostData> mapPostDataFrist_; //[key-数据源id, value-第一步识别信息]
|
||||||
std::map<int, std::map<int, std::vector<Step1Location>>> mapMapStep1Info_; //[key-数据源id, value-[key-识别目标, value-识别框集合]]
|
std::map<int, std::map<int, std::vector<Step1Location>>> mapMapStep1Info_; //[key-数据源id, value-[key-识别目标, value-识别框集合]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
using namespace ai_matrix;
|
using namespace ai_matrix;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> mapLoad = {
|
||||||
|
{"C62", "60"},
|
||||||
|
{"C62B", "61"},
|
||||||
|
{"C63", "61"},
|
||||||
|
{"C64", "61"},
|
||||||
|
{"C65", "60"},
|
||||||
|
{"C70", "70"},
|
||||||
|
{"C80", "80"},
|
||||||
|
{"KM70", "70"},
|
||||||
|
{"KM81", "81"},
|
||||||
|
{"KM98", "98"}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
MergerAllEngine::MergerAllEngine() {}
|
MergerAllEngine::MergerAllEngine() {}
|
||||||
|
|
||||||
MergerAllEngine::~MergerAllEngine() {}
|
MergerAllEngine::~MergerAllEngine() {}
|
||||||
|
|
@ -133,7 +149,7 @@ void MergerAllEngine::PushData(std::shared_ptr<Train> pTrain)
|
||||||
pTrain->bMergerFlag = true;
|
pTrain->bMergerFlag = true;
|
||||||
std::shared_ptr<Train> pTrainToCsv = std::make_shared<Train>();
|
std::shared_ptr<Train> pTrainToCsv = std::make_shared<Train>();
|
||||||
*pTrainToCsv = *pTrain;
|
*pTrainToCsv = *pTrain;
|
||||||
|
|
||||||
if (bUploadFlag_)
|
if (bUploadFlag_)
|
||||||
{
|
{
|
||||||
queTrain_.push(pTrain);
|
queTrain_.push(pTrain);
|
||||||
|
|
@ -251,7 +267,7 @@ APP_ERROR MergerAllEngine::Process()
|
||||||
}
|
}
|
||||||
|
|
||||||
int iHaveDataCnt = QueueHaveDataCount();
|
int iHaveDataCnt = QueueHaveDataCount();
|
||||||
//识别目标信息个数和获取信息个数相等,则合并信息推送web
|
//识别目标信息个数和获取信息个数相等,则合并信息推送web
|
||||||
if (iHaveDataCnt == iPopPortCnt_)
|
if (iHaveDataCnt == iPopPortCnt_)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Train> pTrain = nullptr;
|
std::shared_ptr<Train> pTrain = nullptr;
|
||||||
|
|
@ -299,7 +315,7 @@ APP_ERROR MergerAllEngine::Process()
|
||||||
pTrain->container1 = pTrainContainer->container1;
|
pTrain->container1 = pTrainContainer->container1;
|
||||||
pTrain->container2 = pTrainContainer->container2;
|
pTrain->container2 = pTrainContainer->container2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//车头在前为第0节; 车头在后为最后一节+1
|
//车头在前为第0节; 车头在后为最后一节+1
|
||||||
if(pTrain->trainNum.iTrainTypeId == 0 && iTrainIndex_ == 1)
|
if(pTrain->trainNum.iTrainTypeId == 0 && iTrainIndex_ == 1)
|
||||||
{
|
{
|
||||||
|
|
@ -312,12 +328,28 @@ APP_ERROR MergerAllEngine::Process()
|
||||||
特殊处理:针对车头在后的且当前为最后一节,且未识别到车型,则默认设置为车头。
|
特殊处理:针对车头在后的且当前为最后一节,且未识别到车型,则默认设置为车头。
|
||||||
防止车尾间隔误识别,多切分车型,且web端无法过滤的问题。
|
防止车尾间隔误识别,多切分车型,且web端无法过滤的问题。
|
||||||
*/
|
*/
|
||||||
if (!bHeadFrontFlag_ && pTrain->bIsEnd && pTrain->trainNum.iTrainTypeId == -1)
|
if (!bHeadFrontFlag_
|
||||||
|
&& pTrain->bIsEnd
|
||||||
|
&& pTrain->trainNum.iTrainTypeId == -1)
|
||||||
{
|
{
|
||||||
LogDebug << "cometime:" << pTrain->strTrainDate << " " << pTrain->strTrainName << " iCarXH:" << pTrain->iCarXH
|
LogDebug << "cometime:" << pTrain->strTrainDate << " " << pTrain->strTrainName << " iCarXH:" << pTrain->iCarXH
|
||||||
<< " num:" << pTrain->trainNum.strTrainNum;
|
<< " num:" << pTrain->trainNum.strTrainNum;
|
||||||
pTrain->trainNum.iTrainTypeId = 0;
|
pTrain->trainNum.iTrainTypeId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修正载重
|
||||||
|
for (std::map<std::string, std::string>::iterator it =
|
||||||
|
mapLoad.begin();
|
||||||
|
it != mapLoad.end(); ++it) {
|
||||||
|
|
||||||
|
if (pTrain->trainNum.strTrainType.find(it->first) !=
|
||||||
|
std::string::npos) {
|
||||||
|
pTrain->trainPro.strLoad = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pTrain->trainPro.strLoad.size() > 2 && pTrain->trainPro.strLoad[0] != '1') pTrain->trainPro.strLoad = "";
|
||||||
|
|
||||||
PushData(pTrain);
|
PushData(pTrain);
|
||||||
|
|
||||||
//最后一节处理后,初始化参数
|
//最后一节处理后,初始化参数
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -45,10 +45,10 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
LogWarn << "engineId_:" << engineId_ << " not use engine";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> compression_params;
|
vector<int> compression_params;
|
||||||
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
|
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
|
||||||
compression_params.push_back(iPicQuality); //图片质量
|
compression_params.push_back(iPicQuality); //图片质量
|
||||||
iDirection_ = DIRECTION_UNKNOWN;
|
iDirection_ = DIRECTION_UNKNOWN;
|
||||||
|
|
||||||
int iRet = APP_ERR_OK;
|
int iRet = APP_ERR_OK;
|
||||||
|
|
@ -61,7 +61,7 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SaveImgData> pSaveImgData = std::static_pointer_cast<SaveImgData>(pvoidd);
|
std::shared_ptr<SaveImgData> pSaveImgData = std::static_pointer_cast<SaveImgData>(pvoidd);
|
||||||
|
|
||||||
//如果设置了方向,则方向不对直接过滤,但结束帧不能过滤,需流转到后面Engine,保证后面处理正确。
|
//如果设置了方向,则方向不对直接过滤,但结束帧不能过滤,需流转到后面Engine,保证后面处理正确。
|
||||||
|
|
@ -113,13 +113,13 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.保存图片
|
// 3.保存图片
|
||||||
|
|
||||||
if (pSaveImgData->pData != nullptr && pSaveImgData->iSize != 0)
|
if (pSaveImgData->pData != nullptr && pSaveImgData->iSize != 0)
|
||||||
{
|
{
|
||||||
cv::Mat matBGR(pSaveImgData->iHeight, pSaveImgData->iWidth, CV_8UC3, static_cast<uint8_t *>(pSaveImgData->pData.get())); //RGB
|
cv::Mat matBGR(pSaveImgData->iHeight, pSaveImgData->iWidth, CV_8UC3, static_cast<uint8_t *>(pSaveImgData->pData.get())); //RGB
|
||||||
iWidth = pSaveImgData->iWidth;
|
iWidth = pSaveImgData->iWidth;
|
||||||
iHeight = pSaveImgData->iHeight;
|
iHeight = pSaveImgData->iHeight;
|
||||||
|
|
||||||
// cv::Mat mtOutImage;
|
// cv::Mat mtOutImage;
|
||||||
// cv::cvtColor(cvimg, mtOutImage, cv::COLOR_RGB2BGR);
|
// cv::cvtColor(cvimg, mtOutImage, cv::COLOR_RGB2BGR);
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -4,276 +4,276 @@
|
||||||
|
|
||||||
SocketEngine::SocketEngine()
|
SocketEngine::SocketEngine()
|
||||||
{
|
{
|
||||||
isStop_ = false;
|
isStop_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketEngine::~SocketEngine() {}
|
SocketEngine::~SocketEngine() {}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::Init()
|
APP_ERROR SocketEngine::Init()
|
||||||
{
|
{
|
||||||
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
||||||
|
|
||||||
this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open");
|
this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open");
|
||||||
this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
|
this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
|
||||||
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
|
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
|
||||||
|
|
||||||
MyShellInfo << "SocketEngine init ok";
|
MyShellInfo << "SocketEngine init ok";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::DeInit()
|
APP_ERROR SocketEngine::DeInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int fd = 0; fd <= max_fd; ++fd)
|
for (int fd = 0; fd <= max_fd; ++fd)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(fd, &master_set))
|
if (FD_ISSET(fd, &master_set))
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyShellInfo << "SocketEngine deinit ok";
|
MyShellInfo << "SocketEngine deinit ok";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::Process()
|
APP_ERROR SocketEngine::Process()
|
||||||
{
|
{
|
||||||
int ret = APP_ERR_OK;
|
int ret = APP_ERR_OK;
|
||||||
|
|
||||||
if (this->socketOpenType_)
|
if (this->socketOpenType_)
|
||||||
{
|
{
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
if (!this->Socket_(this->socketPort_)) continue;
|
if (!this->Socket_(this->socketPort_)) continue;
|
||||||
if (!this->Bind()) continue;
|
if (!this->Bind()) continue;
|
||||||
this->Listen(this->socketQueueLen_);
|
this->Listen(this->socketQueueLen_);
|
||||||
this->Run();
|
this->Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Socket_(int port)
|
bool SocketEngine::Socket_(int port)
|
||||||
{
|
{
|
||||||
bzero(&server_addr, sizeof(server_addr));
|
bzero(&server_addr, sizeof(server_addr));
|
||||||
server_addr.sin_family = AF_INET;
|
server_addr.sin_family = AF_INET;
|
||||||
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
||||||
server_addr.sin_port = htons(port);
|
server_addr.sin_port = htons(port);
|
||||||
// create socket to listen
|
// create socket to listen
|
||||||
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
|
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if (listen_fd < 0)
|
if (listen_fd < 0)
|
||||||
{
|
{
|
||||||
LogError << "Create Scoket_Server Failed!";
|
LogError << "Create Scoket_Server Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Bind()
|
bool SocketEngine::Bind()
|
||||||
{
|
{
|
||||||
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
|
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Bind Failed!";
|
LogError << "Scoket_Server Bind Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogInfo << "Scoket_Server Bind Successfully.";
|
LogInfo << "Scoket_Server Bind Successfully.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Listen(int queue_len)
|
bool SocketEngine::Listen(int queue_len)
|
||||||
{
|
{
|
||||||
if (-1 == listen(listen_fd, queue_len))
|
if (-1 == listen(listen_fd, queue_len))
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Listen Failed!";
|
LogError << "Scoket_Server Listen Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogInfo << "Scoket_Server Listen Successfully.";
|
LogInfo << "Scoket_Server Listen Successfully.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Accept()
|
bool SocketEngine::Accept()
|
||||||
{
|
{
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
socklen_t client_addr_len = sizeof(client_addr);
|
socklen_t client_addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
||||||
if (new_fd < 0)
|
if (new_fd < 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Accept Failed!";
|
LogError << "Scoket_Server Accept Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP
|
std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP
|
||||||
|
|
||||||
LogInfo << ip << " new connection was accepted.";
|
LogInfo << ip << " new connection was accepted.";
|
||||||
|
|
||||||
mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0)));
|
mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0)));
|
||||||
|
|
||||||
// 将新建立的连接的fd加入master_set
|
// 将新建立的连接的fd加入master_set
|
||||||
FD_SET(new_fd, &master_set);
|
FD_SET(new_fd, &master_set);
|
||||||
if (new_fd > max_fd)
|
if (new_fd > max_fd)
|
||||||
{
|
{
|
||||||
max_fd = new_fd;
|
max_fd = new_fd;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Recv(int nums)
|
bool SocketEngine::Recv(int nums)
|
||||||
{
|
{
|
||||||
for (int fd = 0; fd <= max_fd; ++fd)
|
for (int fd = 0; fd <= max_fd; ++fd)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(fd, &working_set))
|
if (FD_ISSET(fd, &working_set))
|
||||||
{
|
{
|
||||||
bool close_conn = false; // 标记当前连接是否断开了
|
bool close_conn = false; // 标记当前连接是否断开了
|
||||||
|
|
||||||
char order_str[512] = { 0 };
|
char order_str[512] = { 0 };
|
||||||
|
|
||||||
int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0);
|
int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0);
|
||||||
|
|
||||||
if (size_get <= 0)
|
if (size_get <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
bool isHeart_beat = (std::string(order_str) == "matrixai");
|
bool isHeart_beat = (std::string(order_str) == "matrixai");
|
||||||
if (isHeart_beat)
|
if (isHeart_beat)
|
||||||
{
|
{
|
||||||
mmap[fd].second = 0; // 每次收到心跳包,count置0
|
mmap[fd].second = 0; // 每次收到心跳包,count置0
|
||||||
//LogDebug << "Scoket_Server Received heart-beat from client.";
|
//LogDebug << "Scoket_Server Received heart-beat from client.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo << "Received message from client:" << std::string(order_str);
|
LogInfo << "Received message from client:" << std::string(order_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (close_conn) // 当前这个连接有问题,关闭它
|
if (close_conn) // 当前这个连接有问题,关闭它
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
FD_CLR(fd, &master_set);
|
FD_CLR(fd, &master_set);
|
||||||
if (fd == max_fd) // 需要更新max_fd;
|
if (fd == max_fd) // 需要更新max_fd;
|
||||||
{
|
{
|
||||||
while (FD_ISSET(max_fd, &master_set) == false)
|
while (FD_ISSET(max_fd, &master_set) == false)
|
||||||
--max_fd;
|
--max_fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Run()
|
bool SocketEngine::Run()
|
||||||
{
|
{
|
||||||
pthread_t id; // 创建心跳检测线程
|
pthread_t id; // 创建心跳检测线程
|
||||||
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
|
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Can not create heart-beat checking thread.";
|
LogError << "Scoket_Server Can not create heart-beat checking thread.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
|
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Can not create message send thread.";
|
LogError << "Scoket_Server Can not create message send thread.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
max_fd = listen_fd; // 初始化max_fd
|
max_fd = listen_fd; // 初始化max_fd
|
||||||
FD_ZERO(&master_set);
|
FD_ZERO(&master_set);
|
||||||
FD_SET(listen_fd, &master_set); // 添加监听fd
|
FD_SET(listen_fd, &master_set); // 添加监听fd
|
||||||
|
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
FD_ZERO(&working_set);
|
FD_ZERO(&working_set);
|
||||||
memcpy(&working_set, &master_set, sizeof(master_set));
|
memcpy(&working_set, &master_set, sizeof(master_set));
|
||||||
|
|
||||||
timeout.tv_sec = 30;
|
timeout.tv_sec = 30;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
|
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
|
||||||
/*if (nums < 0)
|
/*if (nums < 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server select() error!";
|
LogError << "Scoket_Server select() error!";
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (nums <= 0)
|
if (nums <= 0)
|
||||||
{
|
{
|
||||||
//cout << "select() is timeout!";
|
//cout << "select() is timeout!";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(listen_fd, &working_set))
|
if (FD_ISSET(listen_fd, &working_set))
|
||||||
Accept(); // 有新的客户端请求
|
Accept(); // 有新的客户端请求
|
||||||
else
|
else
|
||||||
Recv(nums); // 接收客户端的消息
|
Recv(nums); // 接收客户端的消息
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析命令
|
//解析命令
|
||||||
bool SocketEngine::getOrder(const std::string &recv, Json::Value &order)
|
bool SocketEngine::getOrder(const std::string &recv, Json::Value &order)
|
||||||
{
|
{
|
||||||
Json::CharReaderBuilder readerBuilder;
|
Json::CharReaderBuilder readerBuilder;
|
||||||
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
||||||
|
|
||||||
JSONCPP_STRING errs;
|
JSONCPP_STRING errs;
|
||||||
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
|
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (order.isArray()) {
|
if (order.isArray()) {
|
||||||
if (order.size() > 0) order = order[0];
|
if (order.size() > 0) order = order[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info)
|
std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info)
|
||||||
{
|
{
|
||||||
Json::Value feedBack;
|
Json::Value feedBack;
|
||||||
Json::StreamWriterBuilder strbuild;
|
Json::StreamWriterBuilder strbuild;
|
||||||
|
|
||||||
feedBack["poundNo"] = poundNo;
|
feedBack["poundNo"] = poundNo;
|
||||||
feedBack["type"] = type;
|
feedBack["type"] = type;
|
||||||
feedBack["info"] = info;
|
feedBack["info"] = info;
|
||||||
//
|
//
|
||||||
return Json::writeString(strbuild, feedBack);
|
return Json::writeString(strbuild, feedBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SocketEngine::sendInfo(void* arg) {
|
void* SocketEngine::sendInfo(void* arg) {
|
||||||
SocketEngine* s = (SocketEngine*)arg;
|
SocketEngine* s = (SocketEngine*)arg;
|
||||||
while (!s->isStop_) {
|
while (!s->isStop_) {
|
||||||
//pop端口0
|
//pop端口0
|
||||||
std::shared_ptr<void> pVoidData0 = nullptr;
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
||||||
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
|
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
|
||||||
if (nullptr == pVoidData0)
|
if (nullptr == pVoidData0)
|
||||||
{
|
{
|
||||||
usleep(1000); //1ms
|
usleep(1000); //1ms
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::string> pMessage = std::static_pointer_cast<std::string>(pVoidData0);
|
std::shared_ptr<std::string> pMessage = std::static_pointer_cast<std::string>(pVoidData0);
|
||||||
|
|
||||||
SendAllClient(s->mmap, *pMessage);
|
SendAllClient(s->mmap, *pMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -281,176 +281,176 @@ void* SocketEngine::sendInfo(void* arg) {
|
||||||
// thread function
|
// thread function
|
||||||
void* SocketEngine::heart_handler(void* arg)
|
void* SocketEngine::heart_handler(void* arg)
|
||||||
{
|
{
|
||||||
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
|
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
|
||||||
SocketEngine* s = (SocketEngine*)arg;
|
SocketEngine* s = (SocketEngine*)arg;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
|
||||||
for (; it != s->mmap.end(); )
|
for (; it != s->mmap.end(); )
|
||||||
{
|
{
|
||||||
if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线
|
if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线
|
||||||
{
|
{
|
||||||
LogInfo << "The client " << it->second.first << " has be offline.\n";
|
LogInfo << "The client " << it->second.first << " has be offline.\n";
|
||||||
|
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
close(fd); // 关闭该连接
|
close(fd); // 关闭该连接
|
||||||
FD_CLR(fd, &s->master_set);
|
FD_CLR(fd, &s->master_set);
|
||||||
if (fd == s->max_fd) // 需要更新max_fd;
|
if (fd == s->max_fd) // 需要更新max_fd;
|
||||||
{
|
{
|
||||||
while (FD_ISSET(s->max_fd, &s->master_set) == false)
|
while (FD_ISSET(s->max_fd, &s->master_set) == false)
|
||||||
s->max_fd--;
|
s->max_fd--;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->mmap.erase(it++); // 从map中移除该记录
|
s->mmap.erase(it++); // 从map中移除该记录
|
||||||
}
|
}
|
||||||
else if (it->second.second < 5 && it->second.second >= 0)
|
else if (it->second.second < 5 && it->second.second >= 0)
|
||||||
{
|
{
|
||||||
it->second.second += 1;
|
it->second.second += 1;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(3); // 定时三秒
|
sleep(1); // 定时三秒
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SocketEngine::SendClient(std::map<int, std::pair<std::string, int> > mmap, const std::string ip, const std::string message) {
|
bool SocketEngine::SendClient(std::map<int, std::pair<std::string, int> > mmap, const std::string ip, const std::string message) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
||||||
for (; it != mmap.end(); ++it)
|
for (; it != mmap.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->second.first == ip) // 遍历找雷达ip
|
if (it->second.first == ip) // 遍历找雷达ip
|
||||||
{
|
{
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
|
|
||||||
if (send(fd, message.c_str(), message.size(), 0) <= 0)
|
if (send(fd, message.c_str(), message.size(), 0) <= 0)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char clientFeedBack[256] = { 0 };
|
char clientFeedBack[256] = { 0 };
|
||||||
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
||||||
{
|
{
|
||||||
Json::Value feedBack;
|
Json::Value feedBack;
|
||||||
|
|
||||||
if (!getOrder(clientFeedBack, feedBack)) {
|
if (!getOrder(clientFeedBack, feedBack)) {
|
||||||
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
|
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feedBack.get("success", "").asString() == "true")
|
if (feedBack.get("success", "").asString() == "true")
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
|
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
|
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::SendAllClient(std::map<int, std::pair<std::string, int> > mmap, const std::string message) {
|
bool SocketEngine::SendAllClient(std::map<int, std::pair<std::string, int> > mmap, const std::string message) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
||||||
for (; it != mmap.end(); ++it)
|
for (; it != mmap.end(); ++it)
|
||||||
{
|
{
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
|
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
|
||||||
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
|
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// char clientFeedBack[256] = { 0 };
|
// char clientFeedBack[256] = { 0 };
|
||||||
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
||||||
// {
|
// {
|
||||||
// Json::Value feedBack;
|
// Json::Value feedBack;
|
||||||
|
|
||||||
// if (!getOrder(clientFeedBack, feedBack)) {
|
// if (!getOrder(clientFeedBack, feedBack)) {
|
||||||
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
|
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (feedBack.get("success", "").asString() == "true")
|
// if (feedBack.get("success", "").asString() == "true")
|
||||||
// {
|
// {
|
||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
|
|
||||||
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
|
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to all client failed, message:" << message;
|
LogError << "Socker Server send message to all client failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SocketEngine::HexToStr(const std::string &str)
|
std::string SocketEngine::HexToStr(const std::string &str)
|
||||||
{
|
{
|
||||||
std::string hex = str;
|
std::string hex = str;
|
||||||
long len = hex.length();
|
long len = hex.length();
|
||||||
std::string newString;
|
std::string newString;
|
||||||
for (long i = 0; i < len; i += 2)
|
for (long i = 0; i < len; i += 2)
|
||||||
{
|
{
|
||||||
std::string byte = hex.substr(i, 2);
|
std::string byte = hex.substr(i, 2);
|
||||||
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
|
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
|
||||||
newString.push_back(chr);
|
newString.push_back(chr);
|
||||||
}
|
}
|
||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string SocketEngine::StrToHex(const std::string &str)
|
std::string SocketEngine::StrToHex(const std::string &str)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
char buf[2];
|
char buf[2];
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << str;
|
ss << str;
|
||||||
while (ss.read((char*)(&c), sizeof(c)))
|
while (ss.read((char*)(&c), sizeof(c)))
|
||||||
{
|
{
|
||||||
sprintf(buf, "%02x", c);
|
sprintf(buf, "%02x", c);
|
||||||
result += buf;
|
result += buf;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -192,7 +192,9 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
|
||||||
{
|
{
|
||||||
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_" + std::to_string(*iter)]->push(std::static_pointer_cast<void>(pMoveData));
|
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_" + std::to_string(*iter)]->push(std::static_pointer_cast<void>(pMoveData));
|
||||||
}
|
}
|
||||||
//通知第一步开始识别
|
|
||||||
|
// LogInfo << "【来车检测】" << pMoveData->iFrameId << " isEnd:" << pProcessData->bIsEnd;
|
||||||
|
//通知第一步开始识别
|
||||||
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_5"]->push(std::static_pointer_cast<void>(pMoveData));
|
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_5"]->push(std::static_pointer_cast<void>(pMoveData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,16 +285,16 @@ APP_ERROR MoveEngine::Process()
|
||||||
// LogInfo<<"来车当前状态:"<< (nType == 0 ? "有车头" : (nType == 1 ? "无车"));
|
// LogInfo<<"来车当前状态:"<< (nType == 0 ? "有车头" : (nType == 1 ? "无车"));
|
||||||
switch (nType) {
|
switch (nType) {
|
||||||
case 0:
|
case 0:
|
||||||
LogDebug << "来车状态:有车头";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车头";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
LogDebug << "来车状态:无车";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:无车";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
LogDebug << "来车状态:车尾";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:车尾";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
LogDebug << "来车状态:有车";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,9 +194,9 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
std::vector<stDetection> vecSpaceInfo;
|
std::vector<stDetection> vecSpaceInfo;
|
||||||
for (auto it = vecRet.begin(); it != vecRet.end();)
|
for (auto it = vecRet.begin(); it != vecRet.end();)
|
||||||
{
|
{
|
||||||
LogDebug << "frameId:" << pProcessData->iFrameId
|
// LogDebug << "frameId:" << pProcessData->iFrameId
|
||||||
<< " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
|
// << " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
|
||||||
<< " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
|
// << " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
|
||||||
// 根据配置文件中 设置的识别范围,过滤掉无效数据
|
// 根据配置文件中 设置的识别范围,过滤掉无效数据
|
||||||
if (!(it->bbox[0] >= dataSourceCfg.fIdentifyAreasLTX &&
|
if (!(it->bbox[0] >= dataSourceCfg.fIdentifyAreasLTX &&
|
||||||
it->bbox[1] >= dataSourceCfg.fIdentifyAreasLTY &&
|
it->bbox[1] >= dataSourceCfg.fIdentifyAreasLTY &&
|
||||||
|
|
@ -322,6 +322,22 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (it->class_id == K_TRAIN_NUM)
|
||||||
|
{
|
||||||
|
int iCenterY = pProcessData->iHeight / 2;
|
||||||
|
int iHeight0 = it->bbox[1] / 2 + it->bbox[3] / 2;
|
||||||
|
if (iHeight0 > iCenterY) {
|
||||||
|
LogWarn << "矿车编号大框在画面Y轴中线以下,帧号:"
|
||||||
|
<< pProcessData->iFrameId
|
||||||
|
<< " 画面Y轴中心:" << iCenterY
|
||||||
|
<< " 大框Y轴中心:" << iHeight0 ;
|
||||||
|
// << "[" << it->bbox[0] << "," << it->bbox[1] << "]"
|
||||||
|
// << "[" << it->bbox[2] << "," << it->bbox[3] << "]";
|
||||||
|
it = vecRet.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//补连塔的相机比较近,间隔基本在画面底部,因此当间隔比较靠画面上时过滤掉。
|
//补连塔的相机比较近,间隔基本在画面底部,因此当间隔比较靠画面上时过滤掉。
|
||||||
if ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == U_TRAIN_SPACE)
|
if ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == U_TRAIN_SPACE)
|
||||||
{
|
{
|
||||||
|
|
@ -484,10 +500,10 @@ APP_ERROR TrainStepOneEngine::Process()
|
||||||
SetTargetType(postSubData);
|
SetTargetType(postSubData);
|
||||||
pPostData->vecPostSubData.emplace_back(postSubData);
|
pPostData->vecPostSubData.emplace_back(postSubData);
|
||||||
|
|
||||||
// LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
|
LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
|
||||||
// << " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
|
<< " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
|
||||||
// << " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
|
<< " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
|
||||||
// << " clear:" << singledata.fClear;
|
<< " clear:" << singledata.fClear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue