From 8aa402bd5d5134cc2fe4f87fb03350942957c8ea Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Mon, 15 Aug 2022 17:36:19 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=AF=BB=E5=86=99=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B1=BB=EF=BC=88Configfile=EF=BC=89?= =?UTF-8?q?=EF=BC=9A1=EF=BC=89=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BCbug=EF=BC=8C2=EF=BC=89=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=BB=E5=86=99=20=E8=A3=81=E5=89=AA=E6=9C=89?= =?UTF-8?q?=E6=95=88=E7=AA=97=E5=8F=A3=E7=9A=84=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0getEffectiveWindowRoi=EF=BC=9B=202.?= =?UTF-8?q?=20=E5=9C=A8=E6=B2=A1=E6=9C=89=E9=87=87=E9=9B=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=EF=BC=8C=E8=AF=BB=E5=8F=96ximea=E6=B8=A9?= =?UTF-8?q?=E5=BA=A6=EF=BC=8C=E5=B9=B6=E5=86=99=E5=85=A5=E5=88=B0csv?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=EF=BC=9B=203.=20=E5=9C=A8=E5=8F=A6?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E5=B7=A5=E7=A8=8B=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?ximea=E6=8E=A7=E5=88=B6=E7=B1=BB=EF=BC=88Iris::IrisXimeaImager?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E5=B9=B6=E5=9C=A8=E6=AD=A4=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=AD=A4=E6=9B=B4=E6=96=B0=EF=BC=9A=E4=BB=8E?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9A=84=E6=9C=89=E6=95=88=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E4=B8=AD=E8=A3=81=E5=89=AA=E9=9C=80=E8=A6=81=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=8Cm=5Fimager.setEffectiveWindowRoi()=EF=BC=9B?= =?UTF-8?q?=204.=20=E5=9C=A8=E5=87=BD=E6=95=B0XimeaImager::processXiApiErr?= =?UTF-8?q?orCodes=E4=B8=AD=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=90=86xi?= =?UTF-8?q?mea=E9=94=99=E8=AF=AF=E7=A0=8112=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Header_Files/configfile.h | 16 ++--- Header_Files/ximeaimager.h | 27 ++++++++ Source_Files/configfile.cpp | 122 +++++++++++++++++++++++++---------- Source_Files/ximeaimager.cpp | 111 +++++++++++++++++++++++++++---- 记录-杂七杂八.txt | 4 ++ 5 files changed, 226 insertions(+), 54 deletions(-) diff --git a/Header_Files/configfile.h b/Header_Files/configfile.h index b5d2b5b..8237569 100644 --- a/Header_Files/configfile.h +++ b/Header_Files/configfile.h @@ -10,6 +10,9 @@ #include #include +#include +#include + using namespace std; using namespace libconfig; @@ -19,22 +22,19 @@ class Configfile public: Configfile(); void setConfigfilePath(string configfilePath); - int parseConfigfile(); + bool isConfigfileExist(); + bool parseConfigfile(); bool getBin(int &bin); bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety); + bool getEffectiveWindowRoi(int &width, int &offsetx); bool getGainOffset(float &gain, float &offset); - int createConfigFile(); - int updateConfigFile(); + bool createConfigFile(); + bool updateConfigFile(); private: string m_configfilePath; Config cfg; - - - }; - - #endif //XIMEAIMAGERECORDER_CONFIGFILE_H diff --git a/Header_Files/ximeaimager.h b/Header_Files/ximeaimager.h index 3aec613..f5f698f 100644 --- a/Header_Files/ximeaimager.h +++ b/Header_Files/ximeaimager.h @@ -27,6 +27,7 @@ #include #include +#include #include #include "configfile.h" @@ -42,6 +43,26 @@ //#include // Linux, OSX //#endif +class RecordXimeaTemperature : public QObject +{ +Q_OBJECT + +public: + RecordXimeaTemperature(Iris::IrisXimeaImager * imager); + + void stopRecordTemperature(); + +private: + Iris::IrisXimeaImager * m_imager; + + bool m_bIsRecord; +public slots: + void recordTemperature(QString filePath); + +signals: + +}; + class XimeaImager : public QObject { Q_OBJECT @@ -74,7 +95,11 @@ private: int m_iImagerState; int m_iImagerStateTemp; + QThread * m_recordTempThread; + RecordXimeaTemperature * m_ximeaTemperature; + QString m_baseFileName; + QString m_ximeaTemperatureCSVPath; Iris::IrisXimeaImager m_imager; unsigned short * m_buffer; @@ -115,5 +140,7 @@ public slots: signals: void recordFinished(); void ximeaImageStatus(int); + + void recordXimeaTemperatureSignal(QString); }; #endif // XIMEAIMAGER_H diff --git a/Source_Files/configfile.cpp b/Source_Files/configfile.cpp index 1b968c3..2de81f8 100644 --- a/Source_Files/configfile.cpp +++ b/Source_Files/configfile.cpp @@ -14,24 +14,32 @@ void Configfile::setConfigfilePath(string configfilePath) m_configfilePath = configfilePath; } +bool Configfile::isConfigfileExist() +{ + QFileInfo info(QString::fromStdString(m_configfilePath)); -int Configfile::parseConfigfile() + return info.exists(); +} + +bool Configfile::parseConfigfile() { // Read the file. If there is an error, report it and exit. try { cfg.readFile(m_configfilePath); + + return true; } catch(const FileIOException &fioex) { std::cerr << "I/O error while reading file." << std::endl; - return(EXIT_FAILURE); + return false; } catch(const ParseException &pex) { std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl; - return(EXIT_FAILURE); + return false; } } @@ -41,12 +49,12 @@ bool Configfile::getBin(int &bin) { bin = cfg.lookup("bin"); - return(EXIT_SUCCESS); + return true; } catch(const SettingNotFoundException &nfex) { cerr << "No 'bin' setting in configuration file." << endl; - return(EXIT_FAILURE); + return false; } } @@ -71,16 +79,48 @@ bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int & && window.lookupValue("height", height) && window.lookupValue("offsety", offsety))) { - return(EXIT_FAILURE); + return false; } } catch(const SettingNotFoundException &nfex) { // Ignore. - int a=1; + return false; } - return(EXIT_SUCCESS); + return true; +} + +bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx) +{ + const Setting& root = cfg.getRoot(); + + // Output a list of all books in the inventory. + try + { + const Setting &effective_window = root["effective_window_roi"]; + int count = effective_window.getLength(); + + int bin; + getBin(bin); + + const Setting &window = effective_window[bin-1]; + string name = window.getName(); + + if(!(window.lookupValue("width", width) + && window.lookupValue("offsetx", offsetx) + )) + { + return false; + } + } + catch(const SettingNotFoundException &nfex) + { + // Ignore. + return false; + } + + return true; } bool Configfile::getGainOffset(float &gain, float &offset) @@ -102,19 +142,19 @@ bool Configfile::getGainOffset(float &gain, float &offset) if(!(gainOffsetSetting.lookupValue("gain", gain) && gainOffsetSetting.lookupValue("offset", offset))) { - return(EXIT_FAILURE); + return false; } } catch(const SettingNotFoundException &nfex) { // Ignore. - int a=1; + return false; } - return(EXIT_SUCCESS); + return true; } -int Configfile::createConfigFile() +bool Configfile::createConfigFile() { using namespace std; using namespace libconfig; @@ -129,28 +169,42 @@ int Configfile::createConfigFile() Setting &SN = root.add("SN", Setting::TypeString) = "0098"; Setting &effective_window = root.add("effective_window", Setting::TypeGroup); - Setting &effective_windowBin1 = effective_window.add("bin1", Setting::TypeGroup); - Setting &effective_windowBin2 = effective_window.add("bin2", Setting::TypeGroup); + Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup); + Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup); - effective_windowBin1.add("width", Setting::TypeInt) = 1; - effective_windowBin1.add("offsetx", Setting::TypeInt) = 2; - effective_windowBin1.add("height", Setting::TypeInt) = 3; - effective_windowBin1.add("offsety", Setting::TypeInt) = 4; + effective_window_Bin1.add("width", Setting::TypeInt) = 1392; + effective_window_Bin1.add("offsetx", Setting::TypeInt) = 272; + effective_window_Bin1.add("height", Setting::TypeInt) = 300; + effective_window_Bin1.add("offsety", Setting::TypeInt) = 348; - effective_windowBin2.add("width", Setting::TypeInt) = 5; - effective_windowBin2.add("offsetx", Setting::TypeInt) = 6; - effective_windowBin2.add("height", Setting::TypeInt) = 7; - effective_windowBin2.add("offsety", Setting::TypeInt) = 8; + effective_window_Bin2.add("width", Setting::TypeInt) = 712; + effective_window_Bin2.add("offsetx", Setting::TypeInt) = 128; + effective_window_Bin2.add("height", Setting::TypeInt) = 151; + effective_window_Bin2.add("offsety", Setting::TypeInt) = 174; + + Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup); + Setting &effective_window_roi_Bin1 = effective_window_roi.add("bin1", Setting::TypeGroup); + Setting &effective_window_roi_Bin2 = effective_window_roi.add("bin2", Setting::TypeGroup); + + effective_window_roi_Bin1.add("width", Setting::TypeInt) = 1364; + effective_window_roi_Bin1.add("offsetx", Setting::TypeInt) = 14; +// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300; +// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348; + + effective_window_roi_Bin2.add("width", Setting::TypeInt) = 682; + effective_window_roi_Bin2.add("offsetx", Setting::TypeInt) = 15; +// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151; +// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174; Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup); Setting &gainOffsetBin1 = gainOffset.add("bin1", Setting::TypeGroup); Setting &gainOffsetBin2 = gainOffset.add("bin2", Setting::TypeGroup); - gainOffsetBin1.add("gain", Setting::TypeFloat) = 9.12; - gainOffsetBin1.add("offset", Setting::TypeFloat) = -10.2; + gainOffsetBin1.add("gain", Setting::TypeFloat) = 2.00313433; + gainOffsetBin1.add("offset", Setting::TypeFloat) = -300.46283157590585; - gainOffsetBin2.add("gain", Setting::TypeFloat) = 11.789; - gainOffsetBin2.add("offset", Setting::TypeFloat) = -12.58; + gainOffsetBin2.add("gain", Setting::TypeFloat) = 4.00626868; + gainOffsetBin2.add("offset", Setting::TypeFloat) = -299.46126663407176; // Write out the new configuration. @@ -162,14 +216,14 @@ int Configfile::createConfigFile() } catch(const FileIOException &fioex) { - cerr << "I/O error while writing file: " << output_file << endl; - return(EXIT_FAILURE); + cerr << "I/O error while writing configuration file: " << output_file << endl; + return true; } - return(EXIT_SUCCESS); + return true; } -int Configfile::updateConfigFile() +bool Configfile::updateConfigFile() { using namespace std; using namespace libconfig; @@ -191,13 +245,13 @@ int Configfile::updateConfigFile() catch(const FileIOException &fioex) { std::cerr << "I/O error while reading file." << std::endl; - return(EXIT_FAILURE); + return false; } catch(const ParseException &pex) { std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl; - return(EXIT_FAILURE); + return false; } // Find the 'movies' setting. Add intermediate settings if they don't yet @@ -233,8 +287,8 @@ int Configfile::updateConfigFile() catch(const FileIOException &fioex) { cerr << "I/O error while writing file: " << output_file << endl; - return(EXIT_FAILURE); + return false; } - return(EXIT_SUCCESS); + return true; } diff --git a/Source_Files/ximeaimager.cpp b/Source_Files/ximeaimager.cpp index e33cd49..e1a756e 100644 --- a/Source_Files/ximeaimager.cpp +++ b/Source_Files/ximeaimager.cpp @@ -10,9 +10,16 @@ XimeaImager::XimeaImager() //connect(this, SIGNAL(recordFinished()),this, SLOT()); m_configfile.setConfigfilePath("ximea.cfg"); + if(!m_configfile.isConfigfileExist()) + m_configfile.createConfigFile(); m_configfile.parseConfigfile(); -// m_configfile.createConfigFile(); + m_recordTempThread=new QThread(); + m_ximeaTemperature = new RecordXimeaTemperature(&m_imager); + m_ximeaTemperature->moveToThread(m_recordTempThread); + m_recordTempThread->start(); + + connect(this, SIGNAL(recordXimeaTemperatureSignal(QString)),m_ximeaTemperature, SLOT(recordTemperature(QString))); } void XimeaImager::openImger() @@ -29,18 +36,36 @@ void XimeaImager::openImger() //std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<stopRecordTemperature(); + if(m_iImagerState==100) { emit ximeaImageStatus(m_iImagerState); @@ -88,6 +118,8 @@ void XimeaImager::closeImger() std::cout<<"XimeaImager::closeImger-------------------!"<maxValue) +// std::cout<<"像素值为:"<< *(data + i) <maxValue) { - maxValue=data[i]; + //std::cout<<"像素值为:"<< *(data + i) <stopRecordTemperature();//开始采集影像前,停止获取相机的温度,以免降低帧率; try { if(m_iImagerState <= 99 || m_iImagerState==100 || m_iImagerState==104) @@ -424,6 +463,8 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base m_iFrameCounter+=1; +// if(m_iFrameCounter==100) +// break; double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg); @@ -453,11 +494,13 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base double frameLossRate=frameLossed / frameInTheory; std::cout<<"当前采集文件为: "<getTemperature(); + + QDateTime curDateTime = QDateTime::currentDateTime(); + QString currentTime = curDateTime.toString("yyyy/MM/dd hh:mm:ss"); + + ximeaTemperatureFile << currentTime.toStdString() << "," << temp << "\n"; + +// std::cout<<"RecordXimeaTemperature::recordTemperature----------------:ximea Temperature is "<< temp <