1、优化识别切分效果,增加报警信息

This commit is contained in:
Mr.V 2024-08-12 09:41:48 +08:00
parent d72bd78b59
commit f18e10f8f3
25 changed files with 469 additions and 3468 deletions

File diff suppressed because one or more lines are too long

View File

@ -114,7 +114,7 @@ model:
gc_http_open: 1
username: "guest_01"
password: "d55b0f642e817eea24725d2f2a31dd08" # 神东
password: "0a1688bce402a5f6a4279abbfc89c203" # 神东 d55b0f642e817eea24725d2f2a31dd08
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_image_srv: "http://192.168.2.211:9010/"
@ -182,5 +182,5 @@ gc_c_space_frame_width: 500
# 是否识别车头
gc_train_heard_detect: true
#过期文件夹天数
# 识别结果保存天数
gc_days_for_result_expire_folder: 3

View File

@ -24,7 +24,7 @@
#include <math.h>
#include <chrono>
#include <cmath>
#include <functional>
#include <functional>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@ -459,10 +459,10 @@ typedef struct
std::shared_ptr<void> pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1
uint64_t i64TimeStamp = 0; //帧数据时间戳
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 iCarXH = 0; //当前大框所属车厢
} InferenceData;
@ -491,7 +491,7 @@ typedef struct
std::shared_ptr<void> pData = nullptr; // Smart pointer of data
uint64_t i64TimeStamp = 0; //帧数据时间戳
bool bHostMemory = false; //数据解码后内存是否在Host侧
std::string strPicFilePath;
std::string strPicFilePath;
std::string strTrainDate; //过车日期 (格式YYYY-MM-DD)
std::string strTrainName; //车次 (格式HH-MM-SS)
bool bIsEnd = false; //列车结束标识
@ -756,7 +756,7 @@ typedef struct
std::string strTrainDate; //过车日期 (格式YYYY-MM-DD)
std::string strTrainName; //车次 (格式HH-MM-SS)
std::string strContainerNo; //集装箱号
std::string strBestImg; //集装箱最优图
std::string strBestImg; //集装箱最优图
float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用
uint64_t i64TimeStamp = 0; //集装箱最优图时间戳
Step1Location step1Location; //原图上大框坐标
@ -832,30 +832,30 @@ typedef struct imganalyse
{
// from file
/////////下述设定取自csv文件
int nType; //算法目的 0:动态检测 1:车厢划分
int nAreaX1; //算法监测区域 开始位置x坐标
int nAreaY1; //算法监测区域 开始位置y坐标
int nAreaX2; //算法监测区域 结束位置x坐标
int nAreaY2; //算法监测区域 结束位置y坐标
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true以匹配度不同作为判定条件
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false不启用(无效) true:启用(有效)
double dSameThresholdVal; //判定匹配相同的阈值
double dDiffThresholdVal; //判定匹配不同的阈值
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
int templemethod; //模型比对模式
int histmethod; //直方图比对模式
int specmethod; //自定义比对模式
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
std::string baseImagePath; //基准图片路径
int nType; //算法目的 0:动态检测 1:车厢划分
int nAreaX1; //算法监测区域 开始位置x坐标
int nAreaY1; //算法监测区域 开始位置y坐标
int nAreaX2; //算法监测区域 结束位置x坐标
int nAreaY2; //算法监测区域 结束位置y坐标
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true以匹配度不同作为判定条件
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false不启用(无效) true:启用(有效)
double dSameThresholdVal; //判定匹配相同的阈值
double dDiffThresholdVal; //判定匹配不同的阈值
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
int templemethod; //模型比对模式
int histmethod; //直方图比对模式
int specmethod; //自定义比对模式
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
std::string baseImagePath; //基准图片路径
/////////下述设定为处理识别变量
double dComparePoint; //比对值
double dComparePoint; //比对值
double dPreComparePoint; //比对值
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
bool bPreChanged; //上一帧与基准图对比值
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
bool bPreChanged; //上一帧与基准图对比值
bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志
int nSameCount; //比对值没有发生变化的计数
int nSameCount; //比对值没有发生变化的计数
int iIndex; //第几个配置项
}AnalyseInfo;
@ -866,25 +866,25 @@ typedef struct trainpartion
{
std::string strTrainDate;
std::string strTrainName;
int nindex; //车厢顺位
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
float fspeed; //当节车厢的车速
int startframe; //当节车厢出现的开始帧帧号
int endframe; //当节车厢出现的结束帧帧号
int nindex; //车厢顺位
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
float fspeed; //当节车厢的车速
int startframe; //当节车厢出现的开始帧帧号
int endframe; //当节车厢出现的结束帧帧号
int modelSpaceFrame;
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
float fLTX; //车钩开始位置X值
float fLTY; //车钩开始位置y值
float fRBX; //车钩结束位置X值
float fRBY; //车钩结束位置y值
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
float fLTX; //车钩开始位置X值
float fLTY; //车钩开始位置y值
float fRBX; //车钩结束位置X值
float fRBY; //车钩结束位置y值
bool bIsEnd = false; //是否最后一节
int nStatus; //方向(0:未知1:向左行驶2:向右行驶)
int iRate; //帧率
}PartionInfo;
typedef struct
typedef struct
{
std::shared_ptr<ProcessData> processData;
std::string strAllClassType;
@ -895,7 +895,8 @@ typedef struct
{
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
uint32_t iFrameId = 0; //帧号
float fCenterX; //第一步识别目标中心点X坐标
float fCenterX; //第一步识别目标中心点X坐标
float fTargetWidth; // 第一步识别目标X坐标宽度
} CalculateInfo;

File diff suppressed because one or more lines are too long

View File

@ -50,6 +50,7 @@ private:
std::map<int, std::vector<std::string>> mapSourcePushPort_;
MoveData moveData_;
std::queue<MoveData> queuwMoveData_;
std::string strDataDir_;
uint32_t iOrigDataNO_; //原过车数据个数

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@
#include "AppCommon.h"
//编译器这部分代码按C语言而不是C++)的方式进行编译
//编译器这部分代码按C语言而不是C++)的方式进行编译
#ifdef __cplusplus
extern "C"
{
@ -65,6 +65,8 @@ private:
int nDelayTime;
bool bIsAvc_ = false;
int iAudioStream_ = -1;
bool bCameraError_ = false;
};
ENGINE_REGIST(CameraEngine)

View File

@ -105,7 +105,7 @@ APP_ERROR ReadImgEngine::Process()
{
std::string strFilePath = vecFiles_.at(iFileIndex);
cv::Mat matBGR = cv::imread(strFilePath);
//组织数据
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
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

View File

@ -48,6 +48,7 @@ private:
private:
std::string strResultPath_;
std::string strLogBakPath_;
int iDaysNumber_;
};

File diff suppressed because one or more lines are too long

View File

@ -58,11 +58,11 @@ private:
int iChkStopPX_;
int iChkStopCount_;
int iDirection_; //方向
int iPushDirection_; //需要识别的方向
int iPushDirection_; //需要识别的方向
int rightFirst_; // 向右行驶的在前大框类型
int leftFirst_; // 向左行驶的在前大框类型
int iPartitionFrameNum_; //满足跨车厢的帧间隔
int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值
int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值
std::map<int, PostData> mapPostDataFrist_; //[key-数据源id, value-第一步识别信息]
std::map<int, std::map<int, std::vector<Step1Location>>> mapMapStep1Info_; //[key-数据源id, value-[key-识别目标, value-识别框集合]]

View File

@ -2,6 +2,22 @@
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() {}
@ -133,7 +149,7 @@ void MergerAllEngine::PushData(std::shared_ptr<Train> pTrain)
pTrain->bMergerFlag = true;
std::shared_ptr<Train> pTrainToCsv = std::make_shared<Train>();
*pTrainToCsv = *pTrain;
if (bUploadFlag_)
{
queTrain_.push(pTrain);
@ -251,7 +267,7 @@ APP_ERROR MergerAllEngine::Process()
}
int iHaveDataCnt = QueueHaveDataCount();
//识别目标信息个数和获取信息个数相等则合并信息推送web
//识别目标信息个数和获取信息个数相等则合并信息推送web
if (iHaveDataCnt == iPopPortCnt_)
{
std::shared_ptr<Train> pTrain = nullptr;
@ -299,7 +315,7 @@ APP_ERROR MergerAllEngine::Process()
pTrain->container1 = pTrainContainer->container1;
pTrain->container2 = pTrainContainer->container2;
}
//车头在前为第0节; 车头在后为最后一节+1
if(pTrain->trainNum.iTrainTypeId == 0 && iTrainIndex_ == 1)
{
@ -312,12 +328,28 @@ APP_ERROR MergerAllEngine::Process()
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
<< " num:" << pTrain->trainNum.strTrainNum;
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);
//最后一节处理后,初始化参数

File diff suppressed because one or more lines are too long

View File

@ -45,10 +45,10 @@ APP_ERROR SaveImgEngine::Process()
LogWarn << "engineId_:" << engineId_ << " not use engine";
return APP_ERR_OK;
}
vector<int> compression_params;
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
compression_params.push_back(iPicQuality); //图片质量
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
compression_params.push_back(iPicQuality); //图片质量
iDirection_ = DIRECTION_UNKNOWN;
int iRet = APP_ERR_OK;
@ -61,7 +61,7 @@ APP_ERROR SaveImgEngine::Process()
usleep(1000);
continue;
}
std::shared_ptr<SaveImgData> pSaveImgData = std::static_pointer_cast<SaveImgData>(pvoidd);
//如果设置了方向则方向不对直接过滤但结束帧不能过滤需流转到后面Engine保证后面处理正确。
@ -113,13 +113,13 @@ APP_ERROR SaveImgEngine::Process()
}
// 3.保存图片
if (pSaveImgData->pData != nullptr && pSaveImgData->iSize != 0)
{
cv::Mat matBGR(pSaveImgData->iHeight, pSaveImgData->iWidth, CV_8UC3, static_cast<uint8_t *>(pSaveImgData->pData.get())); //RGB
iWidth = pSaveImgData->iWidth;
iHeight = pSaveImgData->iHeight;
// cv::Mat mtOutImage;
// 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

View File

@ -4,276 +4,276 @@
SocketEngine::SocketEngine()
{
isStop_ = false;
isStop_ = false;
}
SocketEngine::~SocketEngine() {}
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->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open");
this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
MyShellInfo << "SocketEngine init ok";
return APP_ERR_OK;
MyShellInfo << "SocketEngine init ok";
return APP_ERR_OK;
}
APP_ERROR SocketEngine::DeInit()
{
for (int fd = 0; fd <= max_fd; ++fd)
{
if (FD_ISSET(fd, &master_set))
{
close(fd);
}
}
for (int fd = 0; fd <= max_fd; ++fd)
{
if (FD_ISSET(fd, &master_set))
{
close(fd);
}
}
MyShellInfo << "SocketEngine deinit ok";
return APP_ERR_OK;
MyShellInfo << "SocketEngine deinit ok";
return APP_ERR_OK;
}
APP_ERROR SocketEngine::Process()
{
int ret = APP_ERR_OK;
int ret = APP_ERR_OK;
if (this->socketOpenType_)
{
while (!isStop_)
{
if (!this->Socket_(this->socketPort_)) continue;
if (!this->Bind()) continue;
this->Listen(this->socketQueueLen_);
this->Run();
}
if (this->socketOpenType_)
{
while (!isStop_)
{
if (!this->Socket_(this->socketPort_)) continue;
if (!this->Bind()) continue;
this->Listen(this->socketQueueLen_);
this->Run();
}
}
else
{
while (!isStop_)
{
usleep(1000);
}
}
}
else
{
while (!isStop_)
{
usleep(1000);
}
}
return APP_ERR_OK;
return APP_ERR_OK;
}
bool SocketEngine::Socket_(int port)
{
bzero(&server_addr, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
server_addr.sin_port = htons(port);
// create socket to listen
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
if (listen_fd < 0)
{
LogError << "Create Scoket_Server Failed!";
return false;
}
int opt = 1;
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
return true;
bzero(&server_addr, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
server_addr.sin_port = htons(port);
// create socket to listen
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
if (listen_fd < 0)
{
LogError << "Create Scoket_Server Failed!";
return false;
}
int opt = 1;
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
return true;
}
bool SocketEngine::Bind()
{
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
{
LogError << "Scoket_Server Bind Failed!";
return false;
}
LogInfo << "Scoket_Server Bind Successfully.";
return true;
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
{
LogError << "Scoket_Server Bind Failed!";
return false;
}
LogInfo << "Scoket_Server Bind Successfully.";
return true;
}
bool SocketEngine::Listen(int queue_len)
{
if (-1 == listen(listen_fd, queue_len))
{
LogError << "Scoket_Server Listen Failed!";
return false;
}
LogInfo << "Scoket_Server Listen Successfully.";
return true;
if (-1 == listen(listen_fd, queue_len))
{
LogError << "Scoket_Server Listen Failed!";
return false;
}
LogInfo << "Scoket_Server Listen Successfully.";
return true;
}
bool SocketEngine::Accept()
{
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
if (new_fd < 0)
{
LogError << "Scoket_Server Accept Failed!";
return false;
}
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
if (new_fd < 0)
{
LogError << "Scoket_Server Accept Failed!";
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_SET(new_fd, &master_set);
if (new_fd > max_fd)
{
max_fd = new_fd;
}
return true;
// 将新建立的连接的fd加入master_set
FD_SET(new_fd, &master_set);
if (new_fd > max_fd)
{
max_fd = new_fd;
}
return true;
}
bool SocketEngine::Recv(int nums)
{
for (int fd = 0; fd <= max_fd; ++fd)
{
if (FD_ISSET(fd, &working_set))
{
bool close_conn = false; // 标记当前连接是否断开了
for (int fd = 0; fd <= max_fd; ++fd)
{
if (FD_ISSET(fd, &working_set))
{
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)
{
continue;
}
else
{
if (size_get <= 0)
{
continue;
}
else
{
bool isHeart_beat = (std::string(order_str) == "matrixai");
if (isHeart_beat)
{
mmap[fd].second = 0; // 每次收到心跳包count置0
//LogDebug << "Scoket_Server Received heart-beat from client.";
}
else
{
LogInfo << "Received message from client:" << std::string(order_str);
}
}
bool isHeart_beat = (std::string(order_str) == "matrixai");
if (isHeart_beat)
{
mmap[fd].second = 0; // 每次收到心跳包count置0
//LogDebug << "Scoket_Server Received heart-beat from client.";
}
else
{
LogInfo << "Received message from client:" << std::string(order_str);
}
}
if (close_conn) // 当前这个连接有问题,关闭它
{
close(fd);
FD_CLR(fd, &master_set);
if (fd == max_fd) // 需要更新max_fd;
{
while (FD_ISSET(max_fd, &master_set) == false)
--max_fd;
}
}
}
}
if (close_conn) // 当前这个连接有问题,关闭它
{
close(fd);
FD_CLR(fd, &master_set);
if (fd == max_fd) // 需要更新max_fd;
{
while (FD_ISSET(max_fd, &master_set) == false)
--max_fd;
}
}
}
}
return true;
return true;
}
bool SocketEngine::Run()
{
pthread_t id; // 创建心跳检测线程
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
if (ret != 0)
{
LogError << "Scoket_Server Can not create heart-beat checking thread.";
return false;
}
pthread_t id; // 创建心跳检测线程
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
if (ret != 0)
{
LogError << "Scoket_Server Can not create heart-beat checking thread.";
return false;
}
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
if (ret != 0)
{
LogError << "Scoket_Server Can not create message send thread.";
return false;
}
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
if (ret != 0)
{
LogError << "Scoket_Server Can not create message send thread.";
return false;
}
max_fd = listen_fd; // 初始化max_fd
FD_ZERO(&master_set);
FD_SET(listen_fd, &master_set); // 添加监听fd
max_fd = listen_fd; // 初始化max_fd
FD_ZERO(&master_set);
FD_SET(listen_fd, &master_set); // 添加监听fd
while (!isStop_)
{
FD_ZERO(&working_set);
memcpy(&working_set, &master_set, sizeof(master_set));
while (!isStop_)
{
FD_ZERO(&working_set);
memcpy(&working_set, &master_set, sizeof(master_set));
timeout.tv_sec = 30;
timeout.tv_usec = 0;
timeout.tv_sec = 30;
timeout.tv_usec = 0;
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
/*if (nums < 0)
{
LogError << "Scoket_Server select() error!";
return false;
}*/
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
/*if (nums < 0)
{
LogError << "Scoket_Server select() error!";
return false;
}*/
if (nums <= 0)
{
//cout << "select() is timeout!";
continue;
}
if (nums <= 0)
{
//cout << "select() is timeout!";
continue;
}
if (FD_ISSET(listen_fd, &working_set))
Accept(); // 有新的客户端请求
else
Recv(nums); // 接收客户端的消息
if (FD_ISSET(listen_fd, &working_set))
Accept(); // 有新的客户端请求
else
Recv(nums); // 接收客户端的消息
}
}
return true;
return true;
}
//解析命令
bool SocketEngine::getOrder(const std::string &recv, Json::Value &order)
{
Json::CharReaderBuilder readerBuilder;
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
Json::CharReaderBuilder readerBuilder;
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
JSONCPP_STRING errs;
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
return false;
JSONCPP_STRING errs;
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
return false;
if (order.isArray()) {
if (order.size() > 0) order = order[0];
return true;
}
return true;
if (order.isArray()) {
if (order.size() > 0) order = order[0];
return true;
}
return true;
}
std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info)
{
Json::Value feedBack;
Json::StreamWriterBuilder strbuild;
Json::Value feedBack;
Json::StreamWriterBuilder strbuild;
feedBack["poundNo"] = poundNo;
feedBack["type"] = type;
feedBack["info"] = info;
//
return Json::writeString(strbuild, feedBack);
feedBack["poundNo"] = poundNo;
feedBack["type"] = type;
feedBack["info"] = info;
//
return Json::writeString(strbuild, feedBack);
}
void* SocketEngine::sendInfo(void* arg) {
SocketEngine* s = (SocketEngine*)arg;
while (!s->isStop_) {
//pop端口0
std::shared_ptr<void> pVoidData0 = nullptr;
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
if (nullptr == pVoidData0)
{
usleep(1000); //1ms
continue;
}
SocketEngine* s = (SocketEngine*)arg;
while (!s->isStop_) {
//pop端口0
std::shared_ptr<void> pVoidData0 = nullptr;
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
if (nullptr == pVoidData0)
{
usleep(1000); //1ms
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
void* SocketEngine::heart_handler(void* arg)
{
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
SocketEngine* s = (SocketEngine*)arg;
while (1)
{
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
for (; it != s->mmap.end(); )
{
if (it->second.second == 5) // sleep(3)*5没有收到心跳包判定客户端掉线
{
LogInfo << "The client " << it->second.first << " has be offline.\n";
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
SocketEngine* s = (SocketEngine*)arg;
while (1)
{
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
for (; it != s->mmap.end(); )
{
if (it->second.second == 5) // sleep(3)*5没有收到心跳包判定客户端掉线
{
LogInfo << "The client " << it->second.first << " has be offline.\n";
int fd = it->first;
close(fd); // 关闭该连接
FD_CLR(fd, &s->master_set);
if (fd == s->max_fd) // 需要更新max_fd;
{
while (FD_ISSET(s->max_fd, &s->master_set) == false)
s->max_fd--;
}
int fd = it->first;
close(fd); // 关闭该连接
FD_CLR(fd, &s->master_set);
if (fd == s->max_fd) // 需要更新max_fd;
{
while (FD_ISSET(s->max_fd, &s->master_set) == false)
s->max_fd--;
}
s->mmap.erase(it++); // 从map中移除该记录
}
else if (it->second.second < 5 && it->second.second >= 0)
{
it->second.second += 1;
++it;
}
else
{
++it;
}
}
sleep(3); // 定时三秒
}
s->mmap.erase(it++); // 从map中移除该记录
}
else if (it->second.second < 5 && it->second.second >= 0)
{
it->second.second += 1;
++it;
}
else
{
++it;
}
}
sleep(1); // 定时三秒
}
}
bool SocketEngine::SendClient(std::map<int, std::pair<std::string, int> > mmap, const std::string ip, const std::string message) {
try
{
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
for (; it != mmap.end(); ++it)
{
if (it->second.first == ip) // 遍历找雷达ip
{
int fd = it->first;
try
{
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
for (; it != mmap.end(); ++it)
{
if (it->second.first == ip) // 遍历找雷达ip
{
int fd = it->first;
if (send(fd, message.c_str(), message.size(), 0) <= 0)
{
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
return false;
}
else
{
char clientFeedBack[256] = { 0 };
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
{
Json::Value feedBack;
if (send(fd, message.c_str(), message.size(), 0) <= 0)
{
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
return false;
}
else
{
char clientFeedBack[256] = { 0 };
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
{
Json::Value feedBack;
if (!getOrder(clientFeedBack, feedBack)) {
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
return false;
}
if (!getOrder(clientFeedBack, feedBack)) {
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
return false;
}
if (feedBack.get("success", "").asString() == "true")
{
return true;
}
else
{
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
return false;
}
}
else {
if (feedBack.get("success", "").asString() == "true")
{
return true;
}
else
{
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
return false;
}
}
else {
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
return false;
}
}
}
}
}
catch (const std::exception&)
{
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
return false;
}
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
return false;
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
return false;
}
}
}
}
}
catch (const std::exception&)
{
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
return false;
}
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
return false;
}
bool SocketEngine::SendAllClient(std::map<int, std::pair<std::string, int> > mmap, const std::string message) {
try
{
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
for (; it != mmap.end(); ++it)
{
int fd = it->first;
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
{
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
return false;
}
else
{
// char clientFeedBack[256] = { 0 };
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
// {
// Json::Value feedBack;
try
{
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
for (; it != mmap.end(); ++it)
{
int fd = it->first;
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
{
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
return false;
}
else
{
// char clientFeedBack[256] = { 0 };
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
// {
// Json::Value feedBack;
// if (!getOrder(clientFeedBack, feedBack)) {
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
// return false;
// }
// if (!getOrder(clientFeedBack, feedBack)) {
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
// return false;
// }
// if (feedBack.get("success", "").asString() == "true")
// {
// return true;
// }
// else
// {
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
// return false;
// }
// }
// else {
// if (feedBack.get("success", "").asString() == "true")
// {
// return true;
// }
// else
// {
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
// return false;
// }
// }
// else {
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
// return false;
// }
}
}
}
catch (const std::exception&)
{
LogError << "Socker Server send message to all client failed, message:" << message;
return false;
}
return false;
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
// return false;
// }
}
}
}
catch (const std::exception&)
{
LogError << "Socker Server send message to all client failed, message:" << message;
return false;
}
return false;
}
std::string SocketEngine::HexToStr(const std::string &str)
{
std::string hex = str;
long len = hex.length();
std::string newString;
for (long i = 0; i < len; i += 2)
{
std::string byte = hex.substr(i, 2);
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
newString.push_back(chr);
}
return newString;
std::string hex = str;
long len = hex.length();
std::string newString;
for (long i = 0; i < len; i += 2)
{
std::string byte = hex.substr(i, 2);
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
newString.push_back(chr);
}
return newString;
}
std::string SocketEngine::StrToHex(const std::string &str)
{
unsigned char c;
char buf[2];
std::string result = "";
std::stringstream ss;
ss << str;
while (ss.read((char*)(&c), sizeof(c)))
{
sprintf(buf, "%02x", c);
result += buf;
}
return result;
unsigned char c;
char buf[2];
std::string result = "";
std::stringstream ss;
ss << str;
while (ss.read((char*)(&c), sizeof(c)))
{
sprintf(buf, "%02x", c);
result += buf;
}
return result;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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));
}
//通知第一步开始识别
// LogInfo << "【来车检测】" << pMoveData->iFrameId << " isEnd:" << pProcessData->bIsEnd;
//通知第一步开始识别
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 ? "无车"));
switch (nType) {
case 0:
LogDebug << "来车状态:有车头";
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车头";
break;
case 1:
LogDebug << "来车状态:无车";
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:无车";
break;
case 2:
LogDebug << "来车状态:车尾";
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:车尾";
break;
case 3:
LogDebug << "来车状态:有车";
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车";
break;
}

View File

@ -194,9 +194,9 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
std::vector<stDetection> vecSpaceInfo;
for (auto it = vecRet.begin(); it != vecRet.end();)
{
LogDebug << "frameId:" << pProcessData->iFrameId
<< " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
<< " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
// LogDebug << "frameId:" << pProcessData->iFrameId
// << " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
// << " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
// 根据配置文件中 设置的识别范围,过滤掉无效数据
if (!(it->bbox[0] >= dataSourceCfg.fIdentifyAreasLTX &&
it->bbox[1] >= dataSourceCfg.fIdentifyAreasLTY &&
@ -322,6 +322,22 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
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)
{
@ -484,10 +500,10 @@ APP_ERROR TrainStepOneEngine::Process()
SetTargetType(postSubData);
pPostData->vecPostSubData.emplace_back(postSubData);
// LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
// << " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
// << " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
// << " clear:" << singledata.fClear;
LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
<< " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
<< " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
<< " clear:" << singledata.fClear;
}
}
}

File diff suppressed because one or more lines are too long