fix & add
1、在界面上实现选择相机类型的功能; 2、创建了一个光谱仪操作的纯虚基类(ImagerOperationBase)并实现了大部分的操作,具体类型的光谱仪应继承此类并实现纯虚函数; 3、添加了 resonon 的 nir 320 相机,修改 resonon 的 pica l 相机的实现:继承 ImagerOperationBase; 4、重构类 QMotorDoubleSlider,提高其通用性,所有马达相关的 slider 都使用此类; 5、适配 resonon nir 320 显微镜使用的 2 轴线性平台,有些特殊的马达参数设置(setMotorParamMicroscope 函数)绑定了 nir 的相机类型参数; 6、修改:将线性平台的量程信息保存在cfg配置文件中,并修改配置文件读写类来读写此量程信息;
This commit is contained in:
399
HPPA/ImagerOperationBase.cpp
Normal file
399
HPPA/ImagerOperationBase.cpp
Normal file
@ -0,0 +1,399 @@
|
||||
#include "ImagerOperationBase.h"
|
||||
|
||||
ImagerOperationBase::ImagerOperationBase()
|
||||
{
|
||||
m_iFrameCounter = 1;
|
||||
m_bRecordControlState = true;
|
||||
|
||||
m_FileName2Save = "tmp_image";
|
||||
m_FileSavedCounter = 1;
|
||||
|
||||
m_RgbImage = new CImage();
|
||||
|
||||
buffer = nullptr;
|
||||
dark = nullptr;
|
||||
white = nullptr;
|
||||
|
||||
m_HasDark = false;
|
||||
m_HasWhite = false;
|
||||
m_bFocusControlState = false;
|
||||
}
|
||||
|
||||
ImagerOperationBase::~ImagerOperationBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImagerOperationBase::connect_imager(int frameNumber)
|
||||
{
|
||||
connectImager();
|
||||
setIntegrationTime(1);
|
||||
setFramerate(30.0);
|
||||
//set_gain(0);
|
||||
|
||||
//m_ResononNirImager.set_spectral_bin(2);
|
||||
|
||||
set_buffer();
|
||||
m_RgbImage->SetRgbImageWidthAndHeight(getBandCount(), getSampleCount(), frameNumber);
|
||||
m_iFrameNumber = frameNumber;
|
||||
|
||||
emit testImagerStatus();
|
||||
|
||||
//std::cout << "------------------------------------------------------" << std::endl;
|
||||
}
|
||||
|
||||
double ImagerOperationBase::auto_exposure()
|
||||
{
|
||||
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>Ϊ<EFBFBD>ڵ<EFBFBD>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
double x = 1 / getFramerate() * 1000;//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
setIntegrationTime(x);
|
||||
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>ѭ<EFBFBD><D1AD>Ѱ<EFBFBD><D1B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
imagerStartCollect();
|
||||
|
||||
while (true)
|
||||
{
|
||||
getFrame(buffer);
|
||||
if (GetMaxValue(buffer, m_FrameSize) >= 4095)
|
||||
{
|
||||
setIntegrationTime(getIntegrationTime() * 0.8);
|
||||
std::cout << "<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>-----------" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
imagerStopCollect();
|
||||
|
||||
//std::cout << "<22>Զ<EFBFBD><D4B6>ع⣺" << getIntegrationTime() << std::endl;
|
||||
|
||||
return getIntegrationTime();
|
||||
}
|
||||
|
||||
void ImagerOperationBase::focus()
|
||||
{
|
||||
m_iFocusFrameCounter = 1;
|
||||
//std::cout << "<22><><EFBFBD><EFBFBD>-----------" << std::endl;
|
||||
|
||||
double tmpFrmerate = getFramerate();
|
||||
double tmpIntegrationTime = getIntegrationTime();
|
||||
|
||||
|
||||
setFramerate(5);
|
||||
auto_exposure();
|
||||
std::cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>" << getIntegrationTime() << std::endl;
|
||||
|
||||
imagerStartCollect();
|
||||
|
||||
//emit SpectralSignal(1);
|
||||
m_bFocusControlState = true;
|
||||
while (m_bFocusControlState)
|
||||
{
|
||||
getFrame(buffer);
|
||||
//m_RgbImage->FillFocusGrayImage(buffer);
|
||||
m_RgbImage->FillFocusGrayQImage(buffer);
|
||||
|
||||
emit SpectralSignal(1);
|
||||
|
||||
++m_iFocusFrameCounter;
|
||||
}
|
||||
emit SpectralSignal(0);
|
||||
|
||||
imagerStopCollect();
|
||||
|
||||
setFramerate(tmpFrmerate);
|
||||
setIntegrationTime(tmpIntegrationTime);
|
||||
}
|
||||
|
||||
void ImagerOperationBase::record_dark()
|
||||
{
|
||||
std::cout << "<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << std::endl;
|
||||
imagerStartCollect();
|
||||
getFrame(dark);
|
||||
imagerStopCollect();
|
||||
|
||||
m_HasDark = true;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::record_white()
|
||||
{
|
||||
std::cout << "<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ壡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << std::endl;
|
||||
imagerStartCollect();
|
||||
getFrame(white);
|
||||
imagerStopCollect();
|
||||
|
||||
//<2F>װ<EFBFBD><D7B0>۰<EFBFBD><DBB0><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (m_HasDark)
|
||||
{
|
||||
for (size_t i = 0; i < m_FrameSize; i++)
|
||||
{
|
||||
if (white[i] < dark[i])
|
||||
{
|
||||
white[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
white[i] = white[i] - dark[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_HasWhite = true;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::start_record()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
//std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
m_iFrameCounter = 0;
|
||||
m_RgbImage->m_iFrameCounter = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rgbͼ<62><CDBC><EFBFBD>ĵ<EFBFBD>0<EFBFBD><30>
|
||||
m_bRecordControlState = true;
|
||||
|
||||
//<2F>ж<EFBFBD><D0B6>ڴ<EFBFBD>buffer<65>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (buffer == 0)
|
||||
{
|
||||
std::cerr << "Error: memory could not be allocated for datacube";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryFromString();
|
||||
string imgPath = directory + "\\" + m_FileName2Save + "_" + std::to_string(m_FileSavedCounter);
|
||||
|
||||
FILE* m_fImage = fopen(imgPath.c_str(), "w+b");
|
||||
|
||||
size_t x;
|
||||
double pixelValueTmp;
|
||||
|
||||
imagerStartCollect();
|
||||
while (m_bRecordControlState)
|
||||
{
|
||||
m_iFrameCounter++;
|
||||
|
||||
getFrame(buffer);
|
||||
|
||||
//<2F><>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӦΪbuffer<65><72>dark<72><6B><EFBFBD><EFBFBD>unsigned short<72><74><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD>dark>bufferʱ<72><CAB1>buffer-dark=65535
|
||||
if (m_HasDark)
|
||||
{
|
||||
for (size_t i = 0; i < m_FrameSize; i++)
|
||||
{
|
||||
if (buffer[i] < dark[i])
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[i] = buffer[i] - dark[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (m_HasWhite)
|
||||
{
|
||||
for (size_t i = 0; i < m_FrameSize; i++)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ壩Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (white[i] != 0)
|
||||
{
|
||||
pixelValueTmp = buffer[i];
|
||||
buffer[i] = (pixelValueTmp / white[i]) * 10000;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
x = fwrite(buffer, 2, m_FrameSize, m_fImage);
|
||||
|
||||
//<2F><>rgb<67><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
||||
m_RgbImage->FillRgbImage(buffer);//??????????????????????????????????????????????????????????????????????????????????????????????????????
|
||||
|
||||
//std::cout << "<22><>" << m_iFrameCounter << "֡д<D6A1><D0B4>" << x << "<22><>unsigned short<72><74>" << std::endl;
|
||||
|
||||
//ÿ<><C3BF>1s<31><73><EFBFBD><EFBFBD>һ<EFBFBD>ν<EFBFBD><CEBD><EFBFBD>ͼ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>
|
||||
if (m_iFrameCounter % (int)getFramerate() == 0)
|
||||
{
|
||||
emit PlotSignal();
|
||||
}
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
imagerStopCollect();
|
||||
|
||||
m_bRecordControlState = false;
|
||||
WriteHdr();
|
||||
m_FileSavedCounter++;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼǰ<CDBC><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//m_RgbImage
|
||||
emit PlotSignal();//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>λ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Է<EFBFBD><D4B7>ɼ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>ʵı<CAB5><C4B1><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>ȫ
|
||||
|
||||
if (m_iFrameCounter >= m_iFrameNumber)
|
||||
{
|
||||
emit RecordFinishedSignal_WhenFrameNumberMeet();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit RecordFinishedSignal_WhenFrameNumberNotMeet();
|
||||
}
|
||||
|
||||
//QThread::msleep(1001);
|
||||
fclose(m_fImage);
|
||||
}
|
||||
|
||||
void ImagerOperationBase::setFrameNumber(int FrameNumber)
|
||||
{
|
||||
m_iFrameNumber = FrameNumber;
|
||||
m_RgbImage->SetRgbImageWidthAndHeight(getBandCount(), getSampleCount(), FrameNumber);
|
||||
}
|
||||
|
||||
void ImagerOperationBase::setFileName2Save(string FileName)
|
||||
{
|
||||
m_FileName2Save = FileName;
|
||||
m_FileSavedCounter = 1;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::setFocusControlState(bool FocusControlState)
|
||||
{
|
||||
m_bFocusControlState = FocusControlState;
|
||||
}
|
||||
|
||||
int ImagerOperationBase::GetFrameSize(int& iWidth, int& iHeight)
|
||||
{
|
||||
/*using namespace GENAPI_NAMESPACE;
|
||||
using namespace std;
|
||||
INodeMap& nodemap = m_phCamera->GetNodeMap();
|
||||
|
||||
iWidth = (int)CIntegerPtr(nodemap.GetNode("Width"))->GetValue();
|
||||
iHeight = (int)CIntegerPtr(nodemap.GetNode("Height"))->GetValue();*/
|
||||
|
||||
iWidth = getSampleCount();
|
||||
iHeight = getBandCount();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CImage* ImagerOperationBase::getRgbImage() const
|
||||
{
|
||||
return m_RgbImage;
|
||||
}
|
||||
|
||||
cv::Mat* ImagerOperationBase::getMatRgbImage() const
|
||||
{
|
||||
return m_RgbImage->m_matRgbImage;
|
||||
}
|
||||
|
||||
cv::Mat* ImagerOperationBase::getMatFocusGrayImage() const
|
||||
{
|
||||
return m_RgbImage->m_matFocusGrayImage;
|
||||
}
|
||||
|
||||
QImage ImagerOperationBase::getQImageFocusGrayImage() const
|
||||
{
|
||||
return *m_RgbImage->m_qimageFocusGrayImage;
|
||||
}
|
||||
|
||||
bool ImagerOperationBase::getRecordControlState() const
|
||||
{
|
||||
return m_bRecordControlState;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::setRecordControlState(bool RecordControlState)
|
||||
{
|
||||
m_bRecordControlState = RecordControlState;
|
||||
}
|
||||
|
||||
int ImagerOperationBase::getFrameCounter() const
|
||||
{
|
||||
return m_iFrameCounter;
|
||||
}
|
||||
|
||||
int ImagerOperationBase::getFocusFrameCounter() const
|
||||
{
|
||||
return m_iFocusFrameCounter;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::set_buffer()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
if (buffer != nullptr)
|
||||
{
|
||||
std::cout << "<EFBFBD>ͷŶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>" << std::endl;
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
m_FrameSize = getBandCount() * getSampleCount();
|
||||
//std::cout << "m_FrameSize<7A><65>СΪ" << m_FrameSize << std::endl;
|
||||
|
||||
buffer = new unsigned short[m_FrameSize];
|
||||
dark = new unsigned short[m_FrameSize];
|
||||
white = new unsigned short[m_FrameSize];
|
||||
|
||||
std::cout << "buffer<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ" << buffer << std::endl;
|
||||
std::cout << "dark<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ" << dark << std::endl;
|
||||
std::cout << "white<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ" << white << std::endl;
|
||||
}
|
||||
|
||||
void ImagerOperationBase::WriteHdr()
|
||||
{
|
||||
//write an ENVI compatible header file
|
||||
using namespace std;
|
||||
|
||||
|
||||
FileOperation* fileOperation = new FileOperation();
|
||||
string directory = fileOperation->getDirectoryFromString();
|
||||
|
||||
string hdrPath = directory + "\\" + m_FileName2Save + "_" + std::to_string(m_FileSavedCounter) + ".hdr";
|
||||
|
||||
std::ofstream outfile(hdrPath.c_str());
|
||||
outfile << "ENVI\n";
|
||||
outfile << "interleave = bil\n";
|
||||
outfile << "data type = 12\n";
|
||||
outfile << "bit depth = 12\n";
|
||||
outfile << "samples = " << getSampleCount() << "\n";
|
||||
outfile << "bands = " << getBandCount() << "\n";
|
||||
outfile << "lines = " << m_iFrameCounter << "\n";
|
||||
outfile << "framerate = " << getFramerate() << "\n";
|
||||
outfile << "shutter = " << getIntegrationTime() << "\n";
|
||||
outfile << "gain = " << getGain() << "\n";
|
||||
outfile << "wavelength = {";
|
||||
outfile << std::setprecision(5);
|
||||
|
||||
int start = getStartBand();
|
||||
int end = getEndBand();
|
||||
for (int i = start; i < end - 1; i++)
|
||||
{
|
||||
outfile << getWavelengthAtBand(i) << ", ";
|
||||
}
|
||||
outfile << getWavelengthAtBand(end - 1) << "}\n";
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
unsigned short ImagerOperationBase::GetMaxValue(unsigned short* dark, int number)
|
||||
{
|
||||
unsigned short max = 0;
|
||||
for (size_t i = 0; i < number; i++)
|
||||
{
|
||||
if (dark[i] > max)
|
||||
{
|
||||
max = dark[i];
|
||||
}
|
||||
}
|
||||
//std::cout << "<22><>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ֵΪ" << max << std::endl;
|
||||
return max;
|
||||
}
|
||||
Reference in New Issue
Block a user