277 lines
12 KiB
C++
277 lines
12 KiB
C++
#include "main.h"
|
|
|
|
#include "HxDevice.h"
|
|
|
|
CarInfoInput car_info;
|
|
|
|
static HxDevice device[6];
|
|
|
|
static ObjectEventDetectConfig event_detect_config;
|
|
/* 报警参数配置 */
|
|
static EventWarnParamConfig warm_param_config;
|
|
/* ADAS 相机内外参 */
|
|
static CameraCalibration adas_camera_calibration;
|
|
|
|
static void broadcast_receive_event(QByteArray data);
|
|
|
|
static void algorithm_initialization();
|
|
/* 算法报警处理函数 */
|
|
static void algorithm_detection_callback(int nDataChannel, ObjectTrackEventResult* pObjectTrackEventResult, void* pPrivData);
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
QCoreApplication a(argc, argv);
|
|
|
|
/* 需要设置的运行时默认工作路径 */
|
|
QDir::setCurrent(QCoreApplication::applicationDirPath());
|
|
|
|
/* 设置最大线程个数 */
|
|
QThreadPool::globalInstance()->setMaxThreadCount(100);
|
|
|
|
/* UDP广播 初始化 */
|
|
HxBroadcast::initialization(BROADCAST_PORT);
|
|
QObject::connect(HxBroadcast::context(), &HxBroadcast::receive_event, [=](QByteArray data) { broadcast_receive_event(data); });
|
|
|
|
WRITE_SYSTEM_LOG("系统启动", "HxIVA");
|
|
|
|
algorithm_initialization();
|
|
|
|
car_info.fVelocity = 20;
|
|
|
|
return a.exec();
|
|
}
|
|
|
|
void broadcast_receive_event(QByteArray data)
|
|
{
|
|
int action_type = -1;
|
|
|
|
auto document = QJsonDocument::fromJson(data);
|
|
auto root = document.object();
|
|
if (!root.contains("action_type"))
|
|
return;
|
|
|
|
action_type = root.value("action_type").toInt();
|
|
|
|
switch (action_type)
|
|
{
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 5:
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* 算法模块初始化 */
|
|
static void algorithm_initialization()
|
|
{
|
|
/* adas检测配置 */
|
|
strcpy(event_detect_config.szAdasDetectConfigPathName, "./algmode/adas_detect.bin");
|
|
/* adas跟踪配置 */
|
|
strcpy(event_detect_config.szAdasTrackConfigPathName, "./algmode/adas_track.bin");
|
|
/* bsd检测配置 */
|
|
strcpy(event_detect_config.szBsdDetectConfigPathName, "./algmode/bsd_detect.bin");
|
|
// strcpy(event_detect_config.szRightBsdFrontDetectConfigPathName, "./algmode/bsd_detect.bin");
|
|
/* dsm人脸检测配置 */
|
|
strcpy(event_detect_config.szDsmFaceDetectConfigPathName, "./algmode/dsm_face_detect.bin");
|
|
/* dsm人脸特征点检测配置 */
|
|
strcpy(event_detect_config.szDsmFaceLandMarksDetectConfigPathName, "./algmode/dsm_face_landmarks_detect.bin");
|
|
/* dsm人脸认证检测配置 */
|
|
strcpy(event_detect_config.szDsmFaceVerificationDetectConfigPathName, "./algmode/dsm_face_verification_detect.bin");
|
|
/* dsm人眼认证检测配置 */
|
|
strcpy(event_detect_config.szDsmEyeLandMarksDetectConfigPathName, "./algmode/dsm_eye_landmarks_detect.bin");
|
|
/* dsm人脸认证检测配置 */
|
|
strcpy(event_detect_config.szDsmSmokeConfPathName, "./algmode/dsm_smoke_detect.bin");
|
|
strcpy(event_detect_config.szDsmCallConfPathName, "./algmode/dsm_call_detect.bin");
|
|
strcpy(event_detect_config.szDsmFaceFeaturePathName, "./algmode/dsm_face_feature.bin");
|
|
strcpy(event_detect_config.szDsmHeadPoseConfPathName, "./algmode/data_68kp");
|
|
|
|
#if USE_ALGORITHM
|
|
/* 输出调试信息 */
|
|
MvSetPrintf(true);
|
|
|
|
/* 目标跟踪事件检测初始化 */
|
|
if (MvObjectEventDetectInit(&event_detect_config, RIGHT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_REAR_DETECT_CHANNEL | LEFT_BSD_FRONT_DETECT_CHANNEL | LEFT_BSD_REAR_DETECT_CHANNEL | FRONT_BSD_DETECT_CHANNEL | REAR_BSD_DETECT_CHANNEL | DMS_DETECT_CHANNEL | ADAS_DETECT_CHANNEL) != 0)
|
|
{
|
|
// HxLog::append("initialization", "object event detect init failed!!");
|
|
qDebug() << "object event detect init failed!!";
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
/* 读取配置文件 */
|
|
auto settings = new QSettings("config.ini", QSettings::IniFormat);
|
|
|
|
auto start_event_warn_kind = settings->value("warn_param/start_event_warn_kind", "1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1").toString().split(";");
|
|
auto abnormal_warn_frame_count = settings->value("warn_param/abnormal_warn_frame_count", "0;0;0;0;0;0;0;50;75;25;50;75;50;50;50;25;75;50;50;50;50;50;75;50;50;100").toString().split(";");
|
|
auto normal_frame_count = settings->value("warn_param/normal_frame_count", "0;0;0;0;0;0;0;25;25;25;25;25;25;25;25;25;25;25;25;25;25;25;0;0;0;0").toString().split(";");
|
|
auto abnormal_warn_interval_frame_count = settings->value("warn_param/abnormal_warn_interval_frame_count", "0;0;125;0;125;0;0;0;0;0;0;0;0;125;0;0;0;0;0;0;0;0;0;0;0;0").toString().split(";");
|
|
auto abnormal_warn_score_threshold = settings->value("warn_param/abnormal_warn_score_threshold", "0;0;0;0;0;0;0;0.7;0.8;0.4;0.65;0.95;0.75;0.3;0.65;0.5;0.87;25;25;20;15;0.75;0.3;0.5;0.5;0.5").toString().split(";");
|
|
auto normal_warn_score_threshold = settings->value("warn_param/normal_warn_score_threshold", "0;0;0;0;0;0;0;0.35;0.35;0.7;0.7;0.7;0.55;0.8;0.4;0.55;0.13;20;20;15;10;0.55;0.3;0.3;0.5;0.5").toString().split(";");
|
|
|
|
for (int i = 0; i < EVENT_WARN_NUM; i++)
|
|
{
|
|
warm_param_config.bStartEventWarnKind[i] = QVariant(start_event_warn_kind.at(i)).toBool();
|
|
warm_param_config.nAbnormalWarnFrameCount[i] = abnormal_warn_frame_count.at(i).toInt();
|
|
warm_param_config.nNormalFrameCount[i] = normal_frame_count.at(i).toInt();
|
|
warm_param_config.nAbnormalWarnIntervalFrameCount[i] = abnormal_warn_interval_frame_count.at(i).toInt();
|
|
warm_param_config.fAbnormalWarnScoreThreshold[i] = abnormal_warn_score_threshold.at(i).toFloat();
|
|
warm_param_config.fNormalWarnScoreThreshold[i] = normal_warn_score_threshold.at(i).toFloat();
|
|
}
|
|
|
|
warm_param_config.nHmwTime = settings->value("warn_param/hmw_time", 1200).toInt();
|
|
warm_param_config.nPcwTime = settings->value("warn_param/pcw_time", 2000).toInt();
|
|
warm_param_config.nFcwTime = settings->value("warn_param/fcw_time", 2400).toInt();
|
|
warm_param_config.fHmwVel = settings->value("warn_param/hmw_vel", 30).toDouble();
|
|
warm_param_config.fFcwVel = settings->value("warn_param/fcw_vel", 30).toDouble();
|
|
warm_param_config.fLdwVel = settings->value("warn_param/ldw_vel", 55).toDouble();
|
|
warm_param_config.fPcwVel = settings->value("warn_param/pcw_vel", 50).toDouble();
|
|
warm_param_config.fBsdFirstVel = settings->value("warn_param/bsd_first_vel", 30).toDouble();
|
|
warm_param_config.fBsdSecondVel = settings->value("warn_param/bsd_second_vel", 30).toDouble();
|
|
warm_param_config.fBsdThirdVel = settings->value("warn_param/bsd_third_vel", 30).toDouble();
|
|
warm_param_config.nLdwDistance = settings->value("warn_param/ldw_distance", -5).toInt();
|
|
warm_param_config.fDsmVel = settings->value("warn_param/dsm_vel", 5).toDouble();
|
|
|
|
#if USE_ALGORITHM
|
|
/* 设置报警参数 */
|
|
if (MvSetEventWarnParamConfig(&warm_param_config) != 0)
|
|
// HxLog::append("initialization", "set event warn param config failed!!");
|
|
qDebug() << "set event warn param config failed!!";
|
|
#endif
|
|
|
|
adas_camera_calibration.fCarLen = settings->value("adas_camera_calibration/car_len", 4527).toInt();
|
|
adas_camera_calibration.fCarWidth = settings->value("adas_camera_calibration/car_width", 1830).toInt();
|
|
adas_camera_calibration.fRefCenter = settings->value("adas_camera_calibration/ref_center", 0).toInt();
|
|
adas_camera_calibration.fRefTop = settings->value("adas_camera_calibration/ref_top", 1695).toInt();
|
|
adas_camera_calibration.fDisLen2Tyre = settings->value("adas_camera_calibration/dis_len_2_tyre", 0).toInt();
|
|
adas_camera_calibration.fCameraHeight = settings->value("adas_camera_calibration/camera_height", 1500).toInt();
|
|
adas_camera_calibration.fCameraFocus = settings->value("adas_camera_calibration/camera_focus", 6.00).toDouble();
|
|
adas_camera_calibration.fCameraDx = settings->value("adas_camera_calibration/camera_dx", 0.00).toDouble();
|
|
adas_camera_calibration.fPitch = settings->value("adas_camera_calibration/pitch", -0.32).toDouble();
|
|
adas_camera_calibration.fYaw = settings->value("adas_camera_calibration/yaw", 0.00).toDouble();
|
|
|
|
#if USE_ALGORITHM
|
|
/* 相机标定 */
|
|
if (MvCameraCalibration(&adas_camera_calibration) != 0)
|
|
// HxLog::append("initialization", "camera calibration failed!!");
|
|
qDebug() << "setcamera calibration failed!!";
|
|
#endif
|
|
|
|
int detect_channel = 0;
|
|
|
|
/* 获取通道配置信息 */
|
|
for (int i = 1; i <= CHANNEL_MAX; i++)
|
|
{
|
|
settings->beginGroup(QString("channel_%1").arg(i, 2, 10, QLatin1Char('0')));
|
|
|
|
auto channel = 0;
|
|
auto url = settings->value("url").toString();
|
|
auto mode = settings->value(QString("mode")).toInt();
|
|
|
|
if (url.isEmpty())
|
|
goto ENDGROUP;
|
|
|
|
if (mode == 0) /* ADAS */
|
|
{
|
|
channel = ADAS_DETECT_CHANNEL;
|
|
}
|
|
else if (mode == 2) /* DSM */
|
|
{
|
|
channel = DMS_DETECT_CHANNEL;
|
|
}
|
|
else /* BSD */
|
|
{
|
|
switch (mode)
|
|
{
|
|
case 6: /* 前 */
|
|
channel = FRONT_BSD_DETECT_CHANNEL;
|
|
break;
|
|
case 7: /* 后 */
|
|
channel = REAR_BSD_DETECT_CHANNEL;
|
|
break;
|
|
case 4:/* 左前 */
|
|
channel = LEFT_BSD_FRONT_DETECT_CHANNEL;
|
|
break;
|
|
case 1:/* 右前 */
|
|
channel = RIGHT_BSD_FRONT_DETECT_CHANNEL;
|
|
break;
|
|
case 5:/* 左后 */
|
|
channel = LEFT_BSD_REAR_DETECT_CHANNEL;
|
|
break;
|
|
case 3:/* 右后 */
|
|
channel = RIGHT_BSD_REAR_DETECT_CHANNEL;
|
|
break;
|
|
|
|
default:
|
|
goto ENDGROUP;
|
|
}
|
|
|
|
BsdWarnRegion region;
|
|
|
|
auto array = settings->value("param", "1280,0 0,0 0,720 1280,720$1280,0 0,0 0,720 1280,720$1280,0 0,0 0,720 1280,720").toString().split("$");
|
|
auto points = array[0].split(" ");
|
|
for (int a = 0; a < 4; a++)
|
|
{
|
|
auto p = points.at(a).split(",");
|
|
|
|
region.tFirstRegionPoint[a].x = p[0].toInt();
|
|
region.tFirstRegionPoint[a].y = p[1].toInt();
|
|
}
|
|
|
|
points = array[1].split(" ");
|
|
for (int a = 0; a < 4; a++)
|
|
{
|
|
auto p = points.at(a).split(",");
|
|
|
|
region.tSecondRegionPoint[a].x = p[0].toInt();
|
|
region.tSecondRegionPoint[a].y = p[1].toInt();
|
|
}
|
|
|
|
points = array[2].split(" ");
|
|
for (int a = 0; a < 4; a++)
|
|
{
|
|
auto p = points.at(a).split(",");
|
|
|
|
region.tThirdRegionPoint[a].x = p[0].toInt();
|
|
region.tThirdRegionPoint[a].y = p[1].toInt();
|
|
}
|
|
|
|
#if USE_ALGORITHM
|
|
MvSetBsdWarnRegion(channel, ®ion);
|
|
#endif
|
|
}
|
|
|
|
detect_channel |= channel;
|
|
|
|
#if USE_ALGORITHM
|
|
if (MvSetAlgResultFuncCallback(channel, algorithm_detection_callback, nullptr) != 0)
|
|
{
|
|
HxTrace::debug_write_line("application", "MvSetAlgResultFuncCallback failed!!");
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
device[i].set(channel, url);
|
|
device[i].startup();
|
|
HxTrace::debug_write_line("application", QString("channel: %1, %2").arg(i).arg(url));
|
|
|
|
ENDGROUP:
|
|
settings->endGroup();
|
|
}
|
|
|
|
#if USE_ALGORITHM
|
|
MvSetDetectChannel(detect_channel);
|
|
#endif
|
|
}
|
|
|
|
static void algorithm_detection_callback(int nDataChannel, ObjectTrackEventResult* pObjectTrackEventResult, void* pPrivData)
|
|
{
|
|
Q_UNUSED(nDataChannel);
|
|
Q_UNUSED(pObjectTrackEventResult);
|
|
Q_UNUSED(pPrivData);
|
|
|
|
if (pObjectTrackEventResult->nEventType)
|
|
HxTrace::debug_write_line("algorithm", QString("nDataChannel=%1, nFrameId=%2, nObjectNumber=%3, nEventType=%4\n").arg(nDataChannel).arg(pObjectTrackEventResult->nFrameId).arg(pObjectTrackEventResult->nObjectNumber).arg(pObjectTrackEventResult->nEventType));
|
|
}
|