Compare commits

...

3 Commits
main ... Test

Author SHA1 Message Date
Mr.V 57b5178413 1、优化识别切分效果,增加报警信息 2024-08-12 09:44:49 +08:00
Mr.V f18e10f8f3 1、优化识别切分效果,增加报警信息 2024-08-12 09:41:48 +08:00
Mr.V d72bd78b59 1、识别结果增加车厢开始结束时间
2、来车检测后,对来车状态改为存储在txt中,模型推理时读取来判定帧所对应的车厢状态
2024-06-19 13:57:23 +08:00
30 changed files with 581 additions and 6992 deletions

File diff suppressed because one or more lines are too long

BIN
app/train

Binary file not shown.

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

@ -459,7 +459,7 @@ 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; //当前大框所属车厢
@ -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; //列车结束标识
@ -516,6 +516,7 @@ typedef struct
uint64_t i64TimeStamp = 0; //帧数据时间戳
std::shared_ptr<DecodedData> pDecodeData = nullptr;
int iDirection = 0; //行驶方向(0-未知; 1-向左; 2-向右)
int nMonitorState = MONITOR_MODEL_INIT_STATE;
} SaveImgData;
//识别处理数据
@ -755,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; //原图上大框坐标
@ -831,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;
@ -865,19 +866,19 @@ 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; //帧率
@ -894,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)

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

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,7 +58,7 @@ private:
int iChkStopPX_;
int iChkStopCount_;
int iDirection_; //方向
int iPushDirection_; //需要识别的方向
int iPushDirection_; //需要识别的方向
int rightFirst_; // 向右行驶的在前大框类型
int leftFirst_; // 向左行驶的在前大框类型
int iPartitionFrameNum_; //满足跨车厢的帧间隔

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() {}
@ -113,6 +129,8 @@ void MergerAllEngine::PushData(std::shared_ptr<Train> pTrain)
<< "集装箱2: " << pTrain->container2.strContainerNo << "\n"
<< "集装箱2图片: " << pTrain->container2.strBestImg << "\n"
<< "集装箱2时间戳: " << pTrain->container2.i64TimeStamp << "\n"
<< "车厢开始时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64StartTimeStamp, true) << "\n"
<< "车厢结束时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true) << "\n"
<< " ---所有信息合并结果 END--- ";
if (pTrain->bIsEnd)
{
@ -249,7 +267,7 @@ APP_ERROR MergerAllEngine::Process()
}
int iHaveDataCnt = QueueHaveDataCount();
//识别目标信息个数和获取信息个数相等则合并信息推送web
//识别目标信息个数和获取信息个数相等则合并信息推送web
if (iHaveDataCnt == iPopPortCnt_)
{
std::shared_ptr<Train> pTrain = nullptr;
@ -310,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

@ -47,8 +47,8 @@ APP_ERROR SaveImgEngine::Process()
}
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;
@ -154,6 +154,7 @@ APP_ERROR SaveImgEngine::Process()
Json::Value jvFrameInfo;
jvFrameInfo["timeStamp"] = pSaveImgData->i64TimeStamp;
jvFrameInfo["status"] = iStatus;
jvFrameInfo["moveType"] = pSaveImgData->nMonitorState;
jvFrameInfo["direction"] = pSaveImgData->iDirection;
jvFrameInfo["width"] = iWidth;
jvFrameInfo["height"] = iHeight;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,279 +1,279 @@
#include "SocketEngine.h"
#include "SocketEngine.h"
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

@ -4,50 +4,50 @@ using namespace std;
HardH264FFmpegDecode::HardH264FFmpegDecode()
{
;
;
}
HardH264FFmpegDecode::~HardH264FFmpegDecode()
{
;
;
}
int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate)
{
uiWidth_ = uiWidth; uiHeight_ = uiHeight;
uiFrameRate_ = uiFrameRate;
iFrameFinished_ = 0;
uiWidth_ = uiWidth; uiHeight_ = uiHeight;
uiFrameRate_ = uiFrameRate;
iFrameFinished_ = 0;
av_log_set_level(AV_LOG_ERROR);
av_log_set_level(AV_LOG_ERROR);
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
if (!pCodec_) {
fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
exit(1);
}
printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
//创建上下文
//创建上下文
pCodecCtx_ = avcodec_alloc_context3(pCodec_);
if (!pCodecCtx_){
fprintf(stderr, "Could not allocate video codec context\n");
exit(1);
}
//创建解析器
pCodecParserCtx_ = av_parser_init(pCodec_->id);
if (!pCodecParserCtx_){
//创建解析器
pCodecParserCtx_ = av_parser_init(pCodec_->id);
if (!pCodecParserCtx_){
fprintf(stderr, "parser not found\n");
exit(1);
}
}
//if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
// pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
//打开解码器
//打开解码器
int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
if (ret < 0) {
fprintf(stderr, "Could not open codec\n");
@ -63,7 +63,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
}
// av_init_packet(pPacket_);
//分配frame
//分配frame
pSrcFrame_ = av_frame_alloc();
if (!pSrcFrame_) {
fprintf(stderr, "Could not allocate video src pFrame\n");
@ -78,14 +78,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
printf("after align down video_width: %d, video_height: %d\n", uiWidth_, uiHeight_);
//初始化解析器参数
pCodecCtx_->time_base.num = 1;
pCodecCtx_->frame_number = 1; //每包一个视频帧
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
pCodecCtx_->bit_rate = 0;
pCodecCtx_->time_base.den = uiFrameRate_;//帧率
pCodecCtx_->width = uiWidth_; //视频宽
pCodecCtx_->height = uiHeight_; //视频高
//初始化解析器参数
pCodecCtx_->time_base.num = 1;
pCodecCtx_->frame_number = 1; //每包一个视频帧
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
pCodecCtx_->bit_rate = 0;
pCodecCtx_->time_base.den = uiFrameRate_;//帧率
pCodecCtx_->width = uiWidth_; //视频宽
pCodecCtx_->height = uiHeight_; //视频高
// pCodecCtx_->pix_fmt = AV_PIX_FMT_YUV420P;
int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P,
@ -102,46 +102,46 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
printf("pDstFrame_->linesize: %d, bufferSize: %d\n", pDstFrame_->linesize, bufferSize);
pSwsContext_ = sws_getContext(pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt,
pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
printf("pCodecCtx_->width: %d, pCodecCtx_->height: %d, pCodecCtx_->pix_fmt: %d\n", pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt);
return 0;
return 0;
}
int HardH264FFmpegDecode::HardH264FFmpegDecoderDeInit()
{
if(pu8OutBuffer_){
if(pu8OutBuffer_){
av_free(pu8OutBuffer_);
pu8OutBuffer_ = nullptr;
}
if(pSrcFrame_){
av_frame_free(&pSrcFrame_);
pSrcFrame_ = nullptr;
}
if(pDstFrame_){
av_frame_free(&pDstFrame_);
pDstFrame_ = nullptr;
}
if(pPacket_){
if(pSrcFrame_){
av_frame_free(&pSrcFrame_);
pSrcFrame_ = nullptr;
}
if(pDstFrame_){
av_frame_free(&pDstFrame_);
pDstFrame_ = nullptr;
}
if(pPacket_){
av_packet_free(&pPacket_);
pPacket_ = nullptr;
}
if(pCodecParserCtx_){
av_parser_close(pCodecParserCtx_);
pCodecParserCtx_ = nullptr;
}
if(pCodecCtx_){
avcodec_close(pCodecCtx_);
av_free(pCodecCtx_);
pCodecCtx_ = nullptr;
}
if(pCodecParserCtx_){
av_parser_close(pCodecParserCtx_);
pCodecParserCtx_ = nullptr;
}
if(pCodecCtx_){
avcodec_close(pCodecCtx_);
av_free(pCodecCtx_);
pCodecCtx_ = nullptr;
}
if(pSwsContext_){
sws_freeContext(pSwsContext_);
pSwsContext_ = nullptr;
}
if(pSwsContext_){
sws_freeContext(pSwsContext_);
pSwsContext_ = nullptr;
}
}
int HardH264FFmpegDecode::HardH264FFmpegDecoderFilterGraph(AVFilterGraph *pGraph, AVFilterContext *pSourceCtx, AVFilterContext *pSinkCtx)
@ -149,7 +149,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderFilterGraph(AVFilterGraph *pGraph
int ret;
AVFilterInOut *pOutputs = nullptr, *pInputs = nullptr;
if ((ret = avfilter_link(pSourceCtx, 0, pSinkCtx, 0)) >= 0){
ret = avfilter_graph_config(pGraph, nullptr);
ret = avfilter_graph_config(pGraph, nullptr);
}
avfilter_inout_free(&pOutputs);
@ -168,14 +168,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGra
"video_size=%dx%d:pix_fmt=%d:time_base=1/1200000",
iWidth, iHeight, iFormat);
if ((ret = avfilter_graph_create_filter(&pFiltSrc,
avfilter_get_by_name("buffer"), "ffplay_buffer", BufferSrcArgs,
nullptr, pGraph)) < 0){
avfilter_get_by_name("buffer"), "ffplay_buffer", BufferSrcArgs,
nullptr, pGraph)) < 0){
goto fail;
}
ret = avfilter_graph_create_filter(&pFiltDst,
avfilter_get_by_name("buffersink"),
"ffplay_buffersink", nullptr, nullptr, pGraph);
avfilter_get_by_name("buffersink"),
"ffplay_buffersink", nullptr, nullptr, pGraph);
if (ret < 0){
goto fail;
}
@ -190,14 +190,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGra
pDecoderFilterIn = pFiltSrc;
pDecoderFilterOut = pFiltDst;
fail:
fail:
return ret;
}
int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame *pFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize)
{
int ret;
AVFilterGraph* pDecoderGraph = nullptr;
int ret;
AVFilterGraph* pDecoderGraph = nullptr;
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
if (ret < 0) {
@ -208,7 +208,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
while (ret >= 0) {
ret = avcodec_receive_frame(pDecCtx, pFrame); //解码
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
fprintf(stderr, "During decoding eof\n");
fprintf(stderr, "During decoding eof\n");
return -1;
}
else if (ret < 0) {
@ -219,7 +219,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
//printf("saving frame %3d\n", pDecCtx->frame_number);
fflush(stdout);
AVFilterContext *pDecoderFilterIn = nullptr, *pDecoderFilterOut = nullptr;
AVFilterContext *pDecoderFilterIn = nullptr, *pDecoderFilterOut = nullptr;
// pFrame->width = ALIGN_DOWN(pFrame->width, 32);
// pFrame->height = ALIGN_DOWN(pFrame->height, 32);
@ -228,26 +228,26 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
pDecoderGraph = avfilter_graph_alloc();
HardH264FFmpegDecoderConfigureVideoFilters(pDecoderGraph, pDecoderFilterIn, pDecoderFilterOut, pFrame->width, pFrame->height, pFrame->format);
if (pFrame->format != AV_PIX_FMT_YUV420P){
if (pFrame->format != AV_PIX_FMT_YUV420P){
DUMP_FRAME(pFrame);
ret = av_buffersrc_add_frame(pDecoderFilterIn, pFrame);
ret = av_buffersrc_add_frame(pDecoderFilterIn, pFrame);
ret = av_buffersink_get_frame_flags(pDecoderFilterOut, pFrame, 0);
DUMP_FRAME(pFrame);
int iSize = pFrame->width * pFrame->height;
memcpy(pOutputData, pFrame->data[0], iSize); //Y
memcpy(pOutputData+iSize, pFrame->data[1], iSize/4); //U
memcpy(pOutputData+iSize+iSize/4, pFrame->data[2], iSize/4); //V
*puiOutputDataSize = iSize*3/2;
return iSize*3/2;
}
}
return 0;
int iSize = pFrame->width * pFrame->height;
memcpy(pOutputData, pFrame->data[0], iSize); //Y
memcpy(pOutputData+iSize, pFrame->data[1], iSize/4); //U
memcpy(pOutputData+iSize+iSize/4, pFrame->data[2], iSize/4); //V
*puiOutputDataSize = iSize*3/2;
return iSize*3/2;
}
}
return 0;
}
int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData,unsigned int* puiOutputDataSize)
{
int ret;
int ret;
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
if (ret < 0) {
@ -258,7 +258,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
while (ret >= 0) {
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); //解码
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
fprintf(stderr, "During decoding eof\n");
fprintf(stderr, "During decoding eof\n");
return -1;
}
else if (ret < 0) {
@ -266,7 +266,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
exit(1);
}
// pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
// pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
// pDecCtx->height = ALIGN_DOWN(pDecCtx->height, 32);
sws_scale(pSwsCtx,
@ -280,13 +280,13 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
//printf("saving frame %3d\n", pDecCtx->frame_number);
fflush(stdout);
int iSize = pDecCtx->width * pDecCtx->height;
int iSize = pDecCtx->width * pDecCtx->height;
memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
*puiOutputDataSize = iSize*3/2;
return iSize*3/2;
}
return 0;
memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
*puiOutputDataSize = iSize*3/2;
return iSize*3/2;
}
return 0;
}

View File

@ -72,7 +72,7 @@ public:
const AVCodec *pCodec_ = nullptr; //解码器
AVCodecContext *pCodecCtx_ = nullptr; //上下文
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
AVFrame *pSrcFrame_ = nullptr;
AVFrame *pDstFrame_ = nullptr;
AVPacket *pPacket_ = nullptr;

File diff suppressed because one or more lines are too long

View File

@ -192,6 +192,8 @@ 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));
}
@ -211,6 +213,7 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
pSaveImgData->bIsEnd = pProcessData->bIsEnd;
pSaveImgData->bSaveToFtp = true;
pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp;
pSaveImgData->nMonitorState = nType;
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pSaveImgData));
}
@ -282,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

View File

@ -113,8 +113,8 @@ void Inference::doInference(IExecutionContext& context, cudaStream_t& stream, vo
void Inference::doInferenceV2(IExecutionContext& context, cudaStream_t& stream, void **buffers, unsigned int outputIndex, float* output, int outputSize, int batchSize)
{
context.enqueue(batchSize, buffers, stream, nullptr);
//context.enqueueV2(buffers, stream, nullptr);
// context.enqueue(batchSize, buffers, stream, nullptr);
context.enqueueV2(buffers, stream, nullptr);
CUDA_CHECK(cudaMemcpyAsync(output, buffers[outputIndex], batchSize * outputSize * sizeof(float), cudaMemcpyDeviceToHost, stream));
cudaStreamSynchronize(stream);
}