Compare commits
6 Commits
34
...
2e158431e7
Author | SHA1 | Date | |
---|---|---|---|
2e158431e7 | |||
6473a1f4ce | |||
cc76d62ded | |||
e620c87ecf | |||
47002ad894 | |||
5337a40837 |
@ -34,7 +34,9 @@ public:
|
||||
bool getspatialBin(int &spatialBin);
|
||||
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
|
||||
bool getEffectiveWindowRoi(int &width, int &offsetx);
|
||||
bool getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString);//spectralBinString = "bin1"或者”bin2“
|
||||
bool getGainOffset(float &gain, float &offset);
|
||||
bool getGainOffsetOfSpectralBin1(float &gain, float &offset);
|
||||
bool getSN(QString &SN);
|
||||
|
||||
bool getBufferPolicy(int &bufferPolicy);
|
||||
|
@ -67,6 +67,7 @@ public slots:
|
||||
|
||||
void sendXimeaImageStatus(int ximeaImageStatus);
|
||||
void sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime);
|
||||
void sendXimeaBinState(int spatialBin, int spectralBin);
|
||||
void sendXimeaImageFrameRate(double frameRate);
|
||||
void sendCopyFileStatus(int fileStatus);
|
||||
};
|
||||
|
@ -100,10 +100,11 @@ Q_OBJECT
|
||||
|
||||
public:
|
||||
WriteData2Disk();
|
||||
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||||
void setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||||
|
||||
private:
|
||||
queue<DataBuffer *> * m_q;
|
||||
queue<int> * m_qFrameCounter;
|
||||
QString m_QbaseFileName;
|
||||
int m_iFrameSizeInByte;
|
||||
int m_iNumber_WriteDisk;
|
||||
@ -154,12 +155,16 @@ private:
|
||||
int m_iImagerState;
|
||||
int m_iImagerStateTemp;
|
||||
|
||||
int m_iOffsetyOfSpectralBin1, m_iOffsetyOfSpectralBin2;
|
||||
int m_iHeightOfSpectralBin1, m_iHeightOfSpectralBin2;
|
||||
|
||||
QThread * m_recordTempThread;
|
||||
RecordXimeaTemperature * m_ximeaTemperature;
|
||||
|
||||
QThread * writeData2DiskThread;
|
||||
WriteData2Disk * writeData2Disk;
|
||||
queue<DataBuffer *> * q;
|
||||
queue<int> * m_qFrameCounter;
|
||||
MemoryPool<DataBuffer> * m_pool;
|
||||
|
||||
QString m_baseFileName;
|
||||
@ -176,23 +181,10 @@ private:
|
||||
|
||||
void processXiApiErrorCodes(int xiApiErrorCodes);
|
||||
|
||||
inline double getSbgTime(double TimeDifferenceBetweensOSAndSbg)
|
||||
inline double getSbgTime(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
|
||||
{
|
||||
struct timespec systemTime;
|
||||
clock_gettime(CLOCK_REALTIME,&systemTime);
|
||||
tm systemTime_rili;
|
||||
localtime_r(&systemTime.tv_sec, &systemTime_rili);
|
||||
|
||||
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
|
||||
double nanosecondSystem=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
|
||||
|
||||
|
||||
// printf("\n");
|
||||
// printf("XimeaImager::getSbgTime------系统时间纳秒%d\n", systemTime.tv_nsec);
|
||||
// printf("XimeaImager::getSbgTime------系统时间(未偏移)%f\n", nanosecondSystem);
|
||||
// printf("XimeaImager::getSbgTime------系统时间(偏移)%f\n", nanosecondSystem-TimeDifferenceBetweensOSAndSbg);
|
||||
|
||||
return nanosecondSystem-TimeDifferenceBetweensOSAndSbg;
|
||||
double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
|
||||
return ximeaTime + timeDifferenceBetweenSbgAndXimea;
|
||||
}
|
||||
|
||||
Configfile m_configfile;
|
||||
@ -203,6 +195,7 @@ public slots:
|
||||
void openImger();
|
||||
void closeImger();
|
||||
|
||||
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
|
||||
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
|
||||
|
||||
signals:
|
||||
@ -214,5 +207,6 @@ signals:
|
||||
|
||||
void autoExposeMaxValueOfOneFrame(int, double);
|
||||
void frameRateSignal(double);
|
||||
void binSignal(int, int);
|
||||
};
|
||||
#endif // XIMEAIMAGER_H
|
||||
|
@ -166,6 +166,28 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
|
||||
if(!(spectralArgument.lookupValue("height", height)
|
||||
&& spectralArgument.lookupValue("offsety", offsety)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getGainOffset(float &gain, float &offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
@ -206,6 +228,35 @@ bool Configfile::getGainOffset(float &gain, float &offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getGainOffsetOfSpectralBin1(float &gain, float &offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting &gainOffset = root["gainOffset"];
|
||||
int count = gainOffset.getLength();
|
||||
|
||||
string spectralBinString = "spectralBin1";
|
||||
|
||||
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
|
||||
string name = gainOffsetSetting.getName();
|
||||
|
||||
if(!(gainOffsetSetting.lookupValue("gain", gain)
|
||||
&& gainOffsetSetting.lookupValue("offset", offset)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getSN(QString &SN)
|
||||
{
|
||||
try
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::cout<<"ximeaAirborneSystem 版本:"<< "35." <<std::endl;
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
//UdpServer* x=new UdpServer();
|
||||
|
@ -8,16 +8,16 @@ UdpServer::UdpServer()
|
||||
m_udpSocket->bind(45454, QUdpSocket::ShareAddress);
|
||||
connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));
|
||||
|
||||
m_RecordSbgThread=new QThread();
|
||||
m_sbgRecorder=new sbgtc::SbgRecorder();
|
||||
m_sbgRecorder->moveToThread(m_RecordSbgThread);
|
||||
m_RecordSbgThread->start();
|
||||
|
||||
m_RecordThread=new QThread();
|
||||
m_imager=new XimeaImager();
|
||||
m_imager->moveToThread(m_RecordThread);
|
||||
m_RecordThread->start(QThread::HighestPriority);
|
||||
|
||||
m_RecordSbgThread=new QThread();
|
||||
m_sbgRecorder=new sbgtc::SbgRecorder();
|
||||
m_sbgRecorder->moveToThread(m_RecordSbgThread);
|
||||
m_RecordSbgThread->start();
|
||||
|
||||
m_CopyFileThread=new QThread();
|
||||
m_copyFile=new FileOperation();
|
||||
m_copyFile->moveToThread(m_CopyFileThread);
|
||||
@ -51,6 +51,7 @@ UdpServer::UdpServer()
|
||||
|
||||
connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int)));
|
||||
connect(m_imager, SIGNAL(autoExposeMaxValueOfOneFrame(int, double)),this, SLOT(sendXimeaAutoExposeMaxValueOfOneFrame(int, double)));
|
||||
connect(m_imager, SIGNAL(binSignal(int, int)),this, SLOT(sendXimeaBinState(int, int)));
|
||||
connect(m_imager, SIGNAL(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
|
||||
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
|
||||
|
||||
@ -59,10 +60,10 @@ UdpServer::UdpServer()
|
||||
//当软件不正常关闭并且重启后,通知其他psdk程序
|
||||
m_clientIpAddress=QHostAddress(QHostAddress::LocalHost);
|
||||
sendSerialPortStatus(0);
|
||||
sendXimeaImageStatus(0);
|
||||
sendXimeaImageStatus(100);
|
||||
sendCopyFileStatus(0);
|
||||
|
||||
|
||||
system("sudo gpio write 10 0");
|
||||
|
||||
|
||||
std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl;
|
||||
@ -309,6 +310,18 @@ void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOn
|
||||
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||
}
|
||||
|
||||
void UdpServer::sendXimeaBinState(int spatialBin, int spectralBin)
|
||||
{
|
||||
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
|
||||
|
||||
QByteArray datagram2send;
|
||||
|
||||
QString status = "bin," + QString::number(spatialBin) + "," + QString::number(spectralBin);
|
||||
|
||||
datagram2send.operator =(status.toStdString().c_str());
|
||||
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||
}
|
||||
|
||||
void UdpServer::sendXimeaImageFrameRate(double frameRate)
|
||||
{
|
||||
// std::cout<<"UdpServer::sendXimeaImageFrameRate---------------------:"<< ximeaImageStatus <<std::endl;
|
||||
|
@ -12,6 +12,22 @@ XimeaImager::XimeaImager()
|
||||
if(!m_configfile.isConfigfileExist())
|
||||
m_configfile.createConfigFile();
|
||||
m_configfile.parseConfigfile();
|
||||
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin1, m_iHeightOfSpectralBin1, "bin1");
|
||||
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin2, m_iHeightOfSpectralBin2, "bin2");
|
||||
//检查 ximea.cfg 是否满足要求
|
||||
if(m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2!"<<std::endl;
|
||||
}
|
||||
if(m_iOffsetyOfSpectralBin2 % 2 != 0)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:m_iOffsetyOfSpectralBin2 不是 2 的倍数,ximea相机不接受!"<<std::endl;
|
||||
}
|
||||
if(m_iHeightOfSpectralBin1 < m_iHeightOfSpectralBin2 * 2)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:bin1 波段数小于 bin2 波段数的 2 倍!"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
m_recordTempThread=new QThread();
|
||||
m_ximeaTemperature = new RecordXimeaTemperature(&m_imager);
|
||||
@ -28,6 +44,7 @@ XimeaImager::XimeaImager()
|
||||
|
||||
m_pool = new MemoryPool<DataBuffer>;
|
||||
q = new queue<DataBuffer *>;
|
||||
m_qFrameCounter = new queue<int>;
|
||||
|
||||
m_rgbImage = new rgbImage();
|
||||
}
|
||||
@ -61,10 +78,14 @@ void XimeaImager::openImger()
|
||||
{
|
||||
bool haha = m_imager.setSpectralBin(spectralBin);
|
||||
bool haha2 = m_imager.setSpatialBin(spatialBin);
|
||||
|
||||
emit binSignal(spatialBin, spectralBin);
|
||||
std::cout<<"spectralBin:"<< spectralBin <<std::endl;
|
||||
std::cout<<"spatialBin:"<< spatialBin <<std::endl;
|
||||
}
|
||||
|
||||
float gain, offset;//用于生成头文件中的波长信息
|
||||
ret = m_configfile.getGainOffset(gain, offset);
|
||||
ret = m_configfile.getGainOffsetOfSpectralBin1(gain, offset);
|
||||
if (ret)
|
||||
{
|
||||
m_imager.setGainOffset(gain, offset);
|
||||
@ -78,6 +99,7 @@ void XimeaImager::openImger()
|
||||
m_rgbImage->SetRgbImageWidthAndHeight(height, width, 20);
|
||||
std::cout<<"height:"<< height <<std::endl;
|
||||
std::cout<<"width:"<< width <<std::endl;
|
||||
std::cout<<"每帧字节数:"<< width * height * 2 <<std::endl;
|
||||
}
|
||||
|
||||
// int width_roi = 0, offsetx_roi = 0;
|
||||
@ -471,6 +493,34 @@ int XimeaImager::getImagerState() const
|
||||
return m_iImagerState;
|
||||
}
|
||||
|
||||
double XimeaImager::calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * image, double timeDifferenceBetweenSbgAndOS)
|
||||
{
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndOS: %f s\n", timeDifferenceBetweenSbgAndOS);
|
||||
|
||||
double ximeaTime=image->tsSec + image->tsUSec/1000000;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--ximeaTime: %f s\n", ximeaTime);
|
||||
|
||||
//获取系统时间(纳秒)
|
||||
struct timespec systemTime;
|
||||
clock_gettime(CLOCK_REALTIME,&systemTime);
|
||||
tm systemTime_rili;
|
||||
localtime_r(&systemTime.tv_sec, &systemTime_rili);
|
||||
|
||||
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
|
||||
double timeOS=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--osTime: %f s\n", timeOS);
|
||||
|
||||
|
||||
//计算系统时间和gps时间之间的差距
|
||||
double timeDifferenceBetweenSbgAndximea = timeOS - timeDifferenceBetweenSbgAndOS - ximeaTime;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndximea: %f s\n", timeDifferenceBetweenSbgAndximea);
|
||||
|
||||
return timeDifferenceBetweenSbgAndximea;
|
||||
}
|
||||
|
||||
void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName)
|
||||
{
|
||||
m_ximeaTemperature->stopRecordTemperature();//开始采集影像前,停止获取相机的温度,以免降低帧率;
|
||||
@ -497,23 +547,24 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
|
||||
m_baseFileName=baseFileName;
|
||||
|
||||
|
||||
QString timesFileName=m_baseFileName+".times";
|
||||
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
||||
// ofstream timesFile(timesFileName.toStdString());
|
||||
|
||||
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
|
||||
|
||||
using namespace std;
|
||||
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
|
||||
|
||||
int number_WriteDisk = 100;
|
||||
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
|
||||
writeData2Disk->setParm(q, m_qFrameCounter,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
|
||||
emit startWriteDiskSignal();
|
||||
|
||||
int indexofbuff;
|
||||
DataBuffer * buffer;
|
||||
|
||||
QString timesFileName=m_baseFileName+".times";
|
||||
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
||||
// ofstream timesFile(timesFileName.toStdString());
|
||||
double timeDifferenceBetweenSbgAndXimea;
|
||||
double * sbgTimeBuffer = new double[number_WriteDisk];
|
||||
|
||||
m_imager.start();
|
||||
struct timeval timeStart, timeEnd;
|
||||
double runTime=0;
|
||||
@ -523,11 +574,10 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
unsigned short *x=m_imager.get_frame(m_buffer);
|
||||
m_iFrameCounter+=1;
|
||||
|
||||
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
|
||||
// fwrite(m_imager.m_image.bp,static_cast<int>(m_imager.m_image.bp_size),1,hFile);
|
||||
//fflush(hFile);//只保证了将IO缓冲写入系统缓冲中,使IO读操作能成功,但系统什么时候写入磁盘,由系统决定,一般是达到一定量时系统他就写入磁盘。
|
||||
//sync();//强制系统将系统文件缓冲的内容写入磁盘
|
||||
|
||||
if (m_iFrameCounter == 1)
|
||||
{
|
||||
timeDifferenceBetweenSbgAndXimea = calculateTimeDifferenceBetweenSbgAndximea(&m_imager.m_image, TimeDifferenceBetweensOSAndSbg);
|
||||
}
|
||||
|
||||
indexofbuff = m_iFrameCounter % number_WriteDisk;
|
||||
|
||||
@ -541,48 +591,59 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
if (indexofbuff == 0)
|
||||
{
|
||||
memcpy((void *)buffer->data + (number_WriteDisk - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||
sbgTimeBuffer[number_WriteDisk - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy((void *)buffer->data + (indexofbuff - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||
sbgTimeBuffer[indexofbuff - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
|
||||
}
|
||||
|
||||
if (indexofbuff == 0)
|
||||
{
|
||||
r_qtx.lock();
|
||||
q->push(buffer);
|
||||
m_qFrameCounter->push(number_WriteDisk);
|
||||
r_qtx.unlock();
|
||||
|
||||
for (int i = 0; i < number_WriteDisk; ++i)
|
||||
{
|
||||
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (indexofbuff != 0)
|
||||
{
|
||||
r_qtx.lock();
|
||||
q->push(buffer);
|
||||
m_qFrameCounter->push(indexofbuff);
|
||||
r_qtx.unlock();
|
||||
|
||||
for (int i = 0; i < indexofbuff; ++i)
|
||||
{
|
||||
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
|
||||
}
|
||||
|
||||
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
|
||||
|
||||
fprintf(hHimesFile,"%f\n",sbgTime);
|
||||
// fwrite(&sbgTime,sizeof(double),1,hHimesFile);
|
||||
// timesFile<<sbgTime<< "\n";
|
||||
|
||||
// timesFileHandle << sbgTime << "\n";
|
||||
std::cout << "没凑满: " << indexofbuff <<std::endl;
|
||||
}
|
||||
gettimeofday(&timeEnd, NULL);
|
||||
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
|
||||
m_imager.stop();
|
||||
writeData2Disk->exitWriteData2Disk();
|
||||
writeHdr();
|
||||
|
||||
m_iFrameCounter = m_iFrameCounter - indexofbuff;
|
||||
if (indexofbuff != 0)
|
||||
{
|
||||
m_pool->deleteElement(buffer);
|
||||
}
|
||||
delete[] sbgTimeBuffer;
|
||||
|
||||
double frameInTheory=runTime * getFramerate() - indexofbuff;
|
||||
double frameInTheory=runTime * getFramerate();
|
||||
|
||||
double frameLossed=m_imager.m_image.acq_nframe - indexofbuff - m_iFrameCounter;
|
||||
double frameLossRate=frameLossed / (m_imager.m_image.acq_nframe - indexofbuff);
|
||||
double frameLossed = m_imager.m_image.acq_nframe - m_iFrameCounter;
|
||||
double frameLossRate = frameLossed / m_imager.m_image.acq_nframe;
|
||||
|
||||
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
|
||||
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<< ".bil" <<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<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe - indexofbuff<<std::endl;
|
||||
std::cout<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe<<std::endl;
|
||||
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
|
||||
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
|
||||
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
|
||||
@ -594,8 +655,6 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
timeStr = formatTimeStr(timeFormat);
|
||||
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
|
||||
|
||||
writeHdr();
|
||||
|
||||
m_iImagerState=m_iImagerStateTemp;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
@ -641,6 +700,9 @@ void XimeaImager::writeHdr()
|
||||
hdrFileHandle << "wavelength units = nanometers\n";
|
||||
hdrFileHandle << "wavelength = {";
|
||||
//hdrFileHandle << std::setprecision(5);
|
||||
|
||||
if (m_imager.getSpectralBin() == 1)
|
||||
{
|
||||
for (int i = getWindowStartBand(); i < getWindowEndBand(); i++)
|
||||
{
|
||||
hdrFileHandle << geWavelengthAtBand(i);
|
||||
@ -651,6 +713,30 @@ void XimeaImager::writeHdr()
|
||||
printf("头文件中写入了多少个波段:%d\n",i-getWindowStartBand()+1);//???????????????
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_imager.getSpectralBin() == 2)
|
||||
{
|
||||
int counter = 0;
|
||||
for (int i = m_iOffsetyOfSpectralBin2; i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2; i++)
|
||||
{
|
||||
if (i*2 + 1 > m_iOffsetyOfSpectralBin1 + m_iHeightOfSpectralBin1)
|
||||
{
|
||||
printf("XimeaImager::writeHdr 出现错误:窗口中,光谱 bin1 波段数小于 bin2 的 2 倍。\n");
|
||||
break;
|
||||
}
|
||||
|
||||
hdrFileHandle << (geWavelengthAtBand(i*2) + geWavelengthAtBand(i*2 + 1)) / 2;
|
||||
counter++;
|
||||
if (i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 - 1)
|
||||
hdrFileHandle << ", ";
|
||||
else
|
||||
{
|
||||
printf("头文件中写入了多少个波段:%d\n", counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hdrFileHandle << "}\n";
|
||||
hdrFileHandle.close();
|
||||
}
|
||||
@ -852,9 +938,31 @@ WriteData2Disk::WriteData2Disk()
|
||||
void WriteData2Disk::write2Disk()
|
||||
{
|
||||
QString imageFileName=m_QbaseFileName+".bil";
|
||||
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
||||
// FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
||||
|
||||
|
||||
int fd = open(imageFileName.toStdString().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
|
||||
size_t fileSize = m_iFrameSizeInByte*(size_t)100*(size_t)60*(size_t)5;
|
||||
size_t fileSizeIncrement = m_iFrameSizeInByte*(size_t)100*(size_t)60*(size_t)5;
|
||||
if (lseek(fd, fileSize - 1, SEEK_SET) == -1) {
|
||||
std::cerr << "Error calling lseek()\n";
|
||||
return;
|
||||
}
|
||||
if (write(fd, "", 1) == -1) {
|
||||
std::cerr << "Error writing last byte of the file\n";
|
||||
return;
|
||||
}
|
||||
void* addr = mmap(nullptr, fileSize, PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error mmapping the file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
size_t sizeWrited2disk = 0;
|
||||
|
||||
int frameCounter = 0;
|
||||
int frameNumber;
|
||||
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2*m_iNumber_WriteDisk];
|
||||
isExitWriteData2Disk = false;
|
||||
while(true)
|
||||
@ -875,10 +983,12 @@ void WriteData2Disk::write2Disk()
|
||||
|
||||
r_qtx.lock();
|
||||
DataBuffer * buffer = m_q->front();
|
||||
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*m_iNumber_WriteDisk);
|
||||
int frameNumber = m_qFrameCounter->front();
|
||||
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*frameNumber);
|
||||
// m_pool->destroy(m_q->front());
|
||||
m_pool->deleteElement(buffer);
|
||||
m_q->pop();
|
||||
m_qFrameCounter->pop();
|
||||
r_qtx.unlock();
|
||||
|
||||
//构造rgb图像,用于推流到m300遥控器
|
||||
@ -886,14 +996,73 @@ void WriteData2Disk::write2Disk()
|
||||
|
||||
|
||||
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
|
||||
fwrite(dataBuffer,1,m_iFrameSizeInByte*m_iNumber_WriteDisk, hFile);
|
||||
|
||||
|
||||
if (fileSize < sizeWrited2disk + m_iFrameSizeInByte*frameNumber)
|
||||
{
|
||||
// if (munmap(addr, fileSize) == -1) {
|
||||
// std::cerr << "Error un-mmapping the file\n";
|
||||
// }
|
||||
|
||||
// std::cout<<"老fileSize:" << fileSize <<std::endl;
|
||||
size_t new_size = fileSize + fileSizeIncrement;
|
||||
if (ftruncate(fd, new_size) == -1) {
|
||||
std::cerr << "Error calling ftruncate()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Remap the file with the new size
|
||||
addr = mremap(addr, fileSize, new_size, MREMAP_MAYMOVE);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error calling mremap()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
fileSize = new_size;
|
||||
// std::cout<<"新fileSize:" << fileSize <<std::endl;
|
||||
|
||||
}
|
||||
// fwrite(dataBuffer,1,m_iFrameSizeInByte*frameNumber, hFile);
|
||||
memcpy(addr + sizeWrited2disk, dataBuffer, m_iFrameSizeInByte*frameNumber);
|
||||
|
||||
sizeWrited2disk = sizeWrited2disk + m_iFrameSizeInByte*frameNumber;
|
||||
// std::cout<<"sizeWrited2disk:" << sizeWrited2disk <<std::endl;
|
||||
|
||||
frameCounter++;
|
||||
}
|
||||
m_rgbImage->m_VideoWriter.release();
|
||||
fclose(hFile);
|
||||
// fclose(hFile);
|
||||
delete[] dataBuffer;
|
||||
|
||||
|
||||
|
||||
|
||||
// if (munmap(addr, fileSize) == -1) {
|
||||
// std::cerr << "Error un-mmapping the file\n";
|
||||
// }
|
||||
|
||||
// Resize the file to 4096 bytes
|
||||
if (ftruncate(fd, sizeWrited2disk) == -1) {
|
||||
std::cerr << "Error calling ftruncate()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Remap the file with the new size
|
||||
addr = mremap(addr, fileSize, sizeWrited2disk, MREMAP_MAYMOVE);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error calling mremap()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (munmap(addr, sizeWrited2disk) == -1) {
|
||||
std::cerr << "Error un-mmapping the file\n";
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter*m_iNumber_WriteDisk <<std::endl;
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,fwrite 调用次数:" << frameCounter <<std::endl;
|
||||
}
|
||||
|
||||
void WriteData2Disk::exitWriteData2Disk()
|
||||
@ -901,9 +1070,10 @@ void WriteData2Disk::exitWriteData2Disk()
|
||||
isExitWriteData2Disk = true;
|
||||
}
|
||||
|
||||
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
||||
void WriteData2Disk::setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
||||
{
|
||||
m_q = q;
|
||||
m_qFrameCounter = qFrameCounter;
|
||||
m_QbaseFileName = baseFileName;
|
||||
m_iFrameSizeInByte = frameSizeInByte;
|
||||
m_iNumber_WriteDisk = number_WriteDisk;
|
||||
|
Reference in New Issue
Block a user