1. 读写配置文件类(Configfile):1)修复一些返回值bug,2)添加读写 裁剪有效窗口的参数 的函数getEffectiveWindowRoi;

2. 在没有采集数据时,读取ximea温度,并写入到csv文件中;
3. 在另外的工程更新了ximea控制类(Iris::IrisXimeaImager),并在此工程加入此更新:从获取的有效窗口中裁剪需要的数据,m_imager.setEffectiveWindowRoi();
4. 在函数XimeaImager::processXiApiErrorCodes中,增加处理ximea错误码12;
This commit is contained in:
tangchao0503
2022-08-15 17:36:19 +08:00
parent 84882c5edb
commit 8aa402bd5d
5 changed files with 226 additions and 54 deletions

View File

@ -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:正在打开相机!"<<std::endl;
m_imager.connect();
bool ret;
int bin=0;
m_configfile.getBin(bin);
bool haha = m_imager.setSpectralBin(bin);
bool haha2 = m_imager.setSpatialBin(bin);
ret = m_configfile.getBin(bin);
if (ret)
{
bool haha = m_imager.setSpectralBin(bin);
bool haha2 = m_imager.setSpatialBin(bin);
}
float gain, offset;//用于生成头文件中的波长信息
m_configfile.getGainOffset(gain, offset);
m_imager.setGainOffset(gain, offset);
ret = m_configfile.getGainOffset(gain, offset);
if (ret)
{
m_imager.setGainOffset(gain, offset);
}
int width = 0, offsetx = 0, height = 0, offsety = 0;
m_configfile.getEffectiveWindow(width, offsetx, height, offsety);
m_imager.setRoi(offsetx, width, offsety, height);
ret = m_configfile.getEffectiveWindow(width, offsetx, height, offsety);
if (ret)
{
m_imager.setEffectiveWindow(offsetx, width, offsety, height);
}
int width_roi = 0, offsetx_roi = 0;
ret = m_configfile.getEffectiveWindowRoi(width_roi, offsetx_roi);
if (ret)
{
m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi);
}
setFramerate(100);
@ -54,6 +79,9 @@ void XimeaImager::openImger()
m_iImagerState = 101;
emit ximeaImageStatus(m_iImagerState);
m_ximeaTemperatureCSVPath = "/home/rock/programRunLog/ximeaTemperature.csv";
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);
}
catch(int xiApiErrorCodes)
{
@ -69,6 +97,8 @@ void XimeaImager::openImger()
void XimeaImager::closeImger()
{
m_ximeaTemperature->stopRecordTemperature();
if(m_iImagerState==100)
{
emit ximeaImageStatus(m_iImagerState);
@ -88,6 +118,8 @@ void XimeaImager::closeImger()
std::cout<<"XimeaImager::closeImger-------------------!"<<std::endl;
processXiApiErrorCodes(xiApiErrorCodes);
}
}
void XimeaImager::setFramerate(double framerate)
@ -359,9 +391,15 @@ int XimeaImager::getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel)
unsigned short maxValue=0;
for(int i=0;i<numberOfPixel;i++)
{
if (data[i]>maxValue)
// std::cout<<"像素值为:"<< *(data + i) <<std::endl;
if (*(data + i)>maxValue)
{
maxValue=data[i];
//std::cout<<"像素值为:"<< *(data + i) <<std::endl;
maxValue=*(data + i);
}
if (*(data + i)==65535)
{
int a=0;
}
}
printf("本帧最大值为: %d.\n",maxValue);
@ -376,6 +414,7 @@ int XimeaImager::getImagerState() const
void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName)
{
m_ximeaTemperature->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<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
std::cout<<"采集时间为: "<<runTime<<std::endl;
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
std::cout<<"理论采集帧数为: "<<frameInTheory<<std::endl;
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
std::cout<<"丢帧率为: "<<frameLossRate<<std::endl;
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
fclose(hFile);
fclose(hHimesFile);
@ -472,6 +515,8 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
emit ximeaImageStatus(m_iImagerState);
emit recordFinished();
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);//停止采集影像后,继续获取传感器温度;
}
catch(int xiApiErrorCodes)
{
@ -594,6 +639,12 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
m_iImagerState=xiApiErrorCodes;
emit ximeaImageStatus(m_iImagerState);
break;
case 12:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
m_iImagerState=xiApiErrorCodes;
emit ximeaImageStatus(m_iImagerState);
break;
case 15:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Memory allocation error!"<<std::endl;
@ -639,3 +690,39 @@ int XimeaImager::getFrameCounter()
{
return m_iFrameCounter;
}
RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager)
{
m_imager = imager;
m_bIsRecord = true;
}
void RecordXimeaTemperature::stopRecordTemperature()
{
m_bIsRecord = false;
}
void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
{
if(filePath== nullptr)
filePath="ximeaTemperature.csv";
ofstream ximeaTemperatureFile(filePath.toStdString().c_str(),ios::app);
while(m_bIsRecord)
{
float temp = m_imager->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 <<std::endl;
sleep(1);
}
m_bIsRecord = true;
ximeaTemperatureFile.close();
}