From c1e4144ed65b255c1bdf80cffa39fe474e280ee5 Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Fri, 9 May 2025 17:27:04 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=94=AF=E6=8C=81corning=20410=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HPPA/Corning410Imager.cpp | 158 +++++++++++ HPPA/Corning410Imager.h | 48 ++++ HPPA/HPPA.cpp | 5 +- HPPA/HPPA.h | 1 + HPPA/HPPA.vcxproj | 12 +- HPPA/HPPA.vcxproj.filters | 24 ++ HPPA/hppaConfigFile.cpp | 526 +++++++++++++++++++++++++++++++++++ HPPA/hppaConfigFile.h | 30 ++ HPPA/imager_base.cpp | 165 +++++++++++ HPPA/imager_base.h | 93 +++++++ HPPA/irisximeaimager.cpp | 565 ++++++++++++++++++++++++++++++++++++++ HPPA/irisximeaimager.h | 123 +++++++++ 12 files changed, 1745 insertions(+), 5 deletions(-) create mode 100644 HPPA/Corning410Imager.cpp create mode 100644 HPPA/Corning410Imager.h create mode 100644 HPPA/imager_base.cpp create mode 100644 HPPA/imager_base.h create mode 100644 HPPA/irisximeaimager.cpp create mode 100644 HPPA/irisximeaimager.h diff --git a/HPPA/Corning410Imager.cpp b/HPPA/Corning410Imager.cpp new file mode 100644 index 0000000..9c50902 --- /dev/null +++ b/HPPA/Corning410Imager.cpp @@ -0,0 +1,158 @@ +#include "Corning410Imager.h" + +Corning410Imager::Corning410Imager() +{ + //配置文件:如果没有,就创建配置文件 + string CfgFile = getPathofEXE() + "\\corning410.cfg"; + m_configfile.setConfigfilePath(CfgFile); + if (!m_configfile.isConfigfileExist()) + { + m_configfile.createConfigFile(); + qDebug() << "create: " << QString::fromStdString(CfgFile); + } + m_configfile.parseConfigfile(); + qDebug() << "exist: " << QString::fromStdString(CfgFile); +} + +Corning410Imager::~Corning410Imager() +{ + if (buffer != nullptr) + { + std::cout << "释放堆上内存" << std::endl; + free(buffer); + free(dark); + free(white); + } +} + +double Corning410Imager::getFramerate() +{ + return m_imager.get_framerate(); +} + +double Corning410Imager::getIntegrationTime() +{ + return m_imager.get_integration_time(); +} + +double Corning410Imager::getGain() +{ + return m_imager.get_gain(); +} + +void Corning410Imager::setGain(const double gain) +{ + m_imager.set_gain(gain); +} + +void Corning410Imager::setFramerate(const double frames_per_second) +{ + m_imager.set_framerate(frames_per_second); + m_RgbImage->m_iFramerate = frames_per_second; +} + +void Corning410Imager::setIntegrationTime(const double milliseconds) +{ + m_imager.set_integration_time(milliseconds); +} + +int Corning410Imager::getStartBand() +{ + return m_imager.get_start_band(); +} + +int Corning410Imager::getEndBand() +{ + return m_imager.get_end_band(); +} + +void Corning410Imager::connectImager(const char* camera_sn) +{ + m_imager.connect(); + + //读取配置文件参数,并为相机设置参数 + bool ret, ret1, ret2; + + int spatialBin; + int spectralBin; + ret1 = m_configfile.getspatialBin(spatialBin); + ret2 = m_configfile.getSpectralBin(spectralBin); + if (ret1 && ret2) + { + bool haha = m_imager.setSpectralBin(spectralBin); + bool haha2 = m_imager.setSpatialBin(spatialBin); + + std::cout << "spectralBin:" << spectralBin << std::endl; + std::cout << "spatialBin:" << spatialBin << std::endl; + } + + float gain, offset; + ret = m_configfile.getGainOffset(gain, offset); + if (ret) + { + m_imager.setGainOffset(gain, offset); + } + + int width = 0, offsetx = 0, height = 0, offsety = 0; + ret = m_configfile.getEffectiveWindow(width, offsetx, height, offsety); + if (ret) + { + m_imager.setEffectiveWindow(offsetx, width, offsety, height); + } + + + int bufferPolicy, acqBufferSize; + ret1 = m_configfile.getBufferPolicy(bufferPolicy); + if (ret1) + { + m_imager.setBufferPolicy(bufferPolicy); + } + ret1 = m_configfile.getAcqBufferSize(acqBufferSize); + if (ret1) + { + m_imager.setAcqBufferSize(acqBufferSize); + } + +} + +void Corning410Imager::disconnectImager() +{ + m_imager.disconnect(); +} + +void Corning410Imager::imagerStartCollect() +{ + m_imager.start(); +} + +void Corning410Imager::imagerStopCollect() +{ + m_imager.stop(); +} + +unsigned short* Corning410Imager::getFrame(unsigned short* buffer) +{ + m_imager.get_frame(buffer); + + return buffer; +} + +void Corning410Imager::setSpectraBin(int new_spectral_bin) +{ + +} + +double Corning410Imager::getWavelengthAtBand(int band) +{ + return m_imager.get_wavelength_at_band(band); +} + +int Corning410Imager::getBandCount() +{ + return m_imager.get_band_count(); +} + +int Corning410Imager::getSampleCount() +{ + return m_imager.get_sample_count(); +} diff --git a/HPPA/Corning410Imager.h b/HPPA/Corning410Imager.h new file mode 100644 index 0000000..d3a03c3 --- /dev/null +++ b/HPPA/Corning410Imager.h @@ -0,0 +1,48 @@ +#pragma once +#include +#include + +#include "ImagerOperationBase.h" +#include "image2display.h" +#include "fileOperation.h" + +#include "irisximeaimager.h" +#include "path_tc.h" +#include "hppaConfigFile.h" + +class Corning410Imager :public ImagerOperationBase +{ + Q_OBJECT + +public: + Corning410Imager(); + ~Corning410Imager(); + + Iris::IrisXimeaImager m_imager; + + double getWavelengthAtBand(int band); + int getBandCount(); + int getSampleCount(); + double getFramerate(); + double getIntegrationTime(); + double getGain(); + void setFramerate(const double frames_per_second); + void setIntegrationTime(const double milliseconds); + void setGain(const double gain); + int getStartBand(); + int getEndBand(); + void connectImager(const char* camera_sn = NULL); + void disconnectImager(); + void imagerStartCollect(); + void imagerStopCollect(); + unsigned short* getFrame(unsigned short* buffer); + void setSpectraBin(int new_spectral_bin); + +protected: +private: + CorningConfigfile m_configfile; + +public slots: + +signals: +}; diff --git a/HPPA/HPPA.cpp b/HPPA/HPPA.cpp index 801211d..016163a 100644 --- a/HPPA/HPPA.cpp +++ b/HPPA/HPPA.cpp @@ -827,10 +827,11 @@ void HPPA::onLeftMouseButtonPressed(int x, int y) QLineSeries *series = new QLineSeries(); //series->clear();////////////////////////////// + int start = m_Imager->getStartBand(); for (size_t i = 0; i < m_Imager->getBandCount(); i++) { //malloc申请的内存用法1:可以当做数组用 - series->append(m_Imager->getWavelengthAtBand(i), data[i]); + series->append(m_Imager->getWavelengthAtBand(i + start), data[i]); ////malloc申请的内存用法2:指针存取 //series->append(m_Imager->getWavelengthAtBand(i), *data); @@ -1779,7 +1780,7 @@ void HPPA::onconnect() } else if (imagerSelected == "mActionCorning_410") { - + m_Imager = new Corning410Imager(); } else { diff --git a/HPPA/HPPA.h b/HPPA/HPPA.h index 4d65c6f..92b2715 100644 --- a/HPPA/HPPA.h +++ b/HPPA/HPPA.h @@ -39,6 +39,7 @@ #include "path_tc.h" #include "ResononNirImager.h" +#include "Corning410Imager.h" #define PI 3.1415926 diff --git a/HPPA/HPPA.vcxproj b/HPPA/HPPA.vcxproj index c70716c..be8fbfd 100644 --- a/HPPA/HPPA.vcxproj +++ b/HPPA/HPPA.vcxproj @@ -55,8 +55,8 @@ - D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;$(IncludePath) - D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;$(LibraryPath) + D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;D:\cpp_library\vincecontrol_vs2017;C:\XIMEA\API\xiAPI;$(IncludePath) + D:\cpp_library\opencv3.4.11\opencv\build\x64\vc15\lib;D:\cpp_library\gdal2.2.3_vs2017\lib;C:\Program Files\ResononAPI\lib64;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\x64\Debug;D:\cpp_library\libconfig-1.7.3\build\x64;D:\cpp_project_vs2022\HPPA\x64\Debug;C:\XIMEA\API\xiAPI;$(LibraryPath) D:\cpp_library\gdal2.2.3_vs2017\include;C:\Program Files\ResononAPI\include;D:\cpp_library\opencv3.4.11\opencv\build\include;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv;D:\cpp_library\opencv3.4.11\opencv\build\include\opencv2;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PCOMM\Include;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL\SDKs\PortControl;D:\cpp_project_vs2022\AutoFocus_InspireLinearMotor_DLL\AutoFocus_InspireLinearMotor_DLL;D:\cpp_project_vs2022\HPPA\HPPA;D:\cpp_library\libconfig-1.7.3\lib;D:\cpp_project_vs2022\HPPA\vincecontrol;$(IncludePath) @@ -64,7 +64,7 @@ - opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;%(AdditionalDependencies) + opencv_world3411.lib;opencv_world3411d.lib;gdal_i.lib;resonon-basler.lib;AutoFocus_InspireLinearMotor_DLL.lib;libconfig++d.lib;vincecontrol.lib;resonon-allied.lib;xiapi64.lib;%(AdditionalDependencies) D:\cpp_project_vs2022\HPPA\x64\Debug;%(AdditionalLibraryDirectories) @@ -106,8 +106,11 @@ + + + @@ -156,6 +159,9 @@ + + + diff --git a/HPPA/HPPA.vcxproj.filters b/HPPA/HPPA.vcxproj.filters index 1b7ece5..af89eb9 100644 --- a/HPPA/HPPA.vcxproj.filters +++ b/HPPA/HPPA.vcxproj.filters @@ -21,6 +21,12 @@ {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} ts + + {eadfac5f-f4f9-49e2-9f99-0849bf074cf8} + + + {4672856c-86fb-46e3-94ff-0a296dcc6111} + @@ -109,6 +115,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + @@ -159,6 +174,9 @@ Header Files + + Header Files + @@ -185,6 +203,12 @@ Header Files + + Header Files + + + Header Files + diff --git a/HPPA/hppaConfigFile.cpp b/HPPA/hppaConfigFile.cpp index 2fc8371..81fd30d 100644 --- a/HPPA/hppaConfigFile.cpp +++ b/HPPA/hppaConfigFile.cpp @@ -397,3 +397,529 @@ bool Configfile::updateConfigFile() return true; } + + + + +CorningConfigfile::CorningConfigfile() +{ + +} + +void CorningConfigfile::setConfigfilePath(string configfilePath) +{ + m_configfilePath = configfilePath; +} + +bool CorningConfigfile::isConfigfileExist() +{ + QFileInfo info(QString::fromStdString(m_configfilePath)); + + return info.exists(); +} + +bool CorningConfigfile::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 false; + } + catch (const ParseException& pex) + { + std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError() << std::endl; + return false; + } +} + +bool CorningConfigfile::getSpectralBin(int& spectralBin) +{ + try + { + spectralBin = cfg.lookup("spectralBin"); + + return true; + } + catch (const SettingNotFoundException& nfex) + { + cerr << "No 'spectralBin' setting in configuration file." << endl; + return false; + } +} + +bool CorningConfigfile::getspatialBin(int& spatialBin) +{ + try + { + spatialBin = cfg.lookup("spatialBin"); + + return true; + } + catch (const SettingNotFoundException& nfex) + { + cerr << "No 'spatialBin' setting in configuration file." << endl; + return false; + } +} + +bool CorningConfigfile::getEffectiveWindow(int& width, int& offsetx, int& height, int& offsety) +{ + const Setting& root = cfg.getRoot(); + + try + { + int spatialBin; + int spectralBin; + getspatialBin(spatialBin); + getSpectralBin(spectralBin); + + string spatialBinString; + if (spatialBin == 1) + { + spatialBinString = "bin1"; + } + else + { + spatialBinString = "bin2"; + } + const Setting& spatialArgument = root["effective_window"][spatialBinString]["spatial"]; + if (!(spatialArgument.lookupValue("width", width) + && spatialArgument.lookupValue("offsetx", offsetx))) + { + return false; + } + + string spectralBinString; + if (spectralBin == 1) + { + spectralBinString = "bin1"; + } + else + { + spectralBinString = "bin2"; + } + const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"]; + if (!(spectralArgument.lookupValue("height", height) + && spectralArgument.lookupValue("offsety", offsety))) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + // Ignore. + return false; + } + + return true; +} + +bool CorningConfigfile::getEffectiveWindowRoi(int& width, int& offsetx) +{ + const Setting& root = cfg.getRoot(); + + try + { + const Setting& effective_window = root["effective_window_roi"]; + int count = effective_window.getLength(); + + int spatialBin; + getspatialBin(spatialBin); + + string spatialBinString; + if (spatialBin == 1) + { + spatialBinString = "spatialBin1"; + } + else + { + spatialBinString = "spatialBin2"; + } + + const Setting& window = effective_window[spatialBinString]; + 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 CorningConfigfile::getPushFlowParam(int& flowSwitch, int& rgbHeight, int& framerateVideo) +{ + Setting& root = cfg.getRoot(); + + if (!root.exists("push_flow_param")) + { + // 配置项不存在,添加配置项 + Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup); + + push_flow_param.add("flow_switch", Setting::TypeInt) = 0; + push_flow_param.add("rgb_height", Setting::TypeInt) = 720; + push_flow_param.add("framerate_video", Setting::TypeInt) = 5; + + // 保存修改后的配置到文件 + try + { + QList fileInfo = getFileInfo(QString::fromStdString(m_configfilePath)); + bool ret = createDir(fileInfo[0]); + + cfg.writeFile(m_configfilePath.c_str()); + std::cout << "Config item 'push_flow_param' added." << std::endl; + + flowSwitch = 0; + rgbHeight = 720; + framerateVideo = 5; + + return true; + } + catch (const libconfig::FileIOException& fioex) + { + std::cerr << "I/O error while writing file." << std::endl; + return false; + } + } + else + { + try + { + const Setting& push_flow_param = root["push_flow_param"]; + + if (!(push_flow_param.lookupValue("rgb_height", rgbHeight) + && push_flow_param.lookupValue("framerate_video", framerateVideo) + && push_flow_param.lookupValue("flow_switch", flowSwitch) + )) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + // Ignore. + return false; + } + + return true; + } +} + +bool CorningConfigfile::getWindowOffsety_HeightOfSpectral(int& offsety, int& height, string spectralBinString) +{ + const Setting& root = cfg.getRoot(); + + try + { + const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"]; + if (!(spectralArgument.lookupValue("height", height) + && spectralArgument.lookupValue("offsety", offsety))) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + // Ignore. + return false; + } + + return true; +} + +bool CorningConfigfile::getGainOffset(float& gain, float& offset) +{ + const Setting& root = cfg.getRoot(); + + try + { + const Setting& gainOffset = root["gainOffset"]; + int count = gainOffset.getLength(); + + int spectralBin; + getSpectralBin(spectralBin); + + string spectralBinString; + if (spectralBin == 1) + { + spectralBinString = "spectralBin1"; + } + else + { + spectralBinString = "spectralBin2"; + } + + const Setting& gainOffsetSetting = gainOffset[spectralBinString]; + string name = gainOffsetSetting.getName(); + + if (!(gainOffsetSetting.lookupValue("gain", gain) + && gainOffsetSetting.lookupValue("offset", offset))) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + // Ignore. + return false; + } + + return true; +} + +bool CorningConfigfile::getGainOffsetOfSpectralBin1(float& gain, float& offset) +{ + const Setting& root = cfg.getRoot(); + + try + { + const Setting& gainOffset = root["gainOffset"]; + int count = gainOffset.getLength(); + + string spectralBinString = "spectralBin1"; + + const Setting& gainOffsetSetting = gainOffset[spectralBinString]; + string name = gainOffsetSetting.getName(); + + if (!(gainOffsetSetting.lookupValue("gain", gain) + && gainOffsetSetting.lookupValue("offset", offset))) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + // Ignore. + return false; + } + + return true; +} + +bool CorningConfigfile::getSN(QString& SN) +{ + try + { + std::string SN_tem = cfg.lookup("SN"); + SN = QString::fromStdString(SN_tem); + + return true; + } + catch (const SettingNotFoundException& nfex) + { + cerr << "No 'spectralBin' setting in configuration file." << endl; + return false; + } +} + +bool CorningConfigfile::getBufferPolicy(int& bufferPolicy) +{ + const Setting& root = cfg.getRoot(); + const Setting& ximeadll = root["ximeadll"]; + + try + { + if (!(ximeadll.lookupValue("buffer_policy", bufferPolicy) + )) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + cerr << "No 'spectralBin' setting in configuration file." << endl; + return false; + } + + return true; +} + +bool CorningConfigfile::getAcqBufferSize(int& acqBufferSize) +{ + const Setting& root = cfg.getRoot(); + const Setting& ximeadll = root["ximeadll"]; + + try + { + if (!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize) + )) + { + return false; + } + } + catch (const SettingNotFoundException& nfex) + { + cerr << "No 'spectralBin' setting in configuration file." << endl; + return false; + } + + return true; +} + +bool CorningConfigfile::createConfigFile() +{ + using namespace std; + using namespace libconfig; + + Config cfg; + + Setting& root = cfg.getRoot(); + + // Add some settings to the configuration. + Setting& SN = root.add("SN", Setting::TypeString) = "0098"; + Setting& spatialBin = root.add("spatialBin", Setting::TypeInt) = 2; + Setting& SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2; + + Setting& effective_window = root.add("effective_window", Setting::TypeGroup); + Setting& effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup); + Setting& effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup); + Setting& effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup); + Setting& effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup); + Setting& effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup); + Setting& effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup); + + effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368; + effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288; + effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300; + effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348; + + effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688; + effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144; + effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150; + effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174; + + Setting& effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup); + Setting& effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup); + Setting& effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup); + + effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364; + effective_window_roi_spatialBin1.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_spatialBin2.add("width", Setting::TypeInt) = 682; + effective_window_roi_spatialBin2.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& gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup); + Setting& gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup); + + gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433; + gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585; + + gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868; + gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176; + + + Setting& ximeadll = root.add("ximeadll", Setting::TypeGroup); + ximeadll.add("buffer_policy", Setting::TypeInt) = 0; + ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400; + + Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup); + push_flow_param.add("flow_switch", Setting::TypeInt) = 1; + push_flow_param.add("rgb_height", Setting::TypeInt) = 720; + push_flow_param.add("framerate_video", Setting::TypeInt) = 5; + + // Write out the new configuration. + try + { + cfg.writeFile(m_configfilePath.c_str()); + cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl; + + } + catch (const FileIOException& fioex) + { + cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl; + return true; + } + + return true; +} + +bool CorningConfigfile::updateConfigFile() +{ + using namespace std; + using namespace libconfig; + + static const char* output_file = "updated.cfg"; + + Config cfg; + + cfg.setOptions(Config::OptionFsync + | Config::OptionSemicolonSeparators + | Config::OptionColonAssignmentForGroups + | Config::OptionOpenBraceOnSeparateLine); + + // Read the file. If there is an error, report it and exit. + try + { + cfg.readFile("example.cfg"); + } + catch (const FileIOException& fioex) + { + std::cerr << "I/O error while reading file." << std::endl; + return false; + } + catch (const ParseException& pex) + { + std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() + << " - " << pex.getError() << std::endl; + return false; + } + + // Find the 'movies' setting. Add intermediate settings if they don't yet + // exist. + Setting& root = cfg.getRoot(); + + if (!root.exists("inventory")) + root.add("inventory", Setting::TypeGroup); + + Setting& inventory = root["inventory"]; + + if (!inventory.exists("movies")) + inventory.add("movies", Setting::TypeList); + + Setting& movies = inventory["movies"]; + + // Create the new movie entry. + Setting& movie = movies.add(Setting::TypeGroup); + + movie.add("title", Setting::TypeString) = "Buckaroo Banzai"; + movie.add("media", Setting::TypeString) = "DVD"; + movie.add("price", Setting::TypeFloat) = 12.99; + movie.add("qty", Setting::TypeInt) = 20; + + // Write out the updated configuration. + try + { + cfg.writeFile(output_file); + cerr << "Updated configuration successfully written to: " << output_file + << endl; + + } + catch (const FileIOException& fioex) + { + cerr << "I/O error while writing file: " << output_file << endl; + return false; + } + + return true; +} \ No newline at end of file diff --git a/HPPA/hppaConfigFile.h b/HPPA/hppaConfigFile.h index f40ec22..09d67d3 100644 --- a/HPPA/hppaConfigFile.h +++ b/HPPA/hppaConfigFile.h @@ -45,6 +45,36 @@ public: bool createConfigFile(); bool updateConfigFile(); +private: + string m_configfilePath; + Config cfg; +}; + +class CorningConfigfile +{ +public: + CorningConfigfile(); + void setConfigfilePath(string configfilePath); + bool isConfigfileExist(); + bool parseConfigfile(); + + bool getSpectralBin(int& spectralBin); + bool getspatialBin(int& spatialBin); + bool getEffectiveWindow(int& width, int& offsetx, int& height, int& offsety); + bool getEffectiveWindowRoi(int& width, int& offsetx); + bool getWindowOffsety_HeightOfSpectral(int& offsety, int& height, string spectralBinString);//spectralBinString = "bin1"或者”bin2“ + bool getGainOffset(float& gain, float& offset); + bool getGainOffsetOfSpectralBin1(float& gain, float& offset); + bool getSN(QString& SN); + + bool getBufferPolicy(int& bufferPolicy); + bool getAcqBufferSize(int& acqBufferSize); + + bool getPushFlowParam(int& flowSwitch, int& rgbHeight, int& framerateVideo); + + bool createConfigFile(); + bool updateConfigFile(); + private: string m_configfilePath; Config cfg; diff --git a/HPPA/imager_base.cpp b/HPPA/imager_base.cpp new file mode 100644 index 0000000..b4c6283 --- /dev/null +++ b/HPPA/imager_base.cpp @@ -0,0 +1,165 @@ +#include "imager_base.h" +Iris::ImagerBase::ImagerBase() +{ + +} + +Iris::ImagerBase::~ImagerBase() +{ + +} + +void Iris::ImagerBase::set_spectral_bin(int new_spectral_bin) +{ + +} + +int Iris::ImagerBase::get_spectral_bin() +{ + return 1; +} + +int Iris::ImagerBase::get_min_spectral_bin() +{ + return 1; +} + +int Iris::ImagerBase::get_max_spectral_bin() +{ + return 1; +} + +int Iris::ImagerBase::get_start_band() +{ + return 1; +} + +void Iris::ImagerBase::set_start_band(int band) +{ + +} + +int Iris::ImagerBase::get_min_start_band() +{ + return 1; +} + +int Iris::ImagerBase::get_max_start_band() +{ + return 1; +} + +int Iris::ImagerBase::get_inc_start_band() +{ + return 1; +} + +int Iris::ImagerBase::get_end_band() +{ + return 1; +} + +void Iris::ImagerBase::set_end_band(int band) +{ + +} + +int Iris::ImagerBase::get_min_end_band() +{ + return 1; +} + +int Iris::ImagerBase::get_max_end_band() +{ + return 1; +} + +int Iris::ImagerBase::get_inc_end_band() +{ + return 1; +} + +int Iris::ImagerBase::get_start_sample() +{ + return 1; +} + +void Iris::ImagerBase::set_start_sample(int sample) +{ + +} + +int Iris::ImagerBase::get_min_start_sample() +{ + return 1; +} + +int Iris::ImagerBase::get_max_start_sample() +{ + return 1; +} + +int Iris::ImagerBase::get_inc_start_sample() +{ + return 1; +} + +int Iris::ImagerBase::get_end_sample() +{ + return 1; +} + +void Iris::ImagerBase::set_end_sample(int sample) +{ + +} + +int Iris::ImagerBase::get_min_end_sample() +{ + return 1; +} + +int Iris::ImagerBase::get_max_end_sample() +{ + return 1; +} + +int Iris::ImagerBase::get_inc_end_sample() +{ + return 1; +} + +void Iris::ImagerBase::set_gain(const double gain) +{ + +} + +double Iris::ImagerBase::get_gain() +{ + return 1; +} + +double Iris::ImagerBase::get_min_gain() +{ + return 1; +} + +double Iris::ImagerBase::get_max_gain() +{ + return 1; +} + +void Iris::ImagerBase::set_internal_trigger() +{ + +} + +void Iris::ImagerBase::set_external_trigger(unsigned int signal_line, bool rising_edge) +{ + +} + +bool Iris::ImagerBase::is_trigger_external() +{ + return true; +} diff --git a/HPPA/imager_base.h b/HPPA/imager_base.h new file mode 100644 index 0000000..fdc129e --- /dev/null +++ b/HPPA/imager_base.h @@ -0,0 +1,93 @@ +/* + * Iris API + * + * By using this API, the user agrees to the terms and conditions as stated in the + * document "Terms of Use", located on the Resonon website + * at: http://www.resonon.com/downloads/Resonon_API_Terms_of_Use.pdf. + * + */ + + +#ifndef __GUARD_Iris_IMAGER_BASE_H +#define __GUARD_Iris_IMAGER_BASE_H + +#include +#include +//#include "irisximeaimager_global.h" + +/** + * The Iris namespace contains all public classes. + */ +namespace Iris +{ + /** + * An abstract base class which provides a common interface for all imagers. + */ + class ImagerBase + { + public: + ImagerBase(); + virtual ~ImagerBase(); + + + virtual void connect(const char * camera_sn=NULL)=0; + virtual void disconnect()=0; + virtual void start()=0; + virtual void stop()=0; + virtual void get_imager_type(char *buffer, int buffer_size)=0; + virtual void get_serial_number(char *buffer, int buffer_size)=0; + virtual void get_camera_serial_number(char *buffer, int buffer_size)=0; + virtual void generate_configuration_report(char *buffer, int buffer_size)=0; + virtual float get_coeff_a()=0; + virtual float get_coeff_b()=0; + virtual float get_coeff_c()=0; + virtual double get_wavelength_at_band(const int band)=0; + int get_nearest_band_to_wavelength(const double wavelength); + virtual int get_frame_buffer_size_in_bytes()=0; + virtual unsigned short* get_frame(unsigned short* buffer)=0; + virtual std::uint64_t get_last_timestamp()=0; + virtual std::uint64_t ticks_per_second()=0; + virtual void set_spectral_bin(int new_spectral_bin); + virtual int get_spectral_bin(); + virtual int get_min_spectral_bin(); + virtual int get_max_spectral_bin(); + virtual int get_band_count()=0; + virtual int get_start_band(); + virtual void set_start_band(int band); + virtual int get_min_start_band(); + virtual int get_max_start_band(); + virtual int get_inc_start_band(); + virtual int get_end_band(); + virtual void set_end_band(int band); + virtual int get_min_end_band(); + virtual int get_max_end_band(); + virtual int get_inc_end_band(); + virtual int get_sample_count()=0; + virtual int get_start_sample(); + virtual void set_start_sample(int sample); + virtual int get_min_start_sample(); + virtual int get_max_start_sample(); + virtual int get_inc_start_sample(); + virtual int get_end_sample(); + virtual void set_end_sample(int sample); + virtual int get_min_end_sample(); + virtual int get_max_end_sample(); + virtual int get_inc_end_sample(); + virtual void set_framerate(const double frames_per_second)=0; + virtual double get_framerate()=0; + virtual double get_min_framerate()=0; + virtual double get_max_framerate()=0; + virtual double get_min_integration_time()=0; + virtual double get_max_integration_time()=0; + virtual void set_integration_time(const double milliseconds)=0; + virtual double get_integration_time()=0; + virtual void set_gain(const double gain); + virtual double get_gain(); + virtual double get_min_gain(); + virtual double get_max_gain(); + virtual void set_internal_trigger(); + virtual void set_external_trigger(unsigned int signal_line, bool rising_edge=true); + virtual bool is_trigger_external(); + }; +} //end namespace Iris +#endif //end ifndef __GUARD_Iris_IMAGER_BASE_H diff --git a/HPPA/irisximeaimager.cpp b/HPPA/irisximeaimager.cpp new file mode 100644 index 0000000..d3c7835 --- /dev/null +++ b/HPPA/irisximeaimager.cpp @@ -0,0 +1,565 @@ +#include "irisximeaimager.h" +using namespace Iris; + +void Iris::IrisXimeaImager::setGainOffset(float gain, float offset) +{ + m_fGain = gain; + m_fOffset = offset; +} + +bool Iris::IrisXimeaImager::setSpectralBin(int spectralBin) +{ + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//鐢細XI_BIN_SELECT_HOST_CPU锛涢粯璁や负XI_BIN_SELECT_SENSOR(浼氭姤閿)锛屼笉鍙敤锛歑I_BIN_SELECT_DEVICE_FPGA + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL_MODE, XI_BIN_MODE_AVERAGE)); + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, spectralBin)); + printf("Iris::IrisXimeaImager::setSpectralBin----2 璁剧疆bin妯″紡涓篨I_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE 锛乗n"); + + +// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_SELECTOR, XI_DEC_SELECT_SENSOR)); +// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_VERTICAL, spectralBin)); + + + m_iSpectralBin = spectralBin; + + return true; +} + +bool Iris::IrisXimeaImager::setSpatialBin(int spatialBin) +{ + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_SELECTOR, XI_BIN_SELECT_HOST_CPU));//鐢細XI_BIN_SELECT_HOST_CPU锛涢粯璁や负XI_BIN_SELECT_SENSOR(浼氭姤閿)锛屼笉鍙敤锛歑I_BIN_SELECT_DEVICE_FPGA + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL_MODE, XI_BIN_MODE_AVERAGE)); + CE(xiSetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, spatialBin)); + printf("Iris::IrisXimeaImager::setSpatialBin----2 璁剧疆bin妯″紡涓篨I_PRM_BINNING_SELECTOR XI_BIN_MODE_AVERAGE 锛乗n"); + + +// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_SELECTOR, XI_DEC_SELECT_SENSOR)); +// CE(xiSetParamInt(m_xiH, XI_PRM_DECIMATION_HORIZONTAL, spatialBin)); + + m_iSpatialBin = spatialBin; + + return true; +} + +int Iris::IrisXimeaImager::getSpectralBin() +{ + int spectralBin = 0; + CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_VERTICAL, &spectralBin)); + +// CE(xiGetParamInt(m_xiH, XI_PRM_DECIMATION_VERTICAL, &spectralBin)); + + return spectralBin; +} + +int Iris::IrisXimeaImager::getSpatialBin() +{ + int spatialBin = 0; + CE(xiGetParamInt(m_xiH, XI_PRM_BINNING_HORIZONTAL, &spatialBin)); + +// CE(xiGetParamInt(m_xiH, XI_PRM_DECIMATION_HORIZONTAL, &spatialBin)); + + return spatialBin; +} + +void Iris::IrisXimeaImager::setEffectiveWindow(int OffsetX, int width, int OffsetY, int height) +{ + CE(xiSetParamInt(m_xiH, XI_PRM_WIDTH, width)); + CE(xiSetParamInt(m_xiH, XI_PRM_OFFSET_X, OffsetX)); + + CE(xiSetParamInt(m_xiH, XI_PRM_HEIGHT, height)); + CE(xiSetParamInt(m_xiH, XI_PRM_OFFSET_Y, OffsetY)); + + m_iEffectiveWindow_OffsetX = OffsetX; + m_iEffectiveWindow_width = width; + m_iEffectiveWindow_OffsetY = OffsetY; + m_iEffectiveWindow_height = height; +} + +void Iris::IrisXimeaImager::setEffectiveWindowRoi(int OffsetX, int width) +{ + m_iEffectiveWindowRoi_OffsetX = OffsetX; + m_iEffectiveWindowRoi_width = width; +} + +int Iris::IrisXimeaImager::getBufferSizeOfOneFrame() +{ +// if(m_xiH==NULL) +// return 0; +// +// start(); +// +// //娓呯┖image缂撳瓨 +// memset(&m_image, 0, sizeof(m_image)); +// m_image.size = sizeof(XI_IMG); +// +// CE(xiGetImage(m_xiH, 5000, &m_image)); // getting next image from the camera opened +// +// stop(); +// +// return static_cast(m_image.bp_size); + +// //姣斿疄闄呭ぇ灏忥紙m_iEffectiveWindow_height * m_iEffectiveWindow_width * 2锛夊ぇ锛寃hy锛 +// int value = 0; +// xiGetParamInt(m_xiH, XI_PRM_IMAGE_PAYLOAD_SIZE, &value); + + + return m_iEffectiveWindow_height * m_iEffectiveWindow_width * 2; +} + +float Iris::IrisXimeaImager::getTemperature() +{ + float temperature = 0.0; + CE(xiGetParamFloat(m_xiH, XI_PRM_TEMP, &temperature)); + + return temperature; +} + +void Iris::IrisXimeaImager::setBufferPolicy(int bufferPolicy) +{ + if (bufferPolicy==0) + { + xiSetParamInt(m_xiH, XI_PRM_BUFFER_POLICY, XI_BP_UNSAFE); + printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_UNSAFE\n"); + } + else if (bufferPolicy==1) + { + xiSetParamInt(m_xiH, XI_PRM_BUFFER_POLICY, XI_BP_SAFE); + printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFER_POLICY: XI_BP_SAFE\n"); + } +} + +void Iris::IrisXimeaImager::setAcqBufferSize(int acqBufferSize) +{ + XI_RETURN stat = XI_OK; + + // set unit to 1 MiB + xiSetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE_UNIT, 1024*1024); + int value = 0; + xiGetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, &value); + printf("Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB.\n", value); + + xiSetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, acqBufferSize); + + xiGetParamInt(m_xiH, XI_PRM_ACQ_BUFFER_SIZE, &value); + printf("Iris::IrisXimeaImager::connect---- XI_PRM_ACQ_BUFFER_SIZE: %d MiB.\n", value); + + // set maximum number of queue + int number_of_field_buffers = 0; + xiGetParamInt(m_xiH, XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX, &number_of_field_buffers); + printf("Iris::IrisXimeaImager::connect---- XI_PRM_BUFFERS_QUEUE_SIZE XI_PRM_INFO_MAX: %d.\n", number_of_field_buffers); + HandleResult(stat,"xiGetParam (number_of_field_buffers maximum)"); + xiSetParamInt(m_xiH, XI_PRM_BUFFERS_QUEUE_SIZE, number_of_field_buffers); + HandleResult(stat,"xiSetParam (number_of_field_buffers)"); +} + +Iris::IrisXimeaImager::IrisXimeaImager() +{ + m_xiH=NULL; + + //std::cout<<"ximeaControlDll 鐗堟湰锛"<< "21." < +#include +#include + +//#include "irisximeaimager_global.h" +#include "imager_base.h" +#ifdef WIN32 +#include // Windows +#else +#include // Linux, OSX +#endif + +#define CE(func) {XI_RETURN stat = (func); if (XI_OK!=stat) {printf("Error:%d returned from function:"#func"\n",stat);throw stat;}} +#define HandleResult(res,place) if (res!=XI_OK) {printf("Error after %s (%d)\n",place,res);} + +namespace Iris +{ + class IrisXimeaImager:public ImagerBase + { + public: + HANDLE m_xiH; + void setGainOffset(float gain, float offset); + bool setSpectralBin(int spectralBin); + bool setSpatialBin(int spatialBin); + int getSpectralBin(); + int getSpatialBin(); + void setEffectiveWindow(int OffsetX, int width, int OffsetY, int height); + void setEffectiveWindowRoi(int OffsetX, int width); + int getBufferSizeOfOneFrame(); + float getTemperature(); + + XI_IMG m_image; // image buffer + + void setBufferPolicy(int bufferPolicy);//0:XI_BP_UNSAFE; 1:XI_BP_SAFE; + void setAcqBufferSize(int acqBufferSize);//鍗曚綅MiB + + public: + //缁ф壙鍩虹被鐨 + IrisXimeaImager();//11111111111111111111 + virtual ~IrisXimeaImager(); + + void connect(const char * camera_serial_number=NULL);//111111111111111111111111111111111 + void disconnect();//111111111111111111111111111111 + void start();//111111111111111111111 + void stop();//1111111111111111111111 + void get_imager_type(char *buffer, int buffer_size); + void get_serial_number(char *buffer, int buffer_size); + void get_camera_serial_number(char *buffer, int buffer_size); + void generate_configuration_report(char *buffer, int buffer_size); + float get_coeff_a(); + float get_coeff_b(); + float get_coeff_c(); + double get_wavelength_at_band(const int band);//11111111111111111111 + int get_frame_buffer_size_in_bytes(); + unsigned short* get_frame(unsigned short* buffer);//11111111111111111111111 + std::uint64_t get_last_timestamp(); + std::uint64_t ticks_per_second(); + void set_spectral_bin(int new_spectral_bin);//11111111111111111111111111111111 + int get_spectral_bin(); + int get_min_spectral_bin(); + int get_max_spectral_bin(); + int get_band_count();//11111111111111111111 + int get_start_band();//瀵瑰簲涓婁竴鐗堟湰api鐨勫嚱鏁:get_window_start_band + void set_start_band(int band); + int get_min_start_band(); + int get_max_start_band(); + int get_inc_start_band(); + int get_end_band();//瀵瑰簲涓婁竴鐗堟湰api鐨勫嚱鏁:get_window_end_band + void set_end_band(int band); + int get_min_end_band(); + int get_max_end_band(); + int get_inc_end_band(); + int get_sample_count();//11111111111111111 + int get_start_sample(); + void set_start_sample(int sample); + int get_min_start_sample(); + int get_max_start_sample(); + int get_inc_start_sample(); + int get_end_sample(); + void set_end_sample(int sample); + int get_min_end_sample(); + int get_max_end_sample(); + int get_inc_end_sample(); + void set_framerate(const double frames_per_second);//11111111111111111111111111111111 + double get_framerate();//1111111111111111111111 + double get_min_framerate(); + double get_max_framerate(); + double get_min_integration_time(); + double get_max_integration_time(); + void set_integration_time(const double microsecond);//111111111111111111111 + double get_integration_time();//1111111111111111111111111111111 + void set_gain(const double gain);//111111111111 + double get_gain();//111111111111 + double get_min_gain(); + double get_max_gain(); + void set_internal_trigger(); + void set_external_trigger(unsigned int signal_line, bool rising_edge=true); + bool is_trigger_external(); + protected: + private: + uint64_t m_timestampOfCamera; + + int m_iSpectralBin; + int m_iSpatialBin; + + int m_iEffectiveWindow_OffsetX; + int m_iEffectiveWindow_width; + int m_iEffectiveWindow_OffsetY; + int m_iEffectiveWindow_height; + + int m_iEffectiveWindowRoi_OffsetX; + int m_iEffectiveWindowRoi_width; + + float m_fGain; + float m_fOffset; + + }; +} + +#endif // IRISXIMEAIMAGER_H