1、添加配置文件读、写、解析类Configfile(使用libconfig.h++);
2、打开相机时,通过Configfile读取和解析配置文件,并使用; 3、修复一些代码逻辑bug;
This commit is contained in:
@ -16,7 +16,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
find_package(Qt5 REQUIRED ${QT})#
|
||||
|
||||
include_directories(.)
|
||||
include_directories(../IrisXimeaImager)
|
||||
include_directories(../IrisXimeaImager/Header_Files)
|
||||
include_directories(../ellipse_n_sdk/SoftwareDevelopment/sbgECom/src)
|
||||
#include_directories(/home/rock/tc_projects/ellipse_n_sdk/SoftwareDevelopment/sbgECom/src/)
|
||||
include_directories(../ellipse_n_sdk/SoftwareDevelopment/sbgECom/common)
|
||||
@ -46,8 +46,12 @@ add_executable(${CMAKE_PROJECT_NAME}
|
||||
Source_Files/utility_tc.cpp
|
||||
Header_Files/utility_tc.h
|
||||
Source_Files/ximeaimager.cpp
|
||||
Header_Files/ximeaimager.h)
|
||||
Header_Files/ximeaimager.h
|
||||
Source_Files/configfile.cpp
|
||||
Header_Files/configfile.h)
|
||||
qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT})
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
irisXimeaImager)
|
||||
irisXimeaImager
|
||||
libconfig.so
|
||||
libconfig++.so)
|
||||
|
40
Header_Files/configfile.h
Normal file
40
Header_Files/configfile.h
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Created by tangchao on 2022/6/28.
|
||||
//
|
||||
|
||||
#ifndef XIMEAIMAGERECORDER_CONFIGFILE_H
|
||||
#define XIMEAIMAGERECORDER_CONFIGFILE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdlib>
|
||||
#include <libconfig.h++>
|
||||
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
class Configfile
|
||||
{
|
||||
|
||||
public:
|
||||
Configfile();
|
||||
void setConfigfilePath(string configfilePath);
|
||||
int parseConfigfile();
|
||||
|
||||
bool getBin(int &bin);
|
||||
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
|
||||
bool getGainOffset(float &gain, float &offset);
|
||||
|
||||
int createConfigFile();
|
||||
int updateConfigFile();
|
||||
|
||||
private:
|
||||
string m_configfilePath;
|
||||
Config cfg;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //XIMEAIMAGERECORDER_CONFIGFILE_H
|
@ -29,6 +29,8 @@
|
||||
#include <QObject>
|
||||
#include <qthread.h>
|
||||
|
||||
#include "configfile.h"
|
||||
|
||||
#include "irisximeaimager.h"
|
||||
#include "math.h"
|
||||
#include "utility_tc.h"
|
||||
@ -102,6 +104,8 @@ private:
|
||||
return nanosecondSystem-TimeDifferenceBetweensOSAndSbg;
|
||||
}
|
||||
|
||||
Configfile m_configfile;
|
||||
|
||||
public slots:
|
||||
void openImger();
|
||||
void closeImger();
|
||||
|
240
Source_Files/configfile.cpp
Normal file
240
Source_Files/configfile.cpp
Normal file
@ -0,0 +1,240 @@
|
||||
//
|
||||
// Created by tangchao on 2022/6/28.
|
||||
//
|
||||
|
||||
#include "Header_Files/configfile.h"
|
||||
|
||||
Configfile::Configfile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Configfile::setConfigfilePath(string configfilePath)
|
||||
{
|
||||
m_configfilePath = configfilePath;
|
||||
}
|
||||
|
||||
|
||||
int Configfile::parseConfigfile()
|
||||
{
|
||||
// Read the file. If there is an error, report it and exit.
|
||||
try
|
||||
{
|
||||
cfg.readFile(m_configfilePath);
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
std::cerr << "I/O error while reading file." << std::endl;
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
catch(const ParseException &pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
bool Configfile::getBin(int &bin)
|
||||
{
|
||||
try
|
||||
{
|
||||
bin = cfg.lookup("bin");
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'bin' setting in configuration file." << endl;
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
// Output a list of all books in the inventory.
|
||||
try
|
||||
{
|
||||
const Setting &effective_window = root["effective_window"];
|
||||
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)
|
||||
&& window.lookupValue("height", height)
|
||||
&& window.lookupValue("offsety", offsety)))
|
||||
{
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
int a=1;
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
bool Configfile::getGainOffset(float &gain, float &offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
// Output a list of all books in the inventory.
|
||||
try
|
||||
{
|
||||
const Setting &gainOffset = root["gainOffset"];
|
||||
int count = gainOffset.getLength();
|
||||
|
||||
int bin;
|
||||
getBin(bin);
|
||||
|
||||
const Setting &gainOffsetSetting = gainOffset[bin-1];
|
||||
string name = gainOffsetSetting.getName();
|
||||
|
||||
if(!(gainOffsetSetting.lookupValue("gain", gain)
|
||||
&& gainOffsetSetting.lookupValue("offset", offset)))
|
||||
{
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
int a=1;
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int Configfile::createConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
static const char *output_file = "ximea.cfg";
|
||||
Config cfg;
|
||||
|
||||
Setting &root = cfg.getRoot();
|
||||
|
||||
// Add some settings to the configuration.
|
||||
Setting &bin = root.add("bin", Setting::TypeInt) = 1;
|
||||
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);
|
||||
|
||||
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_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;
|
||||
|
||||
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;
|
||||
|
||||
gainOffsetBin2.add("gain", Setting::TypeFloat) = 11.789;
|
||||
gainOffsetBin2.add("offset", Setting::TypeFloat) = -12.58;
|
||||
|
||||
|
||||
// Write out the new configuration.
|
||||
try
|
||||
{
|
||||
cfg.writeFile(output_file);
|
||||
cerr << "New configuration successfully written to: " << output_file << endl;
|
||||
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
cerr << "I/O error while writing file: " << output_file << endl;
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int Configfile::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(EXIT_FAILURE);
|
||||
}
|
||||
catch(const ParseException &pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// 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(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
@ -8,6 +8,11 @@ XimeaImager::XimeaImager()
|
||||
m_iImagerState=100;
|
||||
|
||||
//connect(this, SIGNAL(recordFinished()),this, SLOT());
|
||||
|
||||
m_configfile.setConfigfilePath("ximea.cfg");
|
||||
m_configfile.parseConfigfile();
|
||||
|
||||
// m_configfile.createConfigFile();
|
||||
}
|
||||
|
||||
void XimeaImager::openImger()
|
||||
@ -24,40 +29,22 @@ void XimeaImager::openImger()
|
||||
//std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<<std::endl;
|
||||
m_imager.connect();
|
||||
|
||||
// bool haha = m_imager.setSpectralBin(2);
|
||||
// bool haha2 = m_imager.setSpatialBin(2);
|
||||
int bin=0;
|
||||
m_configfile.getBin(bin);
|
||||
bool haha = m_imager.setSpectralBin(bin);
|
||||
bool haha2 = m_imager.setSpatialBin(bin);
|
||||
|
||||
//sn008_bin1
|
||||
float a=1.999564;
|
||||
float b=-279.893;
|
||||
// //sn008_bin2
|
||||
// float a = 3.99912794;
|
||||
// float b = -278.89317732225084;
|
||||
float gain, offset;//用于生成头文件中的波长信息
|
||||
m_configfile.getGainOffset(gain, offset);
|
||||
m_imager.setGainOffset(gain, offset);
|
||||
|
||||
m_imager.setGainOffset(a, b);
|
||||
|
||||
|
||||
//SN=008自己修改
|
||||
// int OffsetX=272;
|
||||
// int width=1392;
|
||||
//
|
||||
// int OffsetY=338;
|
||||
// int height=302;
|
||||
//
|
||||
// //SN=008标准
|
||||
// int OffsetX=288;//272
|
||||
// int width=1360;//是16的整数倍
|
||||
//
|
||||
// int OffsetY=340;
|
||||
// int height=300;//302
|
||||
|
||||
|
||||
// m_imager.setRoi(288,1360,348,300);//sn0098
|
||||
m_imager.setRoi(288,1360,340,300);//sn008,corning410,bin1
|
||||
// m_imager.setRoi(144,680,170,151);//sn008,corning410,bin2
|
||||
int width = 0, offsetx = 0, height = 0, offsety = 0;
|
||||
m_configfile.getEffectiveWindow(width, offsetx, height, offsety);
|
||||
m_imager.setRoi(offsetx, width, offsety, height);
|
||||
|
||||
setFramerate(100);
|
||||
|
||||
//经验证:frameSizeManual和frameSizeAuto相等
|
||||
int frameSizeManual = m_imager.get_band_count()*m_imager.get_sample_count()*2;
|
||||
int frameSizeAuto = m_imager.getBufferSizeOfOneFrame();
|
||||
|
||||
@ -128,13 +115,13 @@ double XimeaImager::getExposureTime()
|
||||
try
|
||||
{
|
||||
exposureTime=m_imager.get_integration_time();
|
||||
return exposureTime;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return exposureTime;
|
||||
}
|
||||
|
||||
double XimeaImager::setExposureTime(float exposureTime_in_us)
|
||||
@ -161,14 +148,14 @@ double XimeaImager::setExposureTime(float exposureTime_in_us)
|
||||
|
||||
//返回设置的积分时间
|
||||
integrationTime2Return=m_imager.get_integration_time();
|
||||
|
||||
return integrationTime2Return;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return integrationTime2Return;
|
||||
}
|
||||
|
||||
double XimeaImager::autoExposure()
|
||||
@ -226,14 +213,19 @@ double XimeaImager::autoExposure()
|
||||
|
||||
m_iImagerState=103;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
std::cout<<"自动曝光完成!"<<std::endl;
|
||||
return exposureTime;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
|
||||
std::cout<<"自动曝光失败!"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout<<"自动曝光完成!"<<std::endl;
|
||||
return exposureTime;
|
||||
|
||||
}
|
||||
|
||||
double XimeaImager::getFramerate()
|
||||
@ -243,13 +235,15 @@ double XimeaImager::getFramerate()
|
||||
try
|
||||
{
|
||||
framerate=m_imager.get_framerate();
|
||||
|
||||
return framerate;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
}
|
||||
|
||||
return framerate;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void XimeaImager::setGain(double gain)
|
||||
@ -273,23 +267,22 @@ double XimeaImager::getGain()
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int XimeaImager::getSampleCount()
|
||||
{
|
||||
int sampleCount;
|
||||
|
||||
try
|
||||
{
|
||||
sampleCount=m_imager.get_sample_count();
|
||||
int sampleCount=m_imager.get_sample_count();
|
||||
return sampleCount;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sampleCount;
|
||||
}
|
||||
|
||||
int XimeaImager::getBandCount()
|
||||
@ -299,13 +292,13 @@ int XimeaImager::getBandCount()
|
||||
try
|
||||
{
|
||||
bandCount=m_imager.get_band_count();
|
||||
return bandCount;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return bandCount;
|
||||
}
|
||||
|
||||
int XimeaImager::getWindowStartBand()
|
||||
@ -315,13 +308,13 @@ int XimeaImager::getWindowStartBand()
|
||||
try
|
||||
{
|
||||
windowStartBand=m_imager.get_start_band();
|
||||
return windowStartBand;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return windowStartBand;
|
||||
}
|
||||
|
||||
int XimeaImager::getWindowEndBand()
|
||||
@ -331,13 +324,13 @@ int XimeaImager::getWindowEndBand()
|
||||
try
|
||||
{
|
||||
windowEndBand=m_imager.get_end_band();
|
||||
return windowEndBand;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return windowEndBand;
|
||||
}
|
||||
|
||||
double XimeaImager::geWavelengthAtBand(int x)
|
||||
@ -347,13 +340,13 @@ double XimeaImager::geWavelengthAtBand(int x)
|
||||
try
|
||||
{
|
||||
wavelengthAtBand=m_imager.get_wavelength_at_band(x);
|
||||
return wavelengthAtBand;
|
||||
}
|
||||
catch(int xiApiErrorCodes)
|
||||
{
|
||||
processXiApiErrorCodes(xiApiErrorCodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return wavelengthAtBand;
|
||||
}
|
||||
|
||||
int XimeaImager::getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel)
|
||||
|
3
记录-杂七杂八.txt
Normal file
3
记录-杂七杂八.txt
Normal file
@ -0,0 +1,3 @@
|
||||
全名:Tang, chao
|
||||
邮件地址:chao.tang@servirst.com
|
||||
box密码:Tangchao123456,
|
Reference in New Issue
Block a user