新增解码异常时解码器自动重置

This commit is contained in:
zhangwei 2025-11-13 09:42:28 +08:00
parent 3dabfe2bf6
commit 6778b5a0e9
46 changed files with 11990 additions and 4573 deletions

13
.gitignore vendored
View File

@ -1,7 +1,6 @@
/build/
/app/
*.tgz
*.tar
*.log
*.o
*.out
build/
cmake-build-debug/
cmake-build-release/
.idea/
.vscode/
app/train

View File

@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.5)
# cmake_policy(SET CMP0074 NEW)
# cmake_policy(SET CMP0146 NEW)
message("NVIDIA NX PLATFORM")
set(PROJECT_NAME train)
project(${PROJECT_NAME} VERSION 1.0)
add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
@ -85,6 +85,7 @@ include_directories(
${PROJECT_SOURCE_DIR}/ai_matrix/myqueue
${PROJECT_SOURCE_DIR}/ai_matrix/myshell
${PROJECT_SOURCE_DIR}/ai_matrix/myutils
${PROJECT_SOURCE_DIR}/ai_matrix/Http
#nvidia ascend common cann include
${PROJECT_SOURCE_DIR}/nvidia_ascend_base/Base/BlockingQueue
@ -106,11 +107,12 @@ include_directories(
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ApiEngine
#common tools rtsp_server include
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/3rdpart/md5
@ -179,17 +181,18 @@ file(GLOB_RECURSE COMMON_SRCS_LISTS
#common engine src
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ApiEngine/*.cpp
#common tools rtsp_server src
${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/*.cpp
@ -198,18 +201,6 @@ file(GLOB_RECURSE COMMON_SRCS_LISTS
file(GLOB_RECURSE SRCS_LISTS
#nvidia engine src
#nvidia engine include
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine/*.cpp
${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MyYaml/*.cpp

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM dustynv/jetson-inference:r32.6.1
#拷贝业务程序
COPY --chown=1000:1000 app /app
#WORKDIR /app/bin
WORKDIR /app
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/lib
#CMD echo "$APP_NAME version $APP_VERSION"
ENTRYPOINT ["./train"]

View File

@ -1,3 +1,3 @@
# Train_Identify
火车车号识别
4分类

246
ai_matrix/Config/Config.cpp Normal file
View File

@ -0,0 +1,246 @@
#include "Config.h"
namespace ai_matrix
{
Config *Config::pInstance_ = nullptr;
Config::GarbageCollector Config::gc_;
std::mutex Config::mx_;
Config *Config::GetIns()
{
//双层锁,确保线程安全
if (pInstance_ == nullptr)
{
std::lock_guard<std::mutex> guard(mx_); //防止异常发生不能解锁
if (pInstance_ == nullptr)
{
pInstance_ = new Config();
}
}
return pInstance_;
}
int Config::readYaml(std::string &strPath)
{
try
{
strConfigYamlPath_ = strPath;
config_ = YAML::LoadFile(strPath);
//退出程序
if (config_.IsNull())
{
printf("config.yaml no find");
return -1;
}
// 控制参数
this->baseConfig_.strTrackName = config_["base"]["track_name"].as<std::string>();
this->baseConfig_.bTestModel = config_["base"]["test_model"].as<bool>();
this->baseConfig_.iApiPort = config_["base"]["api_port"].as<int>();
this->baseConfig_.bUpResult = config_["base"]["up_result"].as<bool>();
this->baseConfig_.strLogPath = config_["base"]["log_path"].as<std::string>();
this->baseConfig_.strResultPath = config_["base"]["result_path"].as<std::string>();
this->baseConfig_.iResultSaveDays = config_["base"]["result_save_days"].as<int>();
// 日志参数
this->logConfig_.strOutLevel = config_["log"]["out_level"].as<std::string>();
this->logConfig_.strSaveLevel = config_["log"]["save_level"].as<std::string>();
// 数据源参数
this->dataSourceConfig_.strUrl = config_["data_source"]["url"].as<std::string>();
this->dataSourceConfig_.iSkipInterval = config_["data_source"]["skip_interval"].as<int>();
this->dataSourceConfig_.iDirection = config_["data_source"]["direction"].as<int>();
this->dataSourceConfig_.iLeftFirst = config_["data_source"]["left_first"].as<int>();
this->dataSourceConfig_.iRightFirst = config_["data_source"]["right_first"].as<int>();
// 识别参数
this->identifyConfig_.strRunModel = config_["identify"]["run_mode"].as<std::string>();
this->identifyConfig_.bNeedMoveDetectFlag = config_["identify"]["need_move_detect_flag"].as<bool>();
this->identifyConfig_.strIdentifyDirection = config_["identify"]["identify_direction"].as<std::string>();
this->identifyConfig_.iPartitionFrameSpan = config_["identify"]["partition_frame_span"].as<int>();
this->identifyConfig_.iSplitFrameSpanPx = config_["identify"]["split_frame_span_px"].as<int>();
this->identifyConfig_.iChkstopPx = config_["identify"]["chkstop_px"].as<int>();
this->identifyConfig_.iChkstopCount = config_["identify"]["chkstop_count"].as<int>();
this->identifyConfig_.iNumFrameHeight = config_["identify"]["num_frame_height"].as<int>();
this->identifyConfig_.iProFrameHeight = config_["identify"]["pro_frame_height"].as<int>();
this->identifyConfig_.iSpaceFrameWidth = config_["identify"]["space_frame_width"].as<int>();
this->identifyConfig_.bTrainHeardDetect = config_["identify"]["train_heard_detect"].as<bool>();
// websocket server 服务端参数
this->wSocketConfig_.bIsUse = config_["wsocket_server"]["is_use"].as<bool>();
this->wSocketConfig_.iPort = config_["wsocket_server"]["port"].as<int>();
this->wSocketConfig_.iMaxQueueLen = config_["wsocket_server"]["max_queue_len"].as<int>();
// http服务器参数
this->httpServerConfig_.bIsUse = config_["http_server"]["is_use"].as<bool>();
this->httpServerConfig_.strIp = config_["http_server"]["http_ip"].as<std::string>();
this->httpServerConfig_.iPort = config_["http_server"]["http_port"].as<int>();
this->httpServerConfig_.strTokenUrl = config_["http_server"]["token_path"].as<std::string>();
this->httpServerConfig_.strUpResultUrl = config_["http_server"]["up_result_path"].as<std::string>();
this->httpServerConfig_.strUserName = config_["http_server"]["username"].as<std::string>();
this->httpServerConfig_.strPassword = config_["http_server"]["password"].as<std::string>();
}
catch (...) //捕获所有异常
{
return -1;
}
return 0;
}
int Config::writeYaml()
{
try
{
std::ofstream of(strConfigYamlPath_);
of << config_;
of.close();
}
catch (...) //捕获所有异常
{
printf("yaml文件不存在\n");
return -1;
}
return 0;
}
std::string Config::getStringValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
{
if(nullptr == pConfig)
{
pConfig = &config_;
}
if (!(*pConfig)[pszKey].IsDefined())
{
printf("key:[%s] not exist!\n", pszKey);
}
return (*pConfig)[pszKey].as<std::string>();
}
int Config::getIntValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
{
if (nullptr == pConfig)
{
pConfig = &config_;
}
if (!(*pConfig)[pszKey].IsDefined())
{
printf("key:[%s] not exist!\n", pszKey);
}
return (*pConfig)[pszKey].as<int>();
}
bool Config::getBoolValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
{
if (nullptr == pConfig)
{
pConfig = &config_;
}
if (!(*pConfig)[pszKey].IsDefined())
{
printf("key:[%s] not exist!\n", pszKey);
}
return (*pConfig)[pszKey].as<bool>();
}
float Config::getFloatValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
{
if (nullptr == pConfig)
{
pConfig = &config_;
}
if (!(*pConfig)[pszKey].IsDefined())
{
printf("key:[%s] not exist!\n", pszKey);
}
return (*pConfig)[pszKey].as<float>();
}
std::string Config::getPathValue(const char *pszKey, const YAML::Node *pConfig /*=nullptr*/) const
{
if (nullptr == pConfig)
{
pConfig = &config_;
}
if (!(*pConfig)[pszKey].IsDefined())
{
printf("key:[%s] not exist!\n", pszKey);
}
std::string strTmp = (*pConfig)[pszKey].as<std::string>();
if (strTmp.back() != '/')
{
strTmp += "/";
}
return strTmp;
}
RunConfig Config::getRunConfig() const
{
return this->runConfig_;
}
void Config::setRunConfig(const ai_matrix::RunConfig runConfig)
{
this->runConfig_ = runConfig;
}
BaseConfig Config::getBaseConfig() const
{
return this->baseConfig_;
}
void Config::setBaseConfig(const BaseConfig baseConfig)
{
this->baseConfig_ = baseConfig;
}
LogConfig Config::getLogConfig() const
{
return this->logConfig_;
}
void Config::setLogConfig(const LogConfig logConfig)
{
this->logConfig_ = logConfig;
}
DataSourceConfig Config::getDataSourceConfig() const
{
return this->dataSourceConfig_;
}
void Config::setDataSourceConfig(const ai_matrix::DataSourceConfig dataSourceConfig)
{
this->dataSourceConfig_ = dataSourceConfig;
}
IdentifyConfig Config::getIdentifyConfig() const
{
return this->identifyConfig_;
}
void Config::setIdentifyConfig(const ai_matrix::IdentifyConfig identifyConfig)
{
this->identifyConfig_ = identifyConfig;
}
WSocketConfig Config::getWSocketConfig() const
{
return this->wSocketConfig_;
}
void Config::setWSocketConfig(const ai_matrix::WSocketConfig wSocketConfig)
{
this->wSocketConfig_ = wSocketConfig;
}
HttpServerConfig Config::getHttpServerConfig() const
{
return this->httpServerConfig_;
}
void Config::setHttpServerConfig(const HttpServerConfig httpServerConfig) {
this->httpServerConfig_ = httpServerConfig;
}
}

209
ai_matrix/Config/Config.h Normal file
View File

@ -0,0 +1,209 @@
#ifndef MYYAML_H_
#define MYYAML_H_
#include <mutex>
#include <fstream>
#include "yaml-cpp/yaml.h"
#include "Log.h"
namespace ai_matrix
{
struct RunConfig
{
// 识别状态
bool bRun;
};
// 基础控制参数
struct BaseConfig
{
// 股道名称
std::string strTrackName;
// 测试模式
bool bTestModel;
// Api 监听端口
int iApiPort;
// 是否上传识别结果
bool bUpResult;
// 日志文件目录
std::string strLogPath;
// 识别结果目录
std::string strResultPath;
// 调试结果目录
std::string strDebugResultPath;
// 日志存储天数
int iResultSaveDays;
// 过期文件夹天数
int iDayForResultExpire;
};
// 日志参数
struct LogConfig {
// 输出日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
std::string strOutLevel;
// 保存日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
std::string strSaveLevel;
};
// 数据源参数
struct DataSourceConfig {
// 数据源地址
std::string strUrl;
// 跳帧数
int iSkipInterval;
// 行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应)
int iDirection;
// 0-向左编号在前 1-向左属性在前 (向右行驶的情况2-向右编号在前 3-向右属性在前)
int iLeftFirst;
// (向左行驶的情况0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前
int iRightFirst;
};
// 识别参数
struct IdentifyConfig {
// 运行方式
std::string strRunModel;
// 是否开启动态检测
bool bNeedMoveDetectFlag;
// 识别方向 [LEFT,RIGHT,ALL]
std::string strIdentifyDirection;
// 大框帧跨度(比一个大框从出现到消失的跨度稍大一点, 跟跳帧有关系)
int iPartitionFrameSpan;
// 大框帧跨度的位置像素差异
int iSplitFrameSpanPx;
// 每帧大框位置差异最小值 (持续小于此值,则可能停车)
int iChkstopPx;
// 持续X次续位置差异小于gc_chkstop_px则判断为停车。
int iChkstopCount;
// 过滤最小大框高度(不需要的话就写个很小的值)
int iNumFrameHeight;
int iProFrameHeight;
// 过滤最大框宽度(不需要的话就写个很大的值)
int iSpaceFrameWidth;
// 是否识别车头
bool bTrainHeardDetect;
};
// websocket_server 的服务端参数
struct WSocketConfig {
// 是否启用
bool bIsUse;
// 端口
int iPort;
// 最大链接队列
int iMaxQueueLen;
};
// web服务器参数
struct HttpServerConfig
{
// 使用状态
bool bIsUse;
// 获取接口授权地址
std::string strIp;
// 通讯端口
int iPort;
// 获取接口授权地址
std::string strTokenUrl;
// 识别结果上传地址
std::string strUpResultUrl;
// 接口用户名
std::string strUserName;
// 接口密码
std::string strPassword;
};
class Config final
{
public:
static Config *GetIns();
// 读yaml文件
int readYaml(std::string &strPath);
// 写yaml文件
int writeYaml();
std::string getStringValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
int getIntValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
bool getBoolValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
float getFloatValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
std::string getPathValue(const char *pszKey, const YAML::Node *pConfig =nullptr) const;
RunConfig getRunConfig() const;
void setRunConfig(const RunConfig runConfig);
// 获取控制参数
BaseConfig getBaseConfig() const;
void setBaseConfig(const BaseConfig baseConfig);
// 获取日志参数
LogConfig getLogConfig() const;
void setLogConfig(const LogConfig logConfig);
// 获取数据源参数
DataSourceConfig getDataSourceConfig() const;
void setDataSourceConfig(const DataSourceConfig dataSourceConfig);
// 获取识别参数
IdentifyConfig getIdentifyConfig() const;
void setIdentifyConfig(const IdentifyConfig identifyConfig);
// 获取websocket server 参数
WSocketConfig getWSocketConfig() const;
void setWSocketConfig(const WSocketConfig wSocketConfig);
// 获取web服务器参数
HttpServerConfig getHttpServerConfig() const;
void setHttpServerConfig(const HttpServerConfig httpServerConfig);
YAML::Node config_;
private:
Config() = default;
Config(const Config &) = delete;
Config(Config &&) = delete;
Config &operator=(const Config &) = delete;
Config &operator=(Config &&) = delete;
~Config() = default;
static Config *pInstance_;
static std::mutex mx_; //锁,保证线程安全
std::string strConfigYamlPath_;
// (全局)运行实时变量
RunConfig runConfig_;
// 控制参数
BaseConfig baseConfig_;
// 日志参数
LogConfig logConfig_;
// 数据源参数
DataSourceConfig dataSourceConfig_;
// 识别参数
IdentifyConfig identifyConfig_;
// websocket server 服务端参数
WSocketConfig wSocketConfig_;
// web服务器参数
HttpServerConfig httpServerConfig_;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (Config::pInstance_)
{
delete Config::pInstance_;
Config::pInstance_ = nullptr;
}
}
};
static GarbageCollector gc_;
};
}
#endif

9388
ai_matrix/Http/httplib.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,190 @@
//
// Created by matrixai on 4/2/24.
//
#include "FileUtil.h"
namespace ai_matrix
{
FileUtil *FileUtil::ins = nullptr;
FileUtil::GarbageCollector FileUtil::gc;
std::mutex FileUtil::mx;
FileUtil *FileUtil::getins()
{
//双层锁,确保线程安全
if (ins == nullptr)
{
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
if (ins == nullptr)
{
ins = new FileUtil();
}
}
return ins;
}
/**
*
* inParam : std::string strDirPath :
* outParam: N/A
* return : true/false
*/
bool FileUtil::CreateDirPath(std::string strDirPath)
{
if (strDirPath.back() != '/')
{
strDirPath += "/";
}
if (access(strDirPath.c_str(), F_OK) == 0)
{
return true;
}
std::string::size_type pos = strDirPath.find('/');
while (pos != std::string::npos)
{
std::string strCur = strDirPath.substr(0, pos);
if (!strCur.empty() && access(strCur.c_str(), F_OK) != 0)
{
if (mkdir(strCur.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return false;
}
if (chmod(strCur.c_str(), 0777) != 0)
{
perror("chmod fail");
}
}
pos = strDirPath.find('/', pos + 1);
}
return true;
}
std::string FileUtil::create_dir_name(std::string root, std::string name)
{
std::string dir_path = root + "/" + name;
if (access(dir_path.c_str(), F_OK) != 0)
{
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return "";
}
}
return dir_path;
}
std::string FileUtil::create_dir_date(std::string root)
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
char tmp_date[20] = {0};
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
std::string dir_path;
dir_path = root + "/" + std::string(tmp_date); //创建日期目录
if (access(dir_path.c_str(), F_OK) != 0)
{
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return "";
}
}
return dir_path;
}
std::string FileUtil::create_dir_date_name_time(std::string root, std::string name)
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
char tmp_date[20] = {0};
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
char tmp_time[20] = {0};
sprintf(tmp_time, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
std::string dir_path;
dir_path = root + "/" + std::string(tmp_date); //创建日期目录
if (access(dir_path.c_str(), F_OK) != 0)
{
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return "";
}
}
dir_path = dir_path + "/" + name + "_" + std::string(tmp_time); //创建点云目录
if (access(dir_path.c_str(), F_OK) != 0)
{
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return "";
}
}
return dir_path;
}
std::string FileUtil::create_file_path(std::string root, std::string name, std::string suffix)
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
char tmp_date[20] = {0};
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
char tmp_time[20] = {0};
sprintf(tmp_time, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
std::string file_path;
file_path = root + "/" + std::string(tmp_date); //创建日期目录
if (access(file_path.c_str(), F_OK) != 0)
{
if (mkdir(file_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
{
perror("mkdir fail");
return "";
}
}
file_path = file_path + "/" + name + "_" + std::string(tmp_time) + suffix; //创建文件
return file_path;
}
/**
*
* @param filePath
* @param savePath
* @return
*/
bool FileUtil::copyFile(std::string filePath, std::string savePath) {
FILE *fp, *sp;
fp = fopen(filePath.c_str(), "rb");
sp = fopen(savePath.c_str(), "w+b");
if (!fp) {
return false;
}
void *buffer;
while (!feof(fp)) {
fread(&buffer, 1, 1, fp);
fwrite(&buffer, 1, 1, sp);
}
fclose(fp);
fclose(sp);
return true;
}
}

View File

@ -0,0 +1,78 @@
//
// Created by matrixai on 4/2/24.
//
#ifndef TRAIN_RFID_LINUX_FILEUTIL_H
#define TRAIN_RFID_LINUX_FILEUTIL_H
#include <string>
#include <mutex>
#include <fstream>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <memory>
namespace ai_matrix
{
class FileUtil final
{
public:
static FileUtil *getins();
//创建文件夹
std::string create_dir_name(std::string root, std::string name);
std::string create_dir_date_name_time(std::string root, std::string name);
std::string create_dir_date(std::string root);
//创建文件路径
std::string create_file_path(std::string root, std::string name, std::string suffix);
//创建文件夹路径
bool CreateDirPath(std::string strDirPath);
/**
*
* @param filePath
* @param savePath
* @return
*/
bool copyFile(std::string filePath, std::string savePath);
private:
FileUtil() = default;
FileUtil(const FileUtil &) = delete;
FileUtil(FileUtil &&) = delete;
FileUtil &operator=(const FileUtil &) = delete;
FileUtil &operator=(FileUtil &&) = delete;
~FileUtil() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (FileUtil::ins)
{
delete FileUtil::ins;
FileUtil::ins = nullptr;
}
}
};
static GarbageCollector gc;
static FileUtil *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif //TRAIN_RFID_LINUX_FILEUTIL_H

View File

@ -0,0 +1,171 @@
//
// Created by matrixai on 4/2/24.
//
#include "StringUtil.h"
namespace ai_matrix
{
StringUtil *StringUtil::ins = nullptr;
StringUtil::GarbageCollector StringUtil::gc;
std::mutex StringUtil::mx;
StringUtil *StringUtil::getins()
{
//双层锁,确保线程安全
if (ins == nullptr)
{
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
if (ins == nullptr)
{
ins = new StringUtil();
}
}
return ins;
}
/**
*
* @param str
* @param pattern
* @return vector<std::string>
*/
std::vector<std::string> StringUtil::split(std::string str, std::string pattern)
{
std::string::size_type pos;
std::vector<std::string> result;
str += pattern; //扩展字符串以方便操作
int size = str.size();
for (int i = 0; i < size; i++)
{
pos = str.find(pattern, i);
if (pos < size)
{
std::string s = str.substr(i, pos - i);
result.push_back(s);
i = pos + pattern.size() - 1;
}
}
return result;
}
/**
*
* @param str
* @return
*/
std::string StringUtil::trim(const std::string& str) {
std::string temp = str;
temp.erase(0, temp.find_first_not_of(" \t\n\r\f\v")); // 去除开头的空格
temp.erase(temp.find_last_not_of(" \t\n\r\f\v") + 1); // 去除末尾的空格
return temp;
}
/**
*
* @param str
* @param old_value
* @param new_value
* @return
*/
std::string& StringUtil::replace_all_distinct(std::string &str, const std::string &old_value, const std::string &new_value)
{
for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) {
if ((pos = str.find(old_value, pos)) != std::string::npos)
str.replace(pos, old_value.length(), new_value);
else break;
}
return str;
}
/**
* Anchor行分割
* inParam : std::string &strLine Anchor一行内容
* : const std::set<char> &setDelimiters
* outParam: N/A
* return :
*/
std::vector<float> StringUtil::SplitAnchor(std::string &strLine, const std::set<char> &setDelimiters)
{
std::vector<float> result;
if (strLine.empty())
{
return result;
}
char const *pch = strLine.c_str();
char const *start = pch;
for (; *pch; ++pch)
{
if (setDelimiters.find(*pch) != setDelimiters.end())
{
if (start != pch)
{
std::string tmp(start, pch);
result.push_back(atof(tmp.c_str())); //浮点数
}
start = pch + 1;
}
}
result.push_back(atof(start)); //最后一个内容
return result;
}
/**
* float string
* @param f
* @return
*/
std::string StringUtil::getStringFromFloat(float f)
{
std::ostringstream buffer;
buffer << f;
return buffer.str();
}
/**
* bool string
* @param b
* @return
*/
std::string StringUtil::getStringFromBool(bool b)
{
std::ostringstream buffer;
buffer << b;
return buffer.str();
}
/**
* string int
* ()
* @param s
* @param b
* @return
*/
int StringUtil::string2int(const std::string s, bool &b) {
try {
b = true;
return std::stoi(this->trim(s));
} catch (...) {
b = false;
return 0;
}
}
/**
*
* @param str
* @return
*/
bool StringUtil::containsNonAlphaNum(const std::string &str) {
for (char c : str) {
if (!std::isalnum(c) && !std::isspace(c)) { // 如果不是字母或数字
return true; // 返回true表示存在非字母数字字符
}
}
return false; // 遍历完成未发现非字母数字字符返回false
}
bool StringUtil::is_digits(const std::string &str) {
return all_of(str.begin(), str.end(), ::isdigit);
}
}

View File

@ -0,0 +1,74 @@
//
// Created by matrixai on 4/2/24.
//
#ifndef TRAIN_RFID_LINUX_STRINGUTIL_H
#define TRAIN_RFID_LINUX_STRINGUTIL_H
#include <string>
#include <vector>
#include <mutex>
#include <set>
#include <sstream>
#include <bits/stdc++.h>
namespace ai_matrix
{
class StringUtil final
{
public:
static StringUtil *getins();
// 字符串分割函数
std::vector<std::string> split(std::string str, std::string pattern);
// 去掉字符串前后的空格
std::string trim(const std::string& str);
// 替换string中所有指定字符串
std::string& replace_all_distinct(std::string &str, const std::string &old_value, const std::string &new_value);
//
std::vector<float> SplitAnchor(std::string &strLine, const std::set<char> &setDelimiters);
// float 转 string
std::string getStringFromFloat(float f);
// bool 转 string
std::string getStringFromBool(bool b);
// string 转 int
int string2int(const std::string s, bool &b);
// 判断字符串中是否含有 字母和数字 之外的字符
bool containsNonAlphaNum(const std::string &str);
// 判断字符串中是否仅含有数字
// 检查函数
bool is_digits(const std::string& str);
private:
StringUtil() = default;
StringUtil(const StringUtil &) = delete;
StringUtil(StringUtil &&) = delete;
StringUtil &operator=(const StringUtil &) = delete;
StringUtil &operator=(StringUtil &&) = delete;
~StringUtil() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (StringUtil::ins)
{
delete StringUtil::ins;
StringUtil::ins = nullptr;
}
}
};
static GarbageCollector gc;
static StringUtil *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif //TRAIN_RFID_LINUX_STRINGUTIL_H

View File

@ -0,0 +1,211 @@
#include <cstring>
#include "TimeUtil.h"
namespace ai_matrix
{
const int TIME_DIFF = 28800; // 8 hour
TimeUtil *TimeUtil::ins = nullptr;
TimeUtil::GarbageCollector TimeUtil::gc;
std::mutex TimeUtil::mx;
TimeUtil *TimeUtil::getins()
{
//双层锁,确保线程安全
if (ins == nullptr)
{
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
if (ins == nullptr)
{
ins = new TimeUtil();
}
}
return ins;
}
/**
*
* @return
*/
std::string TimeUtil::get_timestamp_file()
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
struct timeval tv;
gettimeofday(&tv, NULL);
int msec = tv.tv_usec / 1000;
char tmp[30] = {0};
sprintf(tmp, "%04d-%02d-%02d-%02d-%02d-%02d-%03d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, msec);
return std::string(tmp);
}
/**
*
* @return yyyy-MM-dd hh:mm:ss.us
*/
std::string TimeUtil::getDateTime_usec()
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
struct timeval tv;
gettimeofday(&tv, NULL);
int msec = tv.tv_usec / 1000;
char tmp[30] = {0};
sprintf(tmp, "%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, msec);
return std::string(tmp);
}
/**
*
* @return : yyyy-mm-dd
*/
std::string TimeUtil::getDate()
{
struct timeval time = {0, 0};
gettimeofday(&time, nullptr);
time_t timep = time.tv_sec + TIME_DIFF;
struct tm *p = gmtime(&timep);
char szTmp[12] = {0};
sprintf(szTmp, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
return std::string(szTmp);
}
/**
*
* @return : hh:mm:ss
*/
std::string TimeUtil::getTime()
{
struct timeval time = {0, 0};
gettimeofday(&time, nullptr);
time_t timep = time.tv_sec + TIME_DIFF;
struct tm *p = gmtime(&timep);
char szTmp[10] = {0};
sprintf(szTmp, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec);
return std::string(szTmp);
}
/**
* +
* @return yyyy-MM-dd hh:mm:ss
*/
std::string TimeUtil::getDateTime()
{
struct timeval time = {0, 0};
gettimeofday(&time, nullptr);
time_t timep = time.tv_sec + TIME_DIFF;
struct tm *p = gmtime(&timep);
int msec = time.tv_usec / 1000;
char szTmp[32] = {0};
sprintf(szTmp, "%04d-%02d-%02d %02d:%02d:%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
return std::string(szTmp);
}
/**
*
* @return hh-mm-ss
*/
std::string TimeUtil::getTime_file()
{
time_t timep = time(NULL);
struct tm *p = localtime(&timep);
struct timeval tv;
gettimeofday(&tv, NULL);
int msec = tv.tv_usec / 1000;
char tmp[10] = { 0 };
sprintf(tmp, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
return std::string(tmp);
}
/**
*
* inParam : N/A
* outParam: N/A
* return :
*/
/**
* 1970()
* @param usec
* @return
*/
uint64_t TimeUtil::getCurrentTimeMillis(bool usec)
{
struct timeval tv;
gettimeofday(&tv, NULL);
if (usec)
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
else
return tv.tv_sec;
}
/**
* 1970 (YYYY-MM-DD hh-mm-ss)
* inParam : std::string &strDateTime
* outParam: N/A
* return :
*/
uint64_t TimeUtil::getParamTimeMilliSeconds(std::string &strDateTime)
{
// LogDebug << "strDateTime:" << strDateTime;
if (strDateTime.length() != 19)
{
return 0;
}
int iYear = atoi(strDateTime.substr(0, 4).c_str());
int iMon = atoi(strDateTime.substr(5, 2).c_str());
int iDay = atoi(strDateTime.substr(8, 2).c_str());
int iHour = atoi(strDateTime.substr(11, 2).c_str());
int iMin = atoi(strDateTime.substr(14, 2).c_str());
int iSec = atoi(strDateTime.substr(17, 2).c_str());
struct tm stm;
memset(&stm, 0, sizeof(stm));
stm.tm_year = iYear - 1900;
stm.tm_mon = iMon - 1;
stm.tm_mday = iDay;
stm.tm_hour = iHour;
stm.tm_min = iMin;
stm.tm_sec = iSec;
uint64_t i64Ret = (uint64_t)mktime(&stm) * 1000;
return i64Ret;
}
/**
*
* inParam : uint64_t i64MilliSeconds
* outParam: N/A
* return :
*/
std::string TimeUtil::getDateTimeByMilliSeconds(uint64_t i64MilliSeconds)
{
time_t timep = i64MilliSeconds / 1000 + TIME_DIFF;
struct tm *p = gmtime(&timep);
char szTmp[32] = {0};
sprintf(szTmp, "%04d-%02d-%02d %02d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
return std::string(szTmp);
}
}

View File

@ -0,0 +1,71 @@
#ifndef TimeUtil_H_
#define TimeUtil_H_
#include <mutex>
#include <sstream>
#include <time.h>
#include <sys/time.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <memory>
namespace ai_matrix
{
class TimeUtil final
{
public:
static TimeUtil *getins();
//获取时间戳
std::string get_timestamp_file();
std::string getDateTime_usec();
//获取日期
// std::string get_date();
//获取北京当前日期
std::string getDate();
//获取北京当前时间
std::string getTime();
// 获取当前 日期 时间
std::string getDateTime();
//获取用于文件名的时间
std::string getTime_file();
//获取当前时间距1970年的毫秒数
uint64_t getCurrentTimeMillis(bool usec = false);
//获取指定时间距1970年的毫秒数 (入参格式YYYY-MM-DD hh-mm-ss)
uint64_t getParamTimeMilliSeconds(std::string &strDateTime);
//获取指定毫秒数的对应的日期时间
std::string getDateTimeByMilliSeconds(uint64_t i64MilliSeconds);
private:
TimeUtil() = default;
TimeUtil(const TimeUtil &) = delete;
TimeUtil(TimeUtil &&) = delete;
TimeUtil &operator=(const TimeUtil &) = delete;
TimeUtil &operator=(TimeUtil &&) = delete;
~TimeUtil() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (TimeUtil::ins)
{
delete TimeUtil::ins;
TimeUtil::ins = nullptr;
}
}
};
static GarbageCollector gc;
static TimeUtil *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif

180
ai_matrix/Utils/Utils.cpp Normal file
View File

@ -0,0 +1,180 @@
//
// Created by matrixai on 4/2/24.
//
#include "Utils.h"
namespace ai_matrix
{
Utils *Utils::ins = nullptr;
Utils::GarbageCollector Utils::gc;
std::mutex Utils::mx;
Utils *Utils::getins()
{
//双层锁,确保线程安全
if (ins == nullptr)
{
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
if (ins == nullptr)
{
ins = new Utils();
}
}
return ins;
}
float Utils::getMean(const std::vector<float> &data)
{
int size = data.size();
if (size == 0)
{
return 0;
}
float sum = 0;
for (int i = 0; i < size; i++)
{
sum += data[i];
}
return sum / size;
}
float Utils::getMax(const std::vector<float> &data)
{
int size = data.size();
if (size == 0)
{
return 0;
}
float max = 0;
for (int i = 0; i < size; i++)
{
if (i == 0)
{
max = data[i];
}
else if (data[i] > max)
{
max = data[i];
}
}
return max;
}
float Utils::getMin(const std::vector<float> &data)
{
int size = data.size();
if (size == 0)
{
return 0;
}
float min = 0;
for (int i = 0; i < size; i++)
{
if (i == 0)
{
min = data[i];
}
else if (data[i] < min)
{
min = data[i];
}
}
return min;
}
float Utils::getMedian(const std::vector<float> &data)
{
if (data.size() < 2)
{
return 0;
}
std::vector<float> data_tmp;
int n = data.size();
for (int i = 0; i < n; i++)
{
data_tmp.push_back(data[i]);
}
std::sort(data_tmp.begin(), data_tmp.end(), std::less<float>());
if (n % 2 == 0)
{
return (data_tmp[n / 2] + data_tmp[n / 2 - 1]) / 2;
}
else
{
return data_tmp[(n - 1) / 2];
}
}
bool Utils::contains_vec(const std::vector<std::string> &vec, std::string x) {
return count(vec.begin(), vec.end(), x) > 0;
}
// /**
// * 读取json格式文件内容
// * inParam : std::string &strFilePath :文件路径
// * outParam: Json::Value &jvFileInfo :json格式内容
// * return : true/false
// */
// bool Utils::ReadJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath)
// {
// std::ifstream ifs(strFilePath.c_str());
// if (!ifs.is_open())
// {
//// LogWarn << "txt:" << strFilePath << " open fail";
// return false;
// }
//
// std::string strContent;
// getline(ifs, strContent);
// ifs.close();
//
// Json::CharReaderBuilder jsrBuilder;
// std::shared_ptr<Json::CharReader> reader(jsrBuilder.newCharReader());
// JSONCPP_STRING errs;
// if (!reader->parse(strContent.data(), strContent.data() + strContent.size(), &jvFileInfo, &errs))
// {
//// LogWarn << "json parse fail content:" << strContent;
// return false;
// }
// return true;
// }
//
// /**
// * json格式内容写入文件
// * inParam : Json::Value &jvFileInfo :json格式内容
// : std::string &strFilePath :文件路径
// * outParam: N/A
// * return : true/false
// */
// bool Utils::WriteJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath)
// {
// Json::StreamWriterBuilder jswBuilder;
// // 紧密型存储
// jswBuilder["indentation"] = "";
// std::string strFrameInfo = Json::writeString(jswBuilder, jvFileInfo);
//
// std::ofstream ofs(strFilePath.c_str());
// if (!ofs.is_open())
// {
// LogWarn << "txt:" << strFilePath << " open fail";
// return false;
// }
// ofs.write(strFrameInfo.c_str(), strFrameInfo.length());
// ofs.close();
// return true;
// }
}

71
ai_matrix/Utils/Utils.h Normal file
View File

@ -0,0 +1,71 @@
//
// Created by matrixai on 4/2/24.
//
#ifndef TRAIN_RFID_LINUX_UTILS_H
#define TRAIN_RFID_LINUX_UTILS_H
#include <mutex>
#include <sstream>
#include <fstream>
#include <dirent.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <memory>
#include <cstring>
namespace ai_matrix
{
class Utils final
{
public:
static Utils *getins();
//计算均值
float getMean(const std::vector<float> &data);
//计算最大值
float getMax(const std::vector<float> &data);
//计算最小值
float getMin(const std::vector<float> &data);
//计算中位数
float getMedian(const std::vector<float> &data);
bool contains_vec(const std::vector<std::string> &vec, std::string x);
// //读取json格式文件内容
// bool ReadJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
// //json格式内容写入文件
// bool WriteJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
private:
Utils() = default;
Utils(const Utils &) = delete;
Utils(Utils &&) = delete;
Utils &operator=(const Utils &) = delete;
Utils &operator=(Utils &&) = delete;
~Utils() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (Utils::ins)
{
delete Utils::ins;
Utils::ins = nullptr;
}
}
};
static GarbageCollector gc;
static Utils *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif //TRAIN_RFID_LINUX_UTILS_H

View File

@ -104,11 +104,10 @@ namespace ai_matrix
//检查是否有重复engine
std::string engine_unique = engine_name + "_" + std::to_string(engine_id);
// printf(engine_unique.c_str());
printf(engine_unique.c_str());
auto iter = engine_map_.find(engine_unique);
if (iter != engine_map_.end())
{
LogWarn << "重复engine " << engine_unique;
continue;
}

View File

@ -55,6 +55,7 @@ namespace ai_matrix
std::string get_date();
//获取时间
std::string get_time();
//时间戳转化为时间 毫秒级
std::string Stamp2Time(long long timestamp, bool has_msec = false);

View File

@ -1,26 +1,19 @@
#acl参数
stop_delay_count: 64
stop_by_vari: 0
gc_acl_path: ./config/acl.json
gc_init_deviceid: "ALL" #例: 0; 0,1; 2,3; ALL
method_setting: ./modeltest/model
gc_init_deviceid: "ALL" #例: 0; 0,1; 2,3; ALL
#识别数据来源参数配置
gc_data_source: "camera" #[camera, images]
camera:
camera_0:
#url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream"
# url: "./videos/km70.mp4"
url: "./vedio/buertai2.mp4"
skipInterval: 3
target: "NUM"
use: true
direction: 0 #行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应)
left_first: 0 # 0-向左编号在前 1-向左属性在前 (向右行驶的情况2-向右编号在前 3-向右属性在前)
right_first: 3 # (向左行驶的情况0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前
identify_areas: "120, 0, 1800, 1080" #(ltx,lty,rbx,rby)
classid_minheight: "1:90, 2:120, 3:120, 9:240, 10:240, 18:120" #大框的最小高度(为屏蔽远股道识别到的信息)
#url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream"
# url: "./videos/km70.mp4"
url: "./videos/06-29_96.mp4"
skipInterval: 3
target: "NUM"
use: true
direction: 0 #行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应)
left_first: 0 # 0-向左编号在前 1-向左属性在前 (向右行驶的情况2-向右编号在前 3-向右属性在前)
right_first: 3 # (向左行驶的情况0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前
identify_areas: "120, 0, 1800, 1080" #(ltx,lty,rbx,rby)
classid_minheight: "1:90, 2:120, 3:120, 9:240, 10:240, 18:120" #大框的最小高度(为屏蔽远股道识别到的信息)
images:
images_0:
url: "./images"
@ -119,6 +112,8 @@ gc_http_open: 0
# 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/"
username: ""
password: ""
gc_http_url: "http://192.168.2.121:8081"
gc_gettoken_url: "http://192.168.0.121:20004/api/blade-auth/oauth/token"
gc_image_srv: "http://192.168.0.121:9010/"
@ -159,7 +154,7 @@ gc_mysql_passwd: "123456"
gc_mysql_db: "test1"
gc_mysql_port: "http://192.168.2.115:9000"
gc_push_direction: 1 #(1:识别向左行驶的列车2:识别向右行驶的列车0:识别双方向。 注如果方向不对服务器会正常识别只是不推送给web)
gc_push_direction: 2 #(1:识别向左行驶的列车2:识别向右行驶的列车0:识别双方向。 注如果方向不对服务器会正常识别只是不推送给web)
gc_space_minrbx_imgpercent: 0 #间隔框最低点不应小于画面某个高度值(该值为画面百分比) [主要为屏蔽远股道间隔框若不需要屏蔽则配置为0]

165
config.yaml.bak Normal file
View File

@ -0,0 +1,165 @@
init_deviceid: "ALL" #例: 0; 0,1; 2,3; ALL
# 基础控制参数
base:
# 股道名称
track_name: "1"
# 测试模式
test_model: false
# Api 监听端口
api_port: 7070
# 是否上传识别结果
up_result: false
# 是否启用socket-server
use_socket_server: false
# 日志文件目录
log_path: "./logs"
# 识别结果目录
result_path: "./result"
# 调试结果目录
debug_result_path: "./debug_result"
# 最优识别目录
best_result_path: "./best_result"
# 结果存储天数
result_save_days: 2
# 日志参数
log:
# 输出日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
out_level: "DEBUG"
# 保存日志级别
save_level: "DEBUG"
#识别数据来源参数配置
data_source:
#url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream"
url: "./vedio/buertai2.mp4"
# 跳帧数
skip_interval: 3
# 识别目标
target: "NUM"
# 行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应)
direction: 0
# 0-向左编号在前 1-向左属性在前 (向右行驶的情况2-向右编号在前 3-向右属性在前)
left_first: 0
# (向左行驶的情况0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前
right_first: 3
# (ltx,lty,rbx,rby)
identify_areas: "120, 0, 1800, 1080"
# 大框的最小高度(为屏蔽远股道识别到的信息)
classid_minheight: "1:90, 2:120, 3:120, 9:240, 10:240, 18:120"
# 识别参数
identify:
# 硬件解码
hardware_decode: true
# 运行方式
run_mode: "always" #[always; command]
# 是否开启动态检测
need_move_detect_flag: true
# 识别方向 [LEFT,RIGHT,ALL]
identify_direction: "LEFT"
# 大框帧跨度(比一个大框从出现到消失的跨度稍大一点, 跟跳帧有关系)
partition_frame_span: 20
# 大框帧跨度的位置像素差异
split_frame_span_px: 200
# 每帧大框位置差异最小值 (持续小于此值,则可能停车)
chkstop_px: 15
# 持续X次续位置差异小于chkstop_px则判断为停车。
chkstop_count: 10
# 过滤最小大框高度(不需要的话就写个很小的值)
num_frame_height: 150
pro_frame_height: 120
# 过滤最大框宽度(不需要的话就写个很大的值)
space_frame_width: 500
# 是否识别车头
train_heard_detect: true
# 选优 0-频率优先 1-长度优先
select_best_mode: 0
# 保存图片质量1~100 越高越清晰)
save_pic_quality: 50
#是否实时推流-用于直播
#gc_push_actual_flag: false
# 模型参数
model:
# 来车检测
MoveEngine:
path: "./model/step0/step0.engine"
model_info_path: "./model/step0/move_modelinfo.txt"
score_threshold: 0.9
nms_threshold: 0.3
# 关键区域识别
TrainStepOneEngine:
path: "./model/step1/step1.engine"
model_info_path: "./model/step1/train_step1_modelinfo.txt"
score_threshold: 0.6
nms_threshold: 0.3
# 字符识别
TrainStepTwoEngine:
path: "./model/step2/step2.engine"
model_info_path: "./model/step2/train_step2_modelinfo.txt"
score_threshold: 0.7
nms_threshold: 0.3
# 定检期关键区域识别
ChkDateStepOneEngine:
path: "./model/chkDate_step1/step1.engine"
model_info_path: "./model/chkDate_step1/chkdate_step1_modelinfo.txt"
score_threshold: 0.6
nms_threshold: 0.3
# 定检期字符识别
ChkDateStepTwoEngine:
path: "./model/chkDate_step2/step2.engine"
model_info_path: "./model/chkDate_step2/chkdate_step2_modelinfo.txt"
score_threshold: 0.7
nms_threshold: 0.3
# 集装箱关键区域识别
StepOneContainerEngine:
path: "./model/container_step1/con1.engine"
model_info_path: "./model/container_step1/container_step1_modelinfo.txt"
score_threshold: 0.6
nms_threshold: 0.3
# 集装箱字符识别
StepTwoContainerEngine:
path: "./model/container_step2/con2.engine"
model_info_path: "./model/container_step2/container_step2_modelinfo.txt"
score_threshold: 0.7
nms_threshold: 0.3
# http 接口
http_client:
# 服务器IP
http_ip: 192.168.2.108
# 通讯端口
http_port: 20004
# 获取接口授权地址
token_path: "/api/blade-auth/oauth/token"
# 识别结果上传地址
up_result_path: "/api/train-carriage/identification/rfid-save"
# 设备状态上传地址
device_status_url: "/api/blade-train/deviceInfo/save"
# 接口用户名
username: "guest_01"
# 接口密码
password: "d55b0f642e817eea24725d2f2a31dd08"
# 上传图片的地址
image_srv: "http://192.168.0.121:9010/"
# websocket_server 的服务端参数
wsocket_server:
port: 7071
max_queue_len: 10
#sftp用户名、密码、地址
ftp:
type: "ftp" #可选 ftp 或 sftp
ip: "192.168.2.138"
port: 21 # ftp默认21 sftp默认22
username: "nvidia"
password: "nvidia"
image_path: ""
quit_time: 10 #无上传任务延迟XXX秒断开FTP连接
gc_space_minrbx_imgpercent: 0 #间隔框最低点不应小于画面某个高度值(该值为画面百分比) [主要为屏蔽远股道间隔框若不需要屏蔽则配置为0]

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;

View File

@ -0,0 +1,97 @@
#include "ApiEngine.h"
using namespace ai_matrix;
ApiEngine::ApiEngine() {}
ApiEngine::~ApiEngine() {}
APP_ERROR ApiEngine::Init()
{
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1";
LogInfo << "engineId_:" << engineId_ << " ApiEngine Init ok";
return APP_ERR_OK;
}
APP_ERROR ApiEngine::DeInit()
{
LogInfo << "ApiEngine engineId_:" << engineId_ << " DeInit ok";
return APP_ERR_OK;
}
APP_ERROR ApiEngine::Process()
{
int iRet = APP_ERR_OK;
httplib::Server svr;
svr.Get("/hello", [](const httplib::Request& req, httplib::Response& res){
res.set_content("Hello, World!", "text/plain");
});
svr.Post("/queryDataSource", [=](const httplib::Request& req, httplib::Response& res){
std::string add_result = queryDataSource(req.body);
Json::Value response;
if (add_result.empty())
{
response["success"] = true;
response["msg"] = add_result;
}
else
{
response["success"] = false;
response["msg"] = add_result;
}
res.set_content(response.toStyledString(), "application/json");
});
LogInfo << "开启Api服务端口:" << 8080;
svr.listen("0.0.0.0", 8080);
return APP_ERR_OK;
}
/**
* 使
* @param req
* @return
*/
std::string ApiEngine::queryDataSource(const std::string &req)
{
try {
Json::CharReaderBuilder readerBuilder;
std::istringstream iss(req);
Json::Value root;
std::string errs;
bool parsingSuccessful = Json::parseFromStream(readerBuilder, iss, &root, &errs);
if (parsingSuccessful)
{
// std::shared_ptr<VTrainInfo> pTrainInfo = std::make_shared<VTrainInfo>();
// pTrainInfo->strTrackNo = root["strTrackNo"].asString();
// if (root.isMember("numCoordinate"))
MyYaml::GetIns()->GetUseDataSourceConfig();
// 转发到上传接口引擎中
// outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pTrainInfo));
// 存储到本地数据库
// outputQueMap_[strPort1_]->push(std::static_pointer_cast<void>(pTrainInfo));
}
else
{
return "接口调用参数异常所传数据非json" + req;
}
return "";
}
catch (std::exception &e)
{
return "接口调用失败!请求内容:" + req + "\n异常内容:" + std::string(e.what());
}
}

View File

@ -0,0 +1,41 @@
/**
* engine
* */
#ifndef INC_APIENGINE_H
#define INC_APIENGINE_H
#include <arpa/inet.h>
#include "AppCommon.h"
#include "EngineBase.h"
#include "EngineFactory.h"
#include "MyYaml.h"
#include "json/json.h"
#include "httplib.h"
//#define RTSP_PULL_CAMERA_VIDEO_STREAM
class ApiEngine : public ai_matrix::EngineBase
{
public:
ApiEngine();
~ApiEngine();
APP_ERROR Init() override;
APP_ERROR DeInit() override;
APP_ERROR Process() override;
protected:
private:
std::string strPort0_;
std::string strPort1_;
std::string queryDataSource(const std::string &req);
};
ENGINE_REGIST(ApiEngine)
#endif

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_; //原过车数据个数

View File

@ -407,6 +407,31 @@ int DataDealTwoEngine::GetPostData(std::shared_ptr<ProcessData> pProcessData, Js
return pPostData->vecPostSubData.size();
}
/**
* push数据到队列push
* inParam : const std::string strPort push的端口
: const std::shared_ptr<ProcessData> &pProcessData push的数据
* outParam: N/A
* return : N/A
*/
void DataDealTwoEngine::PushData(const std::string &strPort, const std::shared_ptr<ProcessData> &pProcessData)
{
while (true)
{
int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pProcessData));
if (iRet != 0)
{
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
if (iRet == 2)
{
usleep(10000); // 10ms
continue;
}
}
break;
}
}
/**
* push
* inParam : N/A
@ -490,14 +515,14 @@ void DataDealTwoEngine::MakeProcessData(std::shared_ptr<TrainRange> pTrainRange)
{
if (iPort == vecPushPorts.size() - 1)
{
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData), true);
// PushData(vecPushPorts[iPort], pProcessData);
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pProcessData), true);
PushData(vecPushPorts[iPort], pProcessData);
continue;
}
std::shared_ptr<ProcessData> pNewProcessData = std::make_shared<ProcessData>();
*pNewProcessData = *pProcessData;
iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData), true);
// PushData(vecPushPorts[iPort], pNewProcessData);
//iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast<void>(pNewProcessData), true);
PushData(vecPushPorts[iPort], pNewProcessData);
}
}
@ -593,7 +618,7 @@ APP_ERROR DataDealTwoEngine::Process()
//处理当车厢的每帧信息
MakeProcessData(pTrainRange);
// push结果汇总
iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast<void>(pTrainRange), true);
iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast<void>(pTrainRange));
iTrainIndex_++;
if (pTrainRange->bIsEnd)

View File

@ -306,10 +306,13 @@ APP_ERROR CameraEngine::Process() {
if (iRet != APP_ERR_OK) {
LogError << "engineId_:" << engineId_ << "push the h264 frame data failed...";
}
} else if (pkt.stream_index == iAudioStream_) {
//音频流不处理。
// } else if (pkt.stream_index == iAudioStream_) {
// //音频流不处理。
} else {
av_packet_unref(&pkt); //unref
LogError << "engineId_:" << engineId_ << " stream err stream_index:" << pkt.stream_index;
continue;
}
av_packet_unref(&pkt); //unref

View File

@ -220,9 +220,9 @@ bool DeviceStatusUpSerEngine::ResultToHttpSrv(Json::Value &jvRequest)
APP_ERROR DeviceStatusUpSerEngine::Process()
{
int iRet = APP_ERR_OK;
if (0 == MyYaml::GetIns()->GetIntValue("gc_device_status_open"))
if (0 == MyYaml::GetIns()->GetIntValue("gc_http_open"))
{
LogDebug << " gc_device_status_open value is 0";
LogDebug << " gc_http_open value is 0";
return APP_ERR_OK;
}

View File

@ -342,12 +342,12 @@ APP_ERROR ResultToHttpSrvEngine::Process()
usleep(1000); //1ms
//无数据大于1分钟
iNoDataCnt_++;
if (iNoDataCnt_ > (60 * 1000))
{
DealHttpFailInfo();
iNoDataCnt_ = 0;
}
// iNoDataCnt_++;
// if (iNoDataCnt_ > (60 * 1000))
// {
// DealHttpFailInfo();
// iNoDataCnt_ = 0;
// }
continue;
}
iNoDataCnt_ = 0;

View File

@ -10,6 +10,7 @@ APP_ERROR DeleteExpiredFolderEngine::Init()
{
iDaysNumber_ = MyYaml::GetIns()->GetIntValue("gc_days_for_result_expire_folder");
strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path");
strLogBakPath_ = MyYaml::GetIns()->GetPathValue("gc_log_logfile_bakpath");
LogInfo << "DeleteExpiredFolderEngine Init ok";
return APP_ERR_OK;
@ -24,13 +25,29 @@ APP_ERROR DeleteExpiredFolderEngine::DeInit()
APP_ERROR DeleteExpiredFolderEngine::Process()
{
int iRet = APP_ERR_OK;
const std::chrono::hours LOG_INTERVAL(12); // 每12小时一次
auto last_log_time = std::chrono::steady_clock::now() - LOG_INTERVAL;
while (!isStop_)
{
std::string strTrainDate_temp = MyUtils::getins()->GetDate();
try
{
auto now = std::chrono::steady_clock::now();
if (now - last_log_time < LOG_INTERVAL)
{
continue;
}
DeletePreviousFolder(strResultPath_, strTrainDate_temp, iDaysNumber_);
last_log_time = now;
std::string strTrainDate_temp = MyUtils::getins()->GetDate();
usleep(1000*1000*3600*24); //每二十四小时执行一次
DeletePreviousFolder(strResultPath_, strTrainDate_temp, iDaysNumber_);
// DeletePreviousFolder(this->baseConfig_.strResultPath, strTrainDate_temp, this->baseConfig_.iResultSaveDays + 10);
}
catch(const std::exception& e)
{
LogError << e.what();
}
}
return APP_ERR_OK;
@ -41,7 +58,7 @@ void DeleteExpiredFolderEngine::DeletePreviousFolder(std::string path, const std
// 1 computer date
std::string previous_date = getDateBeforeNDays(date, n_days);
if (!previous_date.empty())
LogDebug << "Date before " << n_days << " days from " << date << " is: " << previous_date;
std::cout << "Date before " << n_days << " days from " << date << " is: " << previous_date << std::endl;
// 2
@ -139,7 +156,7 @@ void DeleteExpiredFolderEngine::GetSubfolderNames(std::string &directory, std::v
while ((ent = readdir(dir)) != nullptr)
{
// 排除"."和".."
if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && ent->d_name != "best")
if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && strcmp(ent->d_name, "best") != 0)
{
folder_names.push_back(StrToDate(ent->d_name));
}
@ -158,9 +175,9 @@ void DeleteExpiredFolderEngine::DeleteFolder(const std::string directory)
int result = system(command.c_str());
if (result != 0)
LogError << "Failed to remove directory recursively: " << directory;
std::cout << "Failed to remove directory recursively: " << directory << std::endl;
else
LogError << "delete folder successfully : " << directory;
std::cout << "delete folder successfully : " << directory << std::endl;
}
// 删除向量中小于指定日期的所有元素
@ -184,4 +201,22 @@ void DeleteExpiredFolderEngine::DeleteEarlierDatesFolder(std::string &path, std:
DeleteFolder(path + DateToStr(cur));
}
}
}
}
// void DeleteExpiredFolderEngine::PushData(const std::string &strPort, const std::shared_ptr<ProcessData> &pSaveImgData)
// {
// while (true)
// {
// int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pSaveImgData));
// if (iRet != 0)
// {
// LogDebug << "sourceid:" << pSaveImgData->iDataSource << " frameid:" << pSaveImgData->iFrameId << " push fail iRet:" << iRet;
// if (iRet == 2)
// {
// usleep(10000); // 10ms
// continue;
// }
// }
// break;
// }
// }

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

@ -62,7 +62,7 @@ private:
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

@ -149,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);
@ -267,7 +267,7 @@ APP_ERROR MergerAllEngine::Process()
}
int iHaveDataCnt = QueueHaveDataCount();
//识别目标信息个数和获取信息个数相等则合并信息推送web
//识别目标信息个数和获取信息个数相等则合并信息推送web
if (iHaveDataCnt == iPopPortCnt_)
{
std::shared_ptr<Train> pTrain = nullptr;
@ -315,7 +315,7 @@ APP_ERROR MergerAllEngine::Process()
pTrain->container1 = pTrainContainer->container1;
pTrain->container2 = pTrainContainer->container2;
}
//车头在前为第0节; 车头在后为最后一节+1
if(pTrain->trainNum.iTrainTypeId == 0 && iTrainIndex_ == 1)
{
@ -328,7 +328,9 @@ 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;
@ -346,6 +348,8 @@ APP_ERROR MergerAllEngine::Process()
}
}
// if (pTrain->trainPro.strLoad.size() > 2 && pTrain->trainPro.strLoad[0] != '1') pTrain->trainPro.strLoad = "";
PushData(pTrain);
//最后一节处理后,初始化参数

View File

@ -109,7 +109,7 @@ APP_ERROR LocalDataMoveEngine::Process()
pFtpData->strFtpFilePath = strImgPath;
pFtpData->strFtpFileName = strImgName;
pFtpData->bIsEnd = pProcessData->bIsEnd;
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pFtpData), true);
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pFtpData), false);
}
}
}

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

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

View File

@ -104,170 +104,170 @@ bool TransTrainEngine::AuthTransNum(int classId, const std::string &trainNum)
// LogInfo << "classId:" << classId << " trainNum:" << trainNum;
switch (classId)
{
case TRAIN_HEAD: // 车头上的编号
break;
case K_TRAIN_NUM: // 编号 矿车、煤炭漏斗车(兖矿自备、枣矿自备)
{
if (trainNum == "K13" || trainNum == "KM100AH")
case TRAIN_HEAD: // 车头上的编号
break;
case K_TRAIN_NUM: // 编号 矿车、煤炭漏斗车(兖矿自备、枣矿自备)
{
return true;
if (trainNum == "K13" || trainNum == "KM100AH")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 4:
reg = "^K[1FMZ]{1}[36789]{1}[018ABKNT]{1}";
break;
case 5:
reg = "^K[1M]{1}[368]{1}[1ABDN]{1}[AGKNT]{1}";
break;
case 6:
reg = "^K[MF]{1}[69]{1}[80]{1}A[KH]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
std::regex reg;
switch (trainNum.size())
case C_TRAIN_NUM: // 敞车 特殊车型 C5D CF CFK
{
case 4:
reg = "^K[1FMZ]{1}[36789]{1}[018ABKNT]{1}";
break;
case 5:
reg = "^K[1M]{1}[368]{1}[1ABDN]{1}[AGKNT]{1}";
break;
case 6:
reg = "^K[MF]{1}[69]{1}[80]{1}A[KH]{1}";
break;
if (trainNum == "CF" || trainNum == "C62A(N)")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^C[15678F]{1}[0123456DK]{1}";
break;
case 4:
reg = "^C[1678]{1}[012346]{1}[0ABCEFHKMTY]{1}";
break;
case 5:
reg = "^C[1678]{1}[01246]{1}[0ABCEY]{1}[KAFHNT]{1}";
break;
case 6:
reg = "^C[17]{1}0[0E]{1}[A-]{1}[AH]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case P_TRAIN_NUM: // 编号 棚车
{
if (trainNum == "P70(H)" || trainNum == "P62(N)")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^P[1678]{1}[012345]{1}";
break;
case 4:
reg = "^P[678]{1}[023456]{1}[ABHKNST]{1}";
break;
case 5:
reg = "^P6[24]{1}[ANG]{1}[KT]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case G_TRAIN_NUM: // 编号 罐车
{
if (trainNum == "GY100SK")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 2:
reg = "^G[HLS]{1}";
break;
case 3:
reg = "^[GL]{1}[1567HL]{1}[01246789K]{1}";
break;
case 4:
reg = "^[GU]{1}[167FJLNQSWY]{1}[170689]{1}[KSABDGTM075W]{1}";
break;
case 5:
reg = "^[GU]{1}[17FHNQY6]{1}[1706A89]{1}[SBDAM057W]{1}[KEHTB0ZAS]{1}";
break;
case 6:
reg = "^[UG]{1}[6YH]{1}[1489A]{1}[057W]{1}[Z0LSA]{1}[KSAT]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case NX_TRAIN_NUM: // 编号 平车
{
if (trainNum == "N6")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^[NQX]{1}[1234678T]{1}[0124567HK]{1}";
break;
case 4:
reg = "^[BNX]{1}[16X]{1}[17BC]{1}[07AGKT]{1}";
break;
case 5:
reg = "^[NX]{1}[16NX]{1}[17C]{1}[07AGT]{1}[KTABH]{1}";
break;
case 6:
reg = "^NX17[AB]{1}[KTH]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case J_TRAIN_NUM: // 编号 牲畜车 特种车
{
if (trainNum == "TP64GK")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 2:
reg = "^[DT]{1}[2678]{1}";
break;
case 3:
reg = "^[DST]{1}[12346789LQ]{1}[012578ADFGP]{1}";
break;
case 4:
reg = "^[DJNT]{1}[12356AFKQS]{1}[012345678DFQS]{1}[A12345679GHKQ]{1}";
break;
case 5:
reg = "^[DJQT]{1}[2KNSH1P]{1}[613XQ2]{1}[A761234B]{1}[KA70G]{1}";
break;
default:
LogWarn << "Unknow train classId: " << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case C_TRAIN_NUM: // 敞车 特殊车型 C5D CF CFK
{
if (trainNum == "CF" || trainNum == "C62A(N)")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^C[15678F]{1}[0123456DK]{1}";
break;
case 4:
reg = "^C[1678]{1}[012346]{1}[0ABCEFHKMTY]{1}";
break;
case 5:
reg = "^C[1678]{1}[01246]{1}[0ABCEY]{1}[KAFHNT]{1}";
break;
case 6:
reg = "^C[17]{1}0[0E]{1}[A-]{1}[AH]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case P_TRAIN_NUM: // 编号 棚车
{
if (trainNum == "P70(H)" || trainNum == "P62(N)")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^P[1678]{1}[012345]{1}";
break;
case 4:
reg = "^P[678]{1}[023456]{1}[ABHKNST]{1}";
break;
case 5:
reg = "^P6[24]{1}[ANG]{1}[KT]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case G_TRAIN_NUM: // 编号 罐车
{
if (trainNum == "GY100SK")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 2:
reg = "^G[HLS]{1}";
break;
case 3:
reg = "^[GL]{1}[1567HL]{1}[01246789K]{1}";
break;
case 4:
reg = "^[GU]{1}[167FJLNQSWY]{1}[170689]{1}[KSABDGTM075W]{1}";
break;
case 5:
reg = "^[GU]{1}[17FHNQY6]{1}[1706A89]{1}[SBDAM057W]{1}[KEHTB0ZAS]{1}";
break;
case 6:
reg = "^[UG]{1}[6YH]{1}[1489A]{1}[057W]{1}[Z0LSA]{1}[KSAT]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case NX_TRAIN_NUM: // 编号 平车
{
if (trainNum == "N6")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 3:
reg = "^[NQX]{1}[1234678T]{1}[0124567HK]{1}";
break;
case 4:
reg = "^[BNX]{1}[16X]{1}[17BC]{1}[07AGKT]{1}";
break;
case 5:
reg = "^[NX]{1}[16NX]{1}[17C]{1}[07AGT]{1}[KTABH]{1}";
break;
case 6:
reg = "^NX17[AB]{1}[KTH]{1}";
break;
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
case J_TRAIN_NUM: // 编号 牲畜车 特种车
{
if (trainNum == "TP64GK")
{
return true;
}
std::regex reg;
switch (trainNum.size())
{
case 2:
reg = "^[DT]{1}[2678]{1}";
break;
case 3:
reg = "^[DST]{1}[12346789LQ]{1}[012578ADFGP]{1}";
break;
case 4:
reg = "^[DJNT]{1}[12356AFKQS]{1}[012345678DFQS]{1}[A12345679GHKQ]{1}";
break;
case 5:
reg = "^[DJQT]{1}[2KNSH1P]{1}[613XQ2]{1}[A761234B]{1}[KA70G]{1}";
break;
default:
LogWarn << "Unknow train classId: " << classId << " trainNum:" << trainNum;
return false;
}
return std::regex_match(trainNum, reg);
}
default:
LogWarn << "Unknow trainclassId:" << classId << " trainNum:" << trainNum;
return false;
}
return true;
}
@ -294,9 +294,9 @@ void TransTrainEngine::FilterSingleData(std::vector<SingleData> &vecObjs, Target
std::deque<SingleData> dqObjs(vecObjs.begin(), vecObjs.end());
std::sort(dqObjs.begin(), dqObjs.end(), [](SingleData &a, SingleData &b)
{
return a.fLTY < b.fLTY;
});
{
return a.fLTY < b.fLTY;
});
dqObjs.pop_front();
dqObjs.pop_back();
@ -516,7 +516,8 @@ void TransTrainEngine::TransNum(TransSubData &transSubData, std::map<int, std::v
//校验车型是否符合验证
typeInfo.IsChkFlag = AuthTransNum(transSubData.iBigClassId, strTemp);
// LogInfo << "--->>> 符合正则吗?" << typeInfo.IsChkFlag << " --- " << strTemp;
transSubData.vecTransInfo.emplace_back(typeInfo);
}
@ -641,15 +642,15 @@ void TransTrainEngine::RecordNum(const TransSubData &transSubData, const std::sh
bool bIntervalFlag = ((int)(pProcessData->iFrameId - mapPreFrameId_[pProcessData->iDataSource]) > iSkipInterval_ * 2);
if (mapNumInfo_[pProcessData->iDataSource].find(strValue) == mapNumInfo_[pProcessData->iDataSource].end())
{
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " NUM:" << strValue
LogDebug << " frameid:" << pProcessData->iFrameId << " NUM:" << strValue
<< " bIntervalFlag:" << bIntervalFlag;
if (bIntervalFlag)
{
mapNumInfo_[pProcessData->iDataSource][strValue] = pProcessData->iFrameId;
}
}
LogDebug << "sourceid:" << pProcessData->iDataSource << " preframeid:" << mapPreFrameId_[pProcessData->iDataSource]
<< " frameid:" << pProcessData->iFrameId << " mapsize:" << mapNumInfo_[pProcessData->iDataSource].size();
// LogDebug << " preframeid:" << mapPreFrameId_[pProcessData->iDataSource]
// << " frameid:" << pProcessData->iFrameId << " mapsize:" << mapNumInfo_[pProcessData->iDataSource].size();
mapPreFrameId_[pProcessData->iDataSource] = pProcessData->iFrameId;
}
@ -659,7 +660,7 @@ void TransTrainEngine::RecordNum(const TransSubData &transSubData, const std::sh
* outParam:
* return : true/false
*/
bool TransTrainEngine::SaveMiddleNumCsv(const std::vector<pair<string, uint32_t>> &vecNums, const std::shared_ptr<ProcessData> &pProcessData,
bool TransTrainEngine::SaveMiddleNumCsv(const std::vector<pair<string, uint32_t>> &vecNums, const std::shared_ptr<ProcessData> &pProcessData,
int iSourceId)
{
//1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/)

View File

@ -389,21 +389,25 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext* pDecCtx, AVFra
if (ret < 0)
{
// fprintf(stderr, "Error sending a packet for decoding\n");
exit(1);
return -9;
}
while (ret >= 0)
{
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); // 解码
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
if (ret == AVERROR(EAGAIN))
{
// fprintf(stderr, "During decoding eof\n");
return -1;
}
else if (ret == AVERROR_EOF)
{
return -1;
}
else if (ret < 0)
{
// fprintf(stderr, "Error during decoding\n");
exit(1);
return -2;
}
////printf("saving frame %3d\n", pDecCtx->frame_number);

View File

@ -69,19 +69,19 @@ APP_ERROR VideoDecodeEngine::Process()
{
usleep(10*1000); //10ms
iNoCameraDataCnt++;
if (iNoCameraDataCnt >= 1000) //10秒内收不到认为相机断开
{
LogError << "engineId:" << engineId_ << " 超过10秒获取到摄像头数据疑似摄像头断开。计数" << iNoCameraDataCnt;
iNoCameraDataCnt = 0;
//camera异常时构造空的解码数据push确保一直有数据流转到后面Engine
std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
pProcessData->iDataSource = engineId_;
pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
pProcessData->iSize = 0;
pProcessData->pData = nullptr;
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
}
// iNoCameraDataCnt++;
// if (iNoCameraDataCnt >= 1000) //10秒内收不到认为相机断开
// {
// LogError << "engineId:" << engineId_ << " 超过10秒获取到摄像头数据疑似摄像头断开。计数" << iNoCameraDataCnt;
// iNoCameraDataCnt = 0;
// //camera异常时构造空的解码数据push确保一直有数据流转到后面Engine
// std::shared_ptr<ProcessData> pProcessData = std::make_shared<ProcessData>();
// pProcessData->iDataSource = engineId_;
// pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis();
// pProcessData->iSize = 0;
// pProcessData->pData = nullptr;
// iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData));
// }
continue;
}
@ -161,14 +161,30 @@ APP_ERROR VideoDecodeEngine::Process()
LogError << "push the after hard h264 decode yuv420m frame data failed...";
}
}
else if (iDecodeRet == -1)
{
// 视频结束 或者 数据量不足 一般为正常情况
}
else
{
LogError << "engineId:" << engineId_ << " HardH264FFmpegDecoderV2 failed...iDecodeRet:" << iDecodeRet;
if (hard_h264_ffmpeg_decoder_ != nullptr)
{
hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderDeInit();
delete hard_h264_ffmpeg_decoder_;
hard_h264_ffmpeg_decoder_ = nullptr;
}
}
}
catch(...)
catch(const std::exception& e)
{
LogError << "解码异常!!";
LogError << "解码异常!报警:" << e.what();
if (hard_h264_ffmpeg_decoder_ != nullptr)
{
hard_h264_ffmpeg_decoder_->HardH264FFmpegDecoderDeInit();
delete hard_h264_ffmpeg_decoder_;
hard_h264_ffmpeg_decoder_ = nullptr;
}
}
}
}

View File

@ -218,6 +218,8 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
APP_ERROR MoveEngine::Process()
{
int iRet = APP_ERR_OK;
const std::chrono::milliseconds LOG_INTERVAL(20000); // 每20秒打印一次
auto last_log_time = std::chrono::steady_clock::now() - LOG_INTERVAL;
while (!isStop_)
{
//pop端口0
@ -317,7 +319,7 @@ APP_ERROR MoveEngine::Process()
else
{
iHasTrainNum_ = iHasTrainNum_ == 0 ? iHasTrainNum_ : iHasTrainNum_ - 1;
if (iHasTrainNum_ == 0) LogInfo << "----- 当前无车 -----";
// if (iHasTrainNum_ == 0) LogInfo << "----- 当前无车 -----";
}
@ -351,6 +353,12 @@ APP_ERROR MoveEngine::Process()
LogDebug << "while iStepInter_: " << iStepInter_ << " queSize:" << queProcessData_.size();
queProcessData_.pop();
}
auto now = std::chrono::steady_clock::now();
if (now - last_log_time > LOG_INTERVAL)
{
last_log_time = now; // 重置计时器
LogInfo << "----- 当前无车 -----";
}
}
//有车识别处理
if (iStepInter_ != 0)

View File

@ -14,7 +14,7 @@ APP_ERROR TrainStepOneEngine::Init()
bUseEngine_ = MyUtils::getins()->ChkIsHaveTarget("NUM");
if (!bUseEngine_)
{
LogWarn << "engineId_:" << engineId_ << " not use engine";
LogInfo << "engineId_:" << engineId_ << " not use engine";
return APP_ERR_OK;
}
@ -98,7 +98,7 @@ APP_ERROR TrainStepOneEngine::InitModel()
int nRet = yolov5model.YoloV5ClearityInferenceInit(&modelinfo, strModelName, modelConfig_.strOmPath);
if (nRet != 0)
{
LogInfo << "YoloV5ClassifyInferenceInit nRet:" << nRet;
LogError << "YoloV5ClassifyInferenceInit nRet:" << nRet;
return APP_ERR_COMM_READ_FAIL;
}
return APP_ERR_OK;
@ -147,7 +147,7 @@ APP_ERROR TrainStepOneEngine::DeInit()
{
if (!bUseEngine_)
{
LogWarn << "engineId_:" << engineId_ << " not use engine";
LogInfo << "engineId_:" << engineId_ << " not use engine";
return APP_ERR_OK;
}
@ -170,7 +170,7 @@ void TrainStepOneEngine::PushData(const std::string &strPort, const std::shared_
int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast<void>(pProcessData));
if (iRet != 0)
{
LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
LogError << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet;
if (iRet == 2)
{
usleep(10000); // 10ms
@ -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 &&
@ -204,14 +204,14 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
it->bbox[3] <= dataSourceCfg.fIdentifyAreasRBY))
{
LogDebug << "frameId:" << pProcessData->iFrameId
<< " bigclassid:" << it->class_id << " 超出识别区域-识别区域:("
<< dataSourceCfg.fIdentifyAreasLTX << "," << dataSourceCfg.fIdentifyAreasLTY << "),("
<< dataSourceCfg.fIdentifyAreasRBX << "," << dataSourceCfg.fIdentifyAreasRBY << ")";
<< " bigclassid:" << it->class_id << " 超出识别区域-识别区域:("
<< dataSourceCfg.fIdentifyAreasLTX << "," << dataSourceCfg.fIdentifyAreasLTY << "),("
<< dataSourceCfg.fIdentifyAreasRBX << "," << dataSourceCfg.fIdentifyAreasRBY << ")";
it = vecRet.erase(it);
continue;
}
// 如果设置了不识别车头,则去掉车头所有大框
// 如果设置了不识别车头,则去掉车头标记的大框
if (!MyYaml::GetIns()->GetBoolValue("gc_train_heard_detect") && it->class_id == TRAIN_HEAD)
{
LogDebug << "frameId:" << pProcessData->iFrameId << " 过滤掉车头编号";
@ -219,13 +219,25 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
continue;
}
// 过滤车头部分的非车头编号大框
// 去除车头时的非车头编号信息
if(pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_HEAD )
{
if(it->class_id != TRAIN_HEAD)
{
LogDebug << " 帧号:" << pProcessData->iFrameId
<< " 大类:" << it->class_id << " 识别于车头位置,无效!";
<< " 大类:" << it->class_id << " 识别于车头位置,无效!";
it = vecRet.erase(it);
continue;
}
}
// 去除非车头的车头编号信息
if (pProcessData->nMonitorState != MONITOR_MODEL_TRAIN_HEAD)
{
if (it->class_id == TRAIN_HEAD)
{
LogDebug << " 帧号:" << pProcessData->iFrameId
<< " 大类:" << it->class_id << " 识别于非车头位置,无效!";
it = vecRet.erase(it);
continue;
}
@ -233,7 +245,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
// 去除车尾的间隔信息
if (pProcessData->nMonitorState == MONITOR_MODEL_TRAIN_TAIL
&& ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == 18))
&& ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == 18))
{
LogDebug << " frameId:" << pProcessData->iFrameId
<< " bigclassid:" << it->class_id
@ -242,12 +254,12 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
continue;
}
// 去除无车状态下的大框信息
// 过滤掉识别于模型反馈无车状态下的所有大框信息
if (pProcessData->nMonitorState == MONITOR_MODEL_NO_TRAIN)
{
LogDebug << " frameId:" << pProcessData->iFrameId
<< " bigclassid:" << it->class_id
<<" 识别于无车状态,无效!";
<<" 识别于模型反馈的无车状态,无效!";
it = vecRet.erase(it);
continue;
}
@ -286,7 +298,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
continue;
}
if (((it->class_id >= 2 && it->class_id <= 6) || it->class_id == J_TRAIN_NUM || it->class_id == W_TRAIN_NUM) &&
(it->bbox[3] - it->bbox[1]) < MyYaml::GetIns()->GetIntValue("gc_num_frame_height"))
(it->bbox[3] - it->bbox[1]) < MyYaml::GetIns()->GetIntValue("gc_num_frame_height"))
{
LogWarn << "疑似误识别到远股道车号,帧号:" << pProcessData->iFrameId
<< "大框高度:" << (it->bbox[3] - it->bbox[1]);
@ -295,7 +307,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
}
if ((it->class_id == 1 || it->class_id == TRAIN_PRO)
&& (it->bbox[3] - it->bbox[1]) < MyYaml::GetIns()->GetIntValue("gc_pro_frame_height")) {
&& (it->bbox[3] - it->bbox[1]) < MyYaml::GetIns()->GetIntValue("gc_pro_frame_height")) {
LogWarn << "疑似误识别到远股道属性,帧号:" << pProcessData->iFrameId
<< "大框高度:" << (it->bbox[3] - it->bbox[1]);
it = vecRet.erase(it);
@ -310,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)
{
@ -334,7 +362,7 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
int iCenterY = pProcessData->iHeight / 2;
if (iHeight0 < iCenterY && iHeight1 < iCenterY) //非平车
{
if (!((vecRet[0].class_id >= 9 && vecRet[0].class_id <= 17 && vecRet[0].class_id != 15) || vecRet[0].class_id == U_TRAIN_SPACE) &&
if (!((vecRet[0].class_id >= 9 && vecRet[0].class_id <= 17 && vecRet[0].class_id != 15) || vecRet[0].class_id == U_TRAIN_SPACE) &&
!((vecRet[1].class_id >= 9 && vecRet[1].class_id <= 17 && vecRet[1].class_id != 15) || vecRet[1].class_id == U_TRAIN_SPACE))
{
LogDebug << " frameId:" << pProcessData->iFrameId << " no space";
@ -401,7 +429,7 @@ APP_ERROR TrainStepOneEngine::Process()
{
if (!bUseEngine_)
{
LogWarn << "engineId_:" << engineId_ << " not use engine";
LogInfo << "engineId_:" << engineId_ << " not use engine";
return APP_ERR_OK;
}
int iRet = APP_ERR_OK;
@ -422,7 +450,7 @@ APP_ERROR TrainStepOneEngine::Process()
pPostData->iModelType = MODELTYPE_NUM;
pPostData->nMonitorState = pProcessData->nMonitorState; //来车检测的四个分类
//获取图片
//获取图片
if (pProcessData->iStatus == TRAINSTATUS_RUN || pProcessData->bIsEnd)
{
if (pProcessData->pData != nullptr && pProcessData->iSize != 0)
@ -431,10 +459,7 @@ APP_ERROR TrainStepOneEngine::Process()
//进行推理
std::vector<stDetection> res;
//auto start = std::chrono::system_clock::now(); //计时开始
yolov5model.YoloV5ClearityInferenceModel(img, res);
//auto end = std::chrono::system_clock::now();
//LogInfo << "nopr1 inference time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms";
//过滤无效信息
FilterInvalidInfo(res, pProcessData);
@ -475,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;
}
}
}
@ -492,8 +517,7 @@ APP_ERROR TrainStepOneEngine::Process()
//push端口0第1步推理
pProcessData->pVoidData = std::static_pointer_cast<void>(pPostData);
iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pProcessData), true);
// PushData(strPort0_, pProcessData);
PushData(strPort0_, pProcessData);
}
return APP_ERR_OK;
}

File diff suppressed because one or more lines are too long