mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-12-15 19:13:31 +08:00
263 lines
7.5 KiB
C++
263 lines
7.5 KiB
C++
|
|
//
|
|||
|
|
// Created by 73505 on 2023/5/7.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#include "Header_Files/JinspFiberImager.h"
|
|||
|
|
|
|||
|
|
JinspFiberImager::JinspFiberImager(bool bIsUSBMode, std::string ucPortNumber, std::string strDeviceName)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer = NULL;
|
|||
|
|
|
|||
|
|
mUcPortNumber=ucPortNumber;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
JinspFiberImager::~JinspFiberImager()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::connectFiberSpectrometer(QString& SN, QString& pixelCount, QString& wavelengthInfo)
|
|||
|
|
{
|
|||
|
|
using namespace std;
|
|||
|
|
|
|||
|
|
m_FiberSpectrometer = new IS11_Ctrl_Qt();
|
|||
|
|
|
|||
|
|
m_FiberSpectrometer->Initialize(false, mUcPortNumber, "OPTOSKY");
|
|||
|
|
|
|||
|
|
DeviceInfo deviceInfo;//
|
|||
|
|
DeviceAttribute deviceAttribute;
|
|||
|
|
|
|||
|
|
m_FiberSpectrometer->GetDeviceInfo(deviceInfo);
|
|||
|
|
m_FiberSpectrometer->GetDeviceAttribute(deviceAttribute);//?????
|
|||
|
|
|
|||
|
|
SN = QString::fromStdString(deviceInfo.strSN);
|
|||
|
|
pixelCount = QString::number(deviceAttribute.iPixels);
|
|||
|
|
wavelengthInfo = QString::number(deviceAttribute.fWaveLengthInNM[0]) + "--" + QString::number(deviceAttribute.fWaveLengthInNM[deviceAttribute.iPixels - 1]);
|
|||
|
|
|
|||
|
|
m_FiberSpectrometer->SetDeviceTemperature(-10);
|
|||
|
|
|
|||
|
|
|
|||
|
|
//设置dn值的最大值(和位深相关)
|
|||
|
|
string qepro = "QEP";//?????????????????????????????????????????????????????????????????????????????????????????
|
|||
|
|
string flame = "FLMS";//?????????????????????????????????????????????????????????????????????????????????????????
|
|||
|
|
if (deviceInfo.strSN.find(qepro) != string::npos)
|
|||
|
|
{
|
|||
|
|
m_MaxValueOfFiberSpectrometer = 200000;
|
|||
|
|
}
|
|||
|
|
else if (deviceInfo.strSN.find(flame) != string::npos)
|
|||
|
|
{
|
|||
|
|
m_MaxValueOfFiberSpectrometer = 65535;
|
|||
|
|
}
|
|||
|
|
else//没有找到匹配的仪器来设置 dn值的最大值
|
|||
|
|
{
|
|||
|
|
m_MaxValueOfFiberSpectrometer = 65535;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::disconnectFiberSpectrometer()
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::getDeviceAttribute(DeviceAttribute& deviceAttribute)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->GetDeviceAttribute(deviceAttribute);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::getDeviceInfo(DeviceInfo& deviceInfo)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->GetDeviceInfo(deviceInfo);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::setExposureTime(int iExposureTimeInMS)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->SetExposureTime(iExposureTimeInMS);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::getExposureTime(int &iExposureTimeInMS)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->GetExposureTime(iExposureTimeInMS);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::getDeviceTemperature(float &fTemperature)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->GetDeviceTemperature(fTemperature);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::singleShot(DataFrame &dfData)
|
|||
|
|
{
|
|||
|
|
m_FiberSpectrometer->SingleShot(dfData);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::getNonlinearityCoeffs(coeffsFrame &coeffs)
|
|||
|
|
{
|
|||
|
|
printf("This is JinspFiberImager.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::recordDark(QString path)
|
|||
|
|
{
|
|||
|
|
//获取设备信息
|
|||
|
|
DeviceAttribute attribute;
|
|||
|
|
DeviceInfo deviceInfo;
|
|||
|
|
getDeviceAttribute(attribute);
|
|||
|
|
getDeviceInfo(deviceInfo);
|
|||
|
|
|
|||
|
|
//采集暗帧
|
|||
|
|
singleShot(m_DarkData);
|
|||
|
|
|
|||
|
|
//输出到csv
|
|||
|
|
QDateTime curDateTime = QDateTime::currentDateTime();
|
|||
|
|
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
|||
|
|
QString fileName = path + "/" + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + "_darkSpectral_dn.csv";
|
|||
|
|
std::ofstream outfile(fileName.toStdString().c_str());
|
|||
|
|
|
|||
|
|
for (int i = 0; i < attribute.iPixels; i++)
|
|||
|
|
{
|
|||
|
|
if (i==0)
|
|||
|
|
{
|
|||
|
|
outfile << m_DarkData.usExposureTimeInMS << std::endl;
|
|||
|
|
}
|
|||
|
|
outfile << attribute.fWaveLengthInNM[i] << "," << m_DarkData.lData[i] << std::endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
outfile.close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::recordTarget(int recordTimes, QString path)
|
|||
|
|
{
|
|||
|
|
//获取设备信息
|
|||
|
|
DeviceAttribute attribute;
|
|||
|
|
DeviceInfo deviceInfo;
|
|||
|
|
getDeviceAttribute(attribute);
|
|||
|
|
getDeviceInfo(deviceInfo);
|
|||
|
|
|
|||
|
|
|
|||
|
|
DataFrame integratingSphereData_tmp;
|
|||
|
|
|
|||
|
|
for (int i = 0; i < recordTimes; i++)
|
|||
|
|
{
|
|||
|
|
singleShot(integratingSphereData_tmp);
|
|||
|
|
|
|||
|
|
if (i == 0)//将integratingSphereData_tmp中的曝光时间、温度等信息传给m_IntegratingSphereData
|
|||
|
|
{
|
|||
|
|
m_IntegratingSphereData = integratingSphereData_tmp;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < attribute.iPixels; i++)
|
|||
|
|
{
|
|||
|
|
m_IntegratingSphereData.lData[i] += integratingSphereData_tmp.lData[i];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < attribute.iPixels; i++)
|
|||
|
|
{
|
|||
|
|
m_IntegratingSphereData.lData[i] = m_IntegratingSphereData.lData[i] / recordTimes;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//输出到csv
|
|||
|
|
QDateTime curDateTime = QDateTime::currentDateTime();
|
|||
|
|
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
|||
|
|
QString fileName = path + "/" + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + "_integratingSphereSpectral_dn.csv";
|
|||
|
|
std::ofstream outfile(fileName.toStdString().c_str());
|
|||
|
|
|
|||
|
|
for (int i = 0; i < attribute.iPixels; i++)
|
|||
|
|
{
|
|||
|
|
if (i==0)
|
|||
|
|
{
|
|||
|
|
outfile << m_IntegratingSphereData.usExposureTimeInMS << std::endl;
|
|||
|
|
}
|
|||
|
|
outfile << attribute.fWaveLengthInNM[i] << "," << m_IntegratingSphereData.lData[i] << std::endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
outfile.close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void JinspFiberImager::autoExpose()
|
|||
|
|
{
|
|||
|
|
// float fPredictedExposureTime;
|
|||
|
|
// m_FiberSpectrometer->PerformAutoExposure(0.6,0.9,fPredictedExposureTime);
|
|||
|
|
|
|||
|
|
//tc
|
|||
|
|
DeviceAttribute attribute;
|
|||
|
|
getDeviceAttribute(attribute);
|
|||
|
|
|
|||
|
|
int iterations = 0;//记录自动曝光已经迭代的次数
|
|||
|
|
int maxIterations = 10;//允许最大的迭代次数
|
|||
|
|
|
|||
|
|
ZZ_U32 thresholdValue = m_MaxValueOfFiberSpectrometer * 0.8;//最佳线性区间为80%
|
|||
|
|
ZZ_U16 range = 10000;
|
|||
|
|
|
|||
|
|
//设置初始曝光时间
|
|||
|
|
int exposureTimeInMS = 200;
|
|||
|
|
setExposureTime(exposureTimeInMS);
|
|||
|
|
|
|||
|
|
// int exposureTime;
|
|||
|
|
// m_FiberSpectrometer->GetExposureTime(exposureTime);
|
|||
|
|
|
|||
|
|
emit sendExposureTimeSignal(exposureTimeInMS);
|
|||
|
|
|
|||
|
|
DataFrame integratingSphereData_tmp;
|
|||
|
|
ZZ_S32 maxValue;
|
|||
|
|
while (true)
|
|||
|
|
{
|
|||
|
|
if (iterations > maxIterations)//是否超过允许的最大迭代次数
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
singleShot(integratingSphereData_tmp);
|
|||
|
|
maxValue = GetMaxValue(integratingSphereData_tmp.lData, attribute.iPixels);
|
|||
|
|
|
|||
|
|
if (maxValue < thresholdValue && maxValue < (thresholdValue - range))//曝光时间过小
|
|||
|
|
{
|
|||
|
|
double scale = 1 + ((double)(thresholdValue - maxValue) / (double)thresholdValue);
|
|||
|
|
|
|||
|
|
int exposureTime;
|
|||
|
|
m_FiberSpectrometer->GetExposureTime(exposureTime);
|
|||
|
|
m_FiberSpectrometer->SetExposureTime(exposureTime * scale);
|
|||
|
|
|
|||
|
|
emit sendExposureTimeSignal(exposureTime);
|
|||
|
|
|
|||
|
|
std::cout << "自动曝光-----------" << "最大值为" << maxValue << std::endl;
|
|||
|
|
}
|
|||
|
|
else if (maxValue > thresholdValue)//曝光时间过大
|
|||
|
|
{
|
|||
|
|
double scale = 1 - ((double)(maxValue - thresholdValue) / (double)thresholdValue);
|
|||
|
|
|
|||
|
|
int exposureTime;
|
|||
|
|
m_FiberSpectrometer->GetExposureTime(exposureTime);
|
|||
|
|
m_FiberSpectrometer->SetExposureTime(exposureTime * scale);
|
|||
|
|
|
|||
|
|
emit sendExposureTimeSignal(exposureTime);
|
|||
|
|
|
|||
|
|
std::cout << "自动曝光-----------" << "最大值为" << maxValue << std::endl;
|
|||
|
|
}
|
|||
|
|
else//找到最佳曝光时间,跳出while循环
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
iterations++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int a = 2;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ZZ_S32 JinspFiberImager::GetMaxValue(ZZ_S32 * dark, int number)
|
|||
|
|
{
|
|||
|
|
ZZ_S32 max = 0;
|
|||
|
|
for (size_t i = 0; i < number; i++)
|
|||
|
|
{
|
|||
|
|
if (dark[i] > max)
|
|||
|
|
{
|
|||
|
|
max = dark[i];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//std::cout << "本帧最大值为" << max << std::endl;
|
|||
|
|
return max;
|
|||
|
|
}
|