From 68b95f4f72f80500f37444e41d2eb669ae9f841e Mon Sep 17 00:00:00 2001 From: SoulBasic <690204874@qq.com> Date: Fri, 26 Feb 2021 17:50:13 +0800 Subject: [PATCH] fix bugs of autoinit --- Detector.cpp | 17 ++++++++++++++++- Detector.h | 1 + detectviewer.cpp | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Detector.cpp b/Detector.cpp index b8dba91..c1594d7 100644 --- a/Detector.cpp +++ b/Detector.cpp @@ -22,13 +22,17 @@ Detector::Detector(int threshVal, int minArea) : _target_ver_offset(0.5f), _target_hor_offset(0.5f), _cell_expand_para(0.75f), - _target_offset_angle(0) + _target_offset_angle(0), + _history_read(false) { + Sleep(15000); FILE* target = fopen("target_config.ini", "rt"); if (target != nullptr) { fscanf(target, "target_ver_offset=%f\ntarget_hor_offset=%f\ntarget_offset_angle=%d\ncell_expand_para=%f", &_target_ver_offset, &_target_hor_offset, &_target_offset_angle, &_cell_expand_para); fclose(target); + calc_target(); + _history_read = true; } std::thread tt(std::bind(&Detector::timeThread, this)); @@ -61,6 +65,17 @@ void Detector::timeThread() { if (a != -1 && msg.message == WM_TIMER) { + if (!_history_read) + { + FILE* target = fopen("target_config.ini", "rt"); + if (target != nullptr) + { + fscanf(target, "target_ver_offset=%f\ntarget_hor_offset=%f\ntarget_offset_angle=%d\ncell_expand_para=%f", &_target_ver_offset, &_target_hor_offset, &_target_offset_angle, &_cell_expand_para); + fclose(target); + calc_target(); + _history_read = true; + } + } _fps = _frame_count * 5; _frame_count = 0; send_modbus_packet(); diff --git a/Detector.h b/Detector.h index 673f066..dd3f396 100644 --- a/Detector.h +++ b/Detector.h @@ -107,6 +107,7 @@ class Detector bool _running; bool _show_ellipse; bool _show_target; + bool _history_read; int _ret; char _recvBuf[256] = {}; }; diff --git a/detectviewer.cpp b/detectviewer.cpp index e07e965..d4bc2da 100644 --- a/detectviewer.cpp +++ b/detectviewer.cpp @@ -26,7 +26,6 @@ void DetectViewer::initializeGL() } auto adaptor = std::make_shared();//初始化一个Aver采集卡视频适配器 - Sleep(10000); if (!adaptor->init())//采集卡初始化 { #ifdef _DEBUG