mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 03:49:42 +08:00
更新了卓哥apt的自动曝光函数
This commit is contained in:
@ -397,137 +397,299 @@ int ZZ_ATPControl_Serial_Qt::Init_Self()
|
|||||||
|
|
||||||
int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float& fPredictedExposureTime)
|
int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float& fPredictedExposureTime)
|
||||||
{
|
{
|
||||||
using namespace ZZ_MATH;
|
// using namespace ZZ_MATH;
|
||||||
int iDeviceDepth = 65535;
|
// int iDeviceDepth = 65535;
|
||||||
|
//
|
||||||
|
// bool bFlagIsOverTrying = false;
|
||||||
|
// bool bFlagIsLowerMinExposureTime = false;
|
||||||
|
// bool bFlagIsOverMaxExposureTime = false;
|
||||||
|
// bool bFlagIsAutoExposureOK = false;
|
||||||
|
// bool bFlagIsAutoExposureFailed = false;
|
||||||
|
//
|
||||||
|
// bool bIsValueOverflow = false;
|
||||||
|
// bool bIsLastValueOverflow = false;
|
||||||
|
//
|
||||||
|
// float fExposureTime = 0;
|
||||||
|
// float fTempExposureTime = 0;
|
||||||
|
// double fLastExposureTime = 0.1;
|
||||||
|
// int iRepeatCount = 0;
|
||||||
|
//
|
||||||
|
// int iRes = SetExposureTime(2000);//need change to load from files
|
||||||
|
// if (iRes != 0)
|
||||||
|
// {
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
|
||||||
|
// {
|
||||||
|
// DataFrame dfTemp;
|
||||||
|
//
|
||||||
|
// if (iRepeatCount++ > 30)
|
||||||
|
// {
|
||||||
|
// bFlagIsAutoExposureFailed = true;
|
||||||
|
// bFlagIsOverTrying = true;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||||
|
// fTempExposureTime = fExposureTime;
|
||||||
|
//
|
||||||
|
// iRes = SingleShot(dfTemp);
|
||||||
|
// if (iRes != 0)
|
||||||
|
// {
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
|
||||||
|
// return 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
|
||||||
|
//
|
||||||
|
// double dSum = 0;
|
||||||
|
// int iCount = m_daDeviceAttr.iPixels / 100;
|
||||||
|
// for (int i = 0; i < iCount; i++)
|
||||||
|
// {
|
||||||
|
// dSum += dfTemp.lData[i];
|
||||||
|
// }
|
||||||
|
// double dTemp = dSum / iCount;
|
||||||
|
//
|
||||||
|
// if (dTemp >= iDeviceDepth * 0.99)
|
||||||
|
// {
|
||||||
|
// bIsValueOverflow = true;
|
||||||
|
// if (!bIsLastValueOverflow)
|
||||||
|
// {
|
||||||
|
// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// fExposureTime = fExposureTime / 2;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
|
||||||
|
// {
|
||||||
|
// bFlagIsAutoExposureOK = 1;
|
||||||
|
// }
|
||||||
|
// else if (dTemp > iDeviceDepth * fMaxScaleFactor)
|
||||||
|
// {
|
||||||
|
// bIsValueOverflow = true;
|
||||||
|
// if (!bIsLastValueOverflow)
|
||||||
|
// {
|
||||||
|
// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// fExposureTime = fExposureTime * 3 / 4;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else if (dTemp < iDeviceDepth * fMinScaleFactor)
|
||||||
|
// {
|
||||||
|
// bIsValueOverflow = false;
|
||||||
|
// if (bIsLastValueOverflow)
|
||||||
|
// {
|
||||||
|
// fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// double dFactor;
|
||||||
|
// dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
|
||||||
|
// fExposureTime = (float)(fExposureTime / dFactor);
|
||||||
|
// }
|
||||||
|
// if (/*fExposureTime > 100 || */fExposureTime < 10)
|
||||||
|
// {
|
||||||
|
// bFlagIsAutoExposureOK = false;
|
||||||
|
// bFlagIsAutoExposureFailed = true;
|
||||||
|
// bFlagIsLowerMinExposureTime = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// bIsLastValueOverflow = bIsValueOverflow;
|
||||||
|
// fLastExposureTime = fTempExposureTime;
|
||||||
|
//
|
||||||
|
// if (fExposureTime > 13000)
|
||||||
|
// {
|
||||||
|
// bFlagIsAutoExposureOK = false;
|
||||||
|
// bFlagIsAutoExposureFailed = true;
|
||||||
|
// fPredictedExposureTime = 13000;
|
||||||
|
// iRes = SetExposureTime(13000);
|
||||||
|
// if (iRes != 0)
|
||||||
|
// {
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
|
||||||
|
// return 3;
|
||||||
|
// }
|
||||||
|
// bFlagIsOverMaxExposureTime = true;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// iRes = SetExposureTime((int)fExposureTime);
|
||||||
|
// if (iRes != 0)
|
||||||
|
// {
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
|
||||||
|
// return 3;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// fPredictedExposureTime = fExposureTime;
|
||||||
|
// return 0;
|
||||||
|
|
||||||
bool bFlagIsOverTrying = false;
|
int m_iThreadID=0;
|
||||||
bool bFlagIsLowerMinExposureTime = false;
|
// qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||||
bool bFlagIsOverMaxExposureTime = false;
|
using namespace ZZ_MATH;
|
||||||
bool bFlagIsAutoExposureOK = false;
|
// float fPredictedExposureTime;
|
||||||
bool bFlagIsAutoExposureFailed = false;
|
int iDeviceDepth = 65535;
|
||||||
|
|
||||||
bool bIsValueOverflow = false;
|
|
||||||
bool bIsLastValueOverflow = false;
|
|
||||||
|
|
||||||
float fExposureTime = 0;
|
|
||||||
float fTempExposureTime = 0;
|
|
||||||
double fLastExposureTime = 0.1;
|
|
||||||
int iRepeatCount = 0;
|
|
||||||
|
|
||||||
int iRes = SetExposureTime(2000);//need change to load from files
|
// qDebug() << "MAX---Min" << fMaxScaleFactor << "---" << fMinScaleFactor << " Thread ID:" << m_iThreadID;
|
||||||
if (iRes != 0)
|
|
||||||
{
|
|
||||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
|
bool bFlagIsOverTrying = false;
|
||||||
{
|
bool bFlagIsLowerMinExposureTime = false;
|
||||||
DataFrame dfTemp;
|
bool bFlagIsOverMaxExposureTime = false;
|
||||||
|
bool bFlagIsAutoExposureOK = false;
|
||||||
|
bool bFlagIsAutoExposureFailed = false;
|
||||||
|
|
||||||
if (iRepeatCount++ > 30)
|
bool bIsValueOverflow = false;
|
||||||
{
|
bool bIsLastValueOverflow = false;
|
||||||
bFlagIsAutoExposureFailed = true;
|
|
||||||
bFlagIsOverTrying = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
int iExposureTime = 0;
|
||||||
fTempExposureTime = fExposureTime;
|
float fTempExposureTime = 0;
|
||||||
|
double fLastExposureTime = 0.1;
|
||||||
|
int iRepeatCount = 0;
|
||||||
|
|
||||||
iRes = SingleShot(dfTemp);
|
//int iRes = m_pFSCtrl->SetExposureTime(1000);//need change to load from files
|
||||||
if (iRes != 0)
|
int iRes = 0;
|
||||||
{
|
if (iRes != 0)
|
||||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
|
{
|
||||||
return 2;
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1" << " Thread ID:" << m_iThreadID;
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
|
while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
|
||||||
|
{
|
||||||
|
DataFrame dfTemp;
|
||||||
|
|
||||||
double dSum = 0;
|
if (iRepeatCount++ > 30)
|
||||||
int iCount = m_daDeviceAttr.iPixels / 100;
|
{
|
||||||
for (int i = 0; i < iCount; i++)
|
bFlagIsAutoExposureFailed = true;
|
||||||
{
|
bFlagIsOverTrying = true;
|
||||||
dSum += dfTemp.lData[i];
|
break;
|
||||||
}
|
}
|
||||||
double dTemp = dSum / iCount;
|
//m_pFSCtrl->SetExposureTime(5000);
|
||||||
|
GetExposureTime(iExposureTime);
|
||||||
|
// qDebug() << "Current ExpTime:" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||||
|
//m_pFSCtrl->SetExposureTime(2500);
|
||||||
|
//fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||||
|
fTempExposureTime = iExposureTime;
|
||||||
|
|
||||||
if (dTemp >= iDeviceDepth * 0.99)
|
iRes = SingleShot(dfTemp);
|
||||||
{
|
//iRes = m_pFSCtrl->SingleShot(dfTemp);
|
||||||
bIsValueOverflow = true;
|
if (iRes != 0)
|
||||||
if (!bIsLastValueOverflow)
|
{
|
||||||
{
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2" << " Thread ID:" << m_iThreadID;
|
||||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
return 2;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
|
||||||
fExposureTime = fExposureTime / 2;
|
|
||||||
}
|
double dSum = 0;
|
||||||
}
|
int iCount = m_daDeviceAttr.iPixels / 200;
|
||||||
|
for (int i = 0; i < iCount; i++)
|
||||||
|
{
|
||||||
|
dSum += dfTemp.lData[i];
|
||||||
|
}
|
||||||
|
double dTemp = dSum / iCount;
|
||||||
|
|
||||||
|
// qDebug() << "Avg " << dTemp << " Thread ID:" << m_iThreadID;
|
||||||
|
|
||||||
|
if (dTemp >= iDeviceDepth * 0.99)
|
||||||
|
{
|
||||||
|
bIsValueOverflow = true;
|
||||||
|
if (!bIsLastValueOverflow)
|
||||||
|
{
|
||||||
|
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iExposureTime = iExposureTime / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
|
||||||
|
{
|
||||||
|
// qDebug() << "trace bFlagIsAutoExposureOK =1 " << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||||
|
bFlagIsAutoExposureOK = 1;
|
||||||
|
}
|
||||||
|
else if (dTemp > iDeviceDepth * fMaxScaleFactor)
|
||||||
|
{
|
||||||
|
bIsValueOverflow = true;
|
||||||
|
if (!bIsLastValueOverflow)
|
||||||
|
{
|
||||||
|
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iExposureTime = iExposureTime * 3 / 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dTemp < iDeviceDepth * fMinScaleFactor)
|
||||||
|
{
|
||||||
|
bIsValueOverflow = false;
|
||||||
|
if (bIsLastValueOverflow)
|
||||||
|
{
|
||||||
|
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double dFactor;
|
||||||
|
dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
|
||||||
|
iExposureTime = (float)(iExposureTime / dFactor);
|
||||||
|
}
|
||||||
|
if (/*fExposureTime > 100 || */iExposureTime < 10)
|
||||||
|
{
|
||||||
|
bFlagIsAutoExposureOK = false;
|
||||||
|
bFlagIsAutoExposureFailed = true;
|
||||||
|
bFlagIsLowerMinExposureTime = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bIsLastValueOverflow = bIsValueOverflow;
|
||||||
|
fLastExposureTime = fTempExposureTime;
|
||||||
|
|
||||||
|
if (iExposureTime > 120000)
|
||||||
|
{
|
||||||
|
bFlagIsAutoExposureOK = false;
|
||||||
|
bFlagIsAutoExposureFailed = true;
|
||||||
|
float fPredictedExposureTime = 120000;
|
||||||
|
iRes = SetExposureTime(120000);
|
||||||
|
if (iRes != 0)
|
||||||
|
{
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3" << " Thread ID:" << m_iThreadID;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to 30sec";
|
||||||
|
// qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to " << m_daDeviceAttr.iMaxIntegrationTimeInMS << "MS" << " Thread ID:" << m_iThreadID;
|
||||||
|
}
|
||||||
|
bFlagIsOverMaxExposureTime = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
iRes = SetExposureTime((int)iExposureTime);
|
||||||
|
if (iRes != 0)
|
||||||
|
{
|
||||||
|
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4" << " Thread ID:" << m_iThreadID;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Success:PerformAutoExposure. Value" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fPredictedExposureTime = iExposureTime;
|
||||||
|
// qDebug() << "--------------------------Stop PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||||
|
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
|
|
||||||
{
|
|
||||||
bFlagIsAutoExposureOK = 1;
|
|
||||||
}
|
|
||||||
else if (dTemp > iDeviceDepth * fMaxScaleFactor)
|
|
||||||
{
|
|
||||||
bIsValueOverflow = true;
|
|
||||||
if (!bIsLastValueOverflow)
|
|
||||||
{
|
|
||||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fExposureTime = fExposureTime * 3 / 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dTemp < iDeviceDepth * fMinScaleFactor)
|
|
||||||
{
|
|
||||||
bIsValueOverflow = false;
|
|
||||||
if (bIsLastValueOverflow)
|
|
||||||
{
|
|
||||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double dFactor;
|
|
||||||
dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
|
|
||||||
fExposureTime = (float)(fExposureTime / dFactor);
|
|
||||||
}
|
|
||||||
if (/*fExposureTime > 100 || */fExposureTime < 10)
|
|
||||||
{
|
|
||||||
bFlagIsAutoExposureOK = false;
|
|
||||||
bFlagIsAutoExposureFailed = true;
|
|
||||||
bFlagIsLowerMinExposureTime = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bIsLastValueOverflow = bIsValueOverflow;
|
|
||||||
fLastExposureTime = fTempExposureTime;
|
|
||||||
|
|
||||||
if (fExposureTime > 13000)
|
|
||||||
{
|
|
||||||
bFlagIsAutoExposureOK = false;
|
|
||||||
bFlagIsAutoExposureFailed = true;
|
|
||||||
fPredictedExposureTime = 13000;
|
|
||||||
iRes = SetExposureTime(13000);
|
|
||||||
if (iRes != 0)
|
|
||||||
{
|
|
||||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
bFlagIsOverMaxExposureTime = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
iRes = SetExposureTime((int)fExposureTime);
|
|
||||||
if (iRes != 0)
|
|
||||||
{
|
|
||||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fPredictedExposureTime = fExposureTime;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
//<2F>Զ<EFBFBD><D4B6>ع<EFBFBD>
|
//<2F>Զ<EFBFBD><D4B6>ع<EFBFBD>
|
||||||
logout("<br><b style=\"color:red\">AutoExpose!</b>");
|
logout("<br><b style=\"color:red\">AutoExpose!</b>");
|
||||||
// m_FiberSpectrometer->autoExpose();
|
m_FiberSpectrometer->autoExpose();
|
||||||
|
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD>sleep<65><70><EFBFBD>ȴ<EFBFBD><C8B4>رտ<D8B1><D5BF><EFBFBD>
|
//<2F><><EFBFBD><EFBFBD>sleep<65><70><EFBFBD>ȴ<EFBFBD><C8B4>رտ<D8B1><D5BF><EFBFBD>
|
||||||
@ -173,7 +173,7 @@ CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *qu
|
|||||||
|
|
||||||
QCommandLineOption averageTimes("a", "Average times.", "average_times");
|
QCommandLineOption averageTimes("a", "Average times.", "average_times");
|
||||||
averageTimes.setDefaultValue("5");//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
|
averageTimes.setDefaultValue("5");//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||||
parser.addOption(averageTimes);
|
parser.addOption(averageTimes);//
|
||||||
|
|
||||||
QCommandLineOption position("position", "Position.", "position");
|
QCommandLineOption position("position", "Position.", "position");
|
||||||
parser.addOption(position);
|
parser.addOption(position);
|
||||||
@ -401,7 +401,7 @@ CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *qu
|
|||||||
}
|
}
|
||||||
else//Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD>
|
else//Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||||
{
|
{
|
||||||
query->calFileOutputName = "";
|
query->calFileOutputName = "";//ʹ<>ô˲<C3B4><CBB2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>query->calFileOutputNameΪ<65><CEAA> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><CBB1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||||
}
|
}
|
||||||
|
|
||||||
// const QStringList positionalArguments = parser.positionalArguments();
|
// const QStringList positionalArguments = parser.positionalArguments();
|
||||||
|
Reference in New Issue
Block a user