Compare commits
6 Commits
447a1aafb1
...
34
Author | SHA1 | Date | |
---|---|---|---|
6b78db5bc3 | |||
73f9b00b02 | |||
6fc2680a1c | |||
09d224075a | |||
371c422a34 | |||
b31cd5fc8a |
@ -26,7 +26,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
template <typename T, size_t BlockSize = 16368000>
|
template <typename T, size_t BlockSize = 409200000>
|
||||||
class MemoryPool
|
class MemoryPool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
#include "utility_tc.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace libconfig;
|
using namespace libconfig;
|
||||||
|
|
||||||
@ -35,6 +37,9 @@ public:
|
|||||||
bool getGainOffset(float &gain, float &offset);
|
bool getGainOffset(float &gain, float &offset);
|
||||||
bool getSN(QString &SN);
|
bool getSN(QString &SN);
|
||||||
|
|
||||||
|
bool getBufferPolicy(int &bufferPolicy);
|
||||||
|
bool getAcqBufferSize(int &acqBufferSize);
|
||||||
|
|
||||||
bool createConfigFile();
|
bool createConfigFile();
|
||||||
bool updateConfigFile();
|
bool updateConfigFile();
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ public slots:
|
|||||||
void sendSbgAccuracyState(int Accuracy,int SatelliteCounter);
|
void sendSbgAccuracyState(int Accuracy,int SatelliteCounter);
|
||||||
|
|
||||||
void sendXimeaImageStatus(int ximeaImageStatus);
|
void sendXimeaImageStatus(int ximeaImageStatus);
|
||||||
|
void sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime);
|
||||||
|
void sendXimeaImageFrameRate(double frameRate);
|
||||||
void sendCopyFileStatus(int fileStatus);
|
void sendCopyFileStatus(int fileStatus);
|
||||||
};
|
};
|
||||||
#endif // UDPSERVER_H
|
#endif // UDPSERVER_H
|
||||||
|
@ -16,4 +16,8 @@ void bubbleSort(unsigned short * a, int n);
|
|||||||
|
|
||||||
void swap(unsigned short * a, unsigned short * b);
|
void swap(unsigned short * a, unsigned short * b);
|
||||||
|
|
||||||
|
bool createDir(QString fullPath);
|
||||||
|
|
||||||
|
QList<QString> getFileInfo(QString file);
|
||||||
|
|
||||||
#endif // UTILITY_TC_H
|
#endif // UTILITY_TC_H
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -62,7 +64,7 @@ public:
|
|||||||
DataBuffer();
|
DataBuffer();
|
||||||
~DataBuffer();
|
~DataBuffer();
|
||||||
|
|
||||||
unsigned short data[425600];//304*1400=425600,为了兼容所有设置spectral bin和spatial bin
|
unsigned short data[41040000];//1368*300*100=41040000,为了兼容所有设置spectral bin和spatial bin
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -98,18 +100,21 @@ Q_OBJECT
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
WriteData2Disk();
|
WriteData2Disk();
|
||||||
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
queue<DataBuffer *> * m_q;
|
queue<DataBuffer *> * m_q;
|
||||||
QString m_QbaseFileName;
|
QString m_QbaseFileName;
|
||||||
int m_iFrameSizeInByte;
|
int m_iFrameSizeInByte;
|
||||||
|
int m_iNumber_WriteDisk;
|
||||||
MemoryPool<DataBuffer> * m_pool;
|
MemoryPool<DataBuffer> * m_pool;
|
||||||
|
bool isExitWriteData2Disk;
|
||||||
|
|
||||||
rgbImage * m_rgbImage;
|
rgbImage * m_rgbImage;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void write2Disk();
|
void write2Disk();
|
||||||
|
void exitWriteData2Disk();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
@ -125,7 +130,7 @@ public:
|
|||||||
void setFramerate(double framerate);
|
void setFramerate(double framerate);
|
||||||
double getFramerate();
|
double getFramerate();
|
||||||
double setExposureTime(float exposureTime);
|
double setExposureTime(float exposureTime);
|
||||||
double wrapSetExposureTime(float exposureTime_in_us);
|
int wrapSetExposureTime(float exposureTime_in_us);
|
||||||
double getExposureTime();
|
double getExposureTime();
|
||||||
double autoExposure();
|
double autoExposure();
|
||||||
void setGain(double gain);
|
void setGain(double gain);
|
||||||
@ -139,6 +144,7 @@ public:
|
|||||||
|
|
||||||
void stopRecord();
|
void stopRecord();
|
||||||
int getFrameCounter();
|
int getFrameCounter();
|
||||||
|
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
|
||||||
|
|
||||||
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
|
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
|
||||||
|
|
||||||
@ -205,5 +211,8 @@ signals:
|
|||||||
|
|
||||||
void recordXimeaTemperatureSignal(QString);
|
void recordXimeaTemperatureSignal(QString);
|
||||||
void startWriteDiskSignal();
|
void startWriteDiskSignal();
|
||||||
|
|
||||||
|
void autoExposeMaxValueOfOneFrame(int, double);
|
||||||
|
void frameRateSignal(double);
|
||||||
};
|
};
|
||||||
#endif // XIMEAIMAGER_H
|
#endif // XIMEAIMAGER_H
|
||||||
|
@ -222,6 +222,50 @@ bool Configfile::getSN(QString &SN)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Configfile::getBufferPolicy(int &bufferPolicy)
|
||||||
|
{
|
||||||
|
const Setting& root = cfg.getRoot();
|
||||||
|
const Setting &ximeadll = root["ximeadll"];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
|
||||||
|
))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const SettingNotFoundException &nfex)
|
||||||
|
{
|
||||||
|
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Configfile::getAcqBufferSize(int &acqBufferSize)
|
||||||
|
{
|
||||||
|
const Setting& root = cfg.getRoot();
|
||||||
|
const Setting &ximeadll = root["ximeadll"];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
|
||||||
|
))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const SettingNotFoundException &nfex)
|
||||||
|
{
|
||||||
|
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Configfile::createConfigFile()
|
bool Configfile::createConfigFile()
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -279,10 +323,18 @@ bool Configfile::createConfigFile()
|
|||||||
gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
|
gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
|
||||||
|
|
||||||
|
|
||||||
|
Setting &ximeadll = root.add("ximeadll", Setting::TypeGroup);
|
||||||
|
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
|
||||||
|
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
|
||||||
|
|
||||||
|
|
||||||
// Write out the new configuration.
|
// Write out the new configuration.
|
||||||
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
|
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
QList<QString> fileInfo = getFileInfo(output_file);
|
||||||
|
bool ret = createDir(fileInfo[0]);
|
||||||
|
|
||||||
cfg.writeFile(output_file.toStdString().c_str());
|
cfg.writeFile(output_file.toStdString().c_str());
|
||||||
cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;
|
cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;
|
||||||
|
|
||||||
|
@ -789,7 +789,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
|
|||||||
|
|
||||||
m_baseFileName=getFileNameBaseOnTime();
|
m_baseFileName=getFileNameBaseOnTime();
|
||||||
|
|
||||||
QString sbgFileName=m_baseFileName+".sbg";
|
QString sbgFileName=m_baseFileName+".bin";
|
||||||
|
|
||||||
FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b");
|
FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b");
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@ UdpServer::UdpServer()
|
|||||||
connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int,int)),this, SLOT(sendSbgAccuracyState(int,int)));
|
connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int,int)),this, SLOT(sendSbgAccuracyState(int,int)));
|
||||||
|
|
||||||
connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int)));
|
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(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
|
||||||
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
|
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
|
||||||
|
|
||||||
|
|
||||||
@ -122,26 +124,19 @@ void UdpServer::processPendingDatagrams()
|
|||||||
}
|
}
|
||||||
case 3://系统开始采集高光谱影像
|
case 3://系统开始采集高光谱影像
|
||||||
{
|
{
|
||||||
//emit startRecordHyperspectralSignal();//真实的影像开始采集通过惯导中的信号(sbgReady)触发
|
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
|
||||||
m_sbgRecorder->startRecordHyperspectral();
|
{
|
||||||
|
std::cout<<"3代表系统开始采集高光谱影像!"<<std::endl;
|
||||||
// if(m_sbgRecorder->getSbgState()==2)//开始采集前还需要判断相机的状态??????????????????????????????????????????
|
m_sbgRecorder->startRecordHyperspectral();
|
||||||
// {
|
}
|
||||||
|
|
||||||
// }
|
|
||||||
// else if(m_sbgRecorder->getSbgState()==3)
|
|
||||||
// {
|
|
||||||
// std::cout<<"系统已经开始采集!"<<std::endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4://系统停止采集高光谱影像
|
case 4://系统停止采集高光谱影像
|
||||||
{
|
{
|
||||||
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
|
|
||||||
|
|
||||||
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104)
|
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104)
|
||||||
{
|
{
|
||||||
|
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
|
||||||
m_imager->stopRecord();
|
m_imager->stopRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,9 +164,12 @@ void UdpServer::processPendingDatagrams()
|
|||||||
}
|
}
|
||||||
case 7:
|
case 7:
|
||||||
{
|
{
|
||||||
float time = datagramList[1].toFloat();//ms
|
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
|
||||||
m_imager->wrapSetExposureTime(time*1000);
|
{
|
||||||
std::cout<<"7,手动设置曝光时间为:" << time <<std::endl;
|
float time = datagramList[1].toFloat();//ms
|
||||||
|
m_imager->wrapSetExposureTime(time*1000);
|
||||||
|
std::cout<<"7,手动设置曝光时间为:" << time <<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -299,6 +297,30 @@ void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
|
|||||||
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime)
|
||||||
|
{
|
||||||
|
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
|
||||||
|
|
||||||
|
QByteArray datagram2send;
|
||||||
|
|
||||||
|
QString status = "XimeaAutoExpose," + QString::number(autoExposeMaxValueOfOneFrame) + "," + QString::number(exposeTime, 'f', 2);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
QByteArray datagram2send;
|
||||||
|
|
||||||
|
QString status = "XimeaFrameRate," + QString::number(frameRate, 'f', 2);
|
||||||
|
|
||||||
|
datagram2send.operator =(status.toStdString().c_str());
|
||||||
|
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||||
|
}
|
||||||
|
|
||||||
void UdpServer::sendCopyFileStatus(int fileStatus)
|
void UdpServer::sendCopyFileStatus(int fileStatus)
|
||||||
{
|
{
|
||||||
// std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
|
// std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
|
||||||
|
@ -88,3 +88,36 @@ void swap(unsigned short * a, unsigned short * b)
|
|||||||
*a=*b;
|
*a=*b;
|
||||||
*b=tmp;
|
*b=tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool createDir(QString fullPath)
|
||||||
|
{
|
||||||
|
QDir dir(fullPath);
|
||||||
|
if (dir.exists()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
bool ok = dir.mkpath(fullPath);//创建多级目录
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QString> getFileInfo(QString file)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo = QFileInfo(file);
|
||||||
|
|
||||||
|
QString fileName, fileSuffix, filePath;
|
||||||
|
filePath = fileInfo.absolutePath();//绝对路径
|
||||||
|
fileName = fileInfo.fileName();//文件名
|
||||||
|
fileSuffix = fileInfo.suffix();//文件后缀
|
||||||
|
|
||||||
|
// qDebug() << fileName <<endl
|
||||||
|
// << fileSuffix<< endl
|
||||||
|
// << filePath<< endl;
|
||||||
|
|
||||||
|
QList<QString> result;
|
||||||
|
result.append(filePath);
|
||||||
|
result.append(fileName);
|
||||||
|
result.append(fileSuffix);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -7,8 +7,6 @@ XimeaImager::XimeaImager()
|
|||||||
m_iFrameCounter=0;
|
m_iFrameCounter=0;
|
||||||
m_iImagerState=100;
|
m_iImagerState=100;
|
||||||
|
|
||||||
//connect(this, SIGNAL(recordFinished()),this, SLOT());
|
|
||||||
|
|
||||||
QString ximeaCfgFile = "/media/nvme/300TC/config/ximea.cfg";
|
QString ximeaCfgFile = "/media/nvme/300TC/config/ximea.cfg";
|
||||||
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
|
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
|
||||||
if(!m_configfile.isConfigfileExist())
|
if(!m_configfile.isConfigfileExist())
|
||||||
@ -89,6 +87,18 @@ void XimeaImager::openImger()
|
|||||||
// m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi);
|
// m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
int bufferPolicy, acqBufferSize;
|
||||||
|
ret1 = m_configfile.getBufferPolicy(bufferPolicy);
|
||||||
|
if (ret1)
|
||||||
|
{
|
||||||
|
m_imager.setBufferPolicy(bufferPolicy);
|
||||||
|
}
|
||||||
|
ret1 = m_configfile.getAcqBufferSize(acqBufferSize);
|
||||||
|
if (ret1)
|
||||||
|
{
|
||||||
|
m_imager.setAcqBufferSize(acqBufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
setFramerate(100);
|
setFramerate(100);
|
||||||
|
|
||||||
//经验证:frameSizeManual和frameSizeAuto相等
|
//经验证:frameSizeManual和frameSizeAuto相等
|
||||||
@ -160,6 +170,8 @@ void XimeaImager::setFramerate(double framerate)
|
|||||||
|
|
||||||
m_iImagerState=102;
|
m_iImagerState=102;
|
||||||
emit ximeaImageStatus(m_iImagerState);
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
|
||||||
|
emit frameRateSignal(framerate);
|
||||||
}
|
}
|
||||||
catch(int xiApiErrorCodes)
|
catch(int xiApiErrorCodes)
|
||||||
{
|
{
|
||||||
@ -216,12 +228,22 @@ double XimeaImager::setExposureTime(float exposureTime_in_us)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double XimeaImager::wrapSetExposureTime(float exposureTime_in_us)
|
int XimeaImager::wrapSetExposureTime(float exposureTime_in_us)
|
||||||
{
|
{
|
||||||
setExposureTime(exposureTime_in_us);
|
double exposureTime = setExposureTime(exposureTime_in_us);
|
||||||
|
|
||||||
|
m_imager.start();
|
||||||
|
m_imager.get_frame(m_buffer);
|
||||||
|
m_imager.stop();
|
||||||
|
|
||||||
|
int maxValueOfOneFrame = getMaxValueOfOneFrame((short unsigned int*)m_imager.m_image.bp,m_imager.get_band_count()*m_imager.get_sample_count());
|
||||||
|
|
||||||
m_iImagerState=103;
|
m_iImagerState=103;
|
||||||
emit ximeaImageStatus(m_iImagerState);
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
|
||||||
|
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
|
||||||
|
|
||||||
|
return maxValueOfOneFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
double XimeaImager::autoExposure()
|
double XimeaImager::autoExposure()
|
||||||
@ -247,6 +269,7 @@ double XimeaImager::autoExposure()
|
|||||||
m_imager.stop();
|
m_imager.stop();
|
||||||
|
|
||||||
maxValueOfOneFrame=getMaxValueOfOneFrame((short unsigned int*)m_imager.m_image.bp,m_imager.get_band_count()*m_imager.get_sample_count());
|
maxValueOfOneFrame=getMaxValueOfOneFrame((short unsigned int*)m_imager.m_image.bp,m_imager.get_band_count()*m_imager.get_sample_count());
|
||||||
|
printf("本帧最大值为: %d.\n",maxValueOfOneFrame);
|
||||||
|
|
||||||
if(maxValueOfOneFrame <= suitableMaxValue)
|
if(maxValueOfOneFrame <= suitableMaxValue)
|
||||||
{
|
{
|
||||||
@ -281,6 +304,7 @@ double XimeaImager::autoExposure()
|
|||||||
|
|
||||||
m_iImagerState=103;
|
m_iImagerState=103;
|
||||||
emit ximeaImageStatus(m_iImagerState);
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
|
||||||
|
|
||||||
std::cout<<"自动曝光完成!"<<std::endl;
|
std::cout<<"自动曝光完成!"<<std::endl;
|
||||||
return exposureTime;
|
return exposureTime;
|
||||||
@ -438,7 +462,6 @@ int XimeaImager::getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel)
|
|||||||
int a=0;
|
int a=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("本帧最大值为: %d.\n",maxValue);
|
|
||||||
|
|
||||||
return maxValue;
|
return maxValue;
|
||||||
}
|
}
|
||||||
@ -477,14 +500,20 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
|||||||
|
|
||||||
QString timesFileName=m_baseFileName+".times";
|
QString timesFileName=m_baseFileName+".times";
|
||||||
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
||||||
|
// ofstream timesFile(timesFileName.toStdString());
|
||||||
|
|
||||||
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
|
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
|
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
|
||||||
|
|
||||||
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, m_pool, m_rgbImage);
|
int number_WriteDisk = 100;
|
||||||
|
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
|
||||||
emit startWriteDiskSignal();
|
emit startWriteDiskSignal();
|
||||||
|
|
||||||
|
int indexofbuff;
|
||||||
|
DataBuffer * buffer;
|
||||||
|
|
||||||
m_imager.start();
|
m_imager.start();
|
||||||
struct timeval timeStart, timeEnd;
|
struct timeval timeStart, timeEnd;
|
||||||
double runTime=0;
|
double runTime=0;
|
||||||
@ -492,6 +521,7 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
|||||||
while (m_bRecordControl)
|
while (m_bRecordControl)
|
||||||
{
|
{
|
||||||
unsigned short *x=m_imager.get_frame(m_buffer);
|
unsigned short *x=m_imager.get_frame(m_buffer);
|
||||||
|
m_iFrameCounter+=1;
|
||||||
|
|
||||||
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
|
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
|
||||||
// fwrite(m_imager.m_image.bp,static_cast<int>(m_imager.m_image.bp_size),1,hFile);
|
// fwrite(m_imager.m_image.bp,static_cast<int>(m_imager.m_image.bp_size),1,hFile);
|
||||||
@ -499,56 +529,67 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
|||||||
//sync();//强制系统将系统文件缓冲的内容写入磁盘
|
//sync();//强制系统将系统文件缓冲的内容写入磁盘
|
||||||
|
|
||||||
|
|
||||||
|
indexofbuff = m_iFrameCounter % number_WriteDisk;
|
||||||
|
|
||||||
r_qtx.lock();
|
if (indexofbuff == 1)
|
||||||
DataBuffer * buffer = m_pool->newElement();
|
{
|
||||||
r_qtx.unlock();
|
r_qtx.lock();
|
||||||
// m_pool->construct(buffer);
|
buffer = m_pool->newElement();
|
||||||
|
r_qtx.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
// memcpy(buffer->data,(unsigned short *)m_imager.m_image.bp,m_iFrameSizeInByte/2);
|
if (indexofbuff == 0)
|
||||||
memcpy((void *)buffer->data,m_imager.m_image.bp,m_iFrameSizeInByte);
|
{
|
||||||
|
memcpy((void *)buffer->data + (number_WriteDisk - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy((void *)buffer->data + (indexofbuff - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||||
|
}
|
||||||
|
|
||||||
r_qtx.lock();
|
if (indexofbuff == 0)
|
||||||
q->push(buffer);
|
{
|
||||||
r_qtx.unlock();//
|
r_qtx.lock();
|
||||||
|
q->push(buffer);
|
||||||
// std::cout<<"XimeaImager::startRecord,队列长度为:"<< q->size() <<std::endl;//
|
r_qtx.unlock();
|
||||||
|
}
|
||||||
// fwrite(buffer,1,m_iFrameSizeInByte,hFile);
|
|
||||||
|
|
||||||
m_iFrameCounter+=1;
|
|
||||||
|
|
||||||
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
|
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
|
||||||
|
|
||||||
fprintf(hHimesFile,"%f\n",sbgTime);
|
fprintf(hHimesFile,"%f\n",sbgTime);
|
||||||
//fwrite(&sbgTime,sizeof(double),1,hHimesFile);
|
// fwrite(&sbgTime,sizeof(double),1,hHimesFile);
|
||||||
|
// timesFile<<sbgTime<< "\n";
|
||||||
|
|
||||||
// timesFileHandle << sbgTime << "\n";
|
// timesFileHandle << sbgTime << "\n";
|
||||||
// std::cout<<"XimeaImager::startRecord---std::cout: "<<sbgTime<<std::endl;
|
|
||||||
|
|
||||||
// unsigned char pixel = *(unsigned char*)image.bp;//Default value: XI_MONO8
|
|
||||||
// unsigned short pixel =*(unsigned short*)image.bp;//XI_RAW16
|
|
||||||
// printf("Image %d (%dx%d) received from camera. First pixel value: %d\n", m_iFrameCounter, (int)image.width, (int)image.height, pixel);
|
|
||||||
}
|
}
|
||||||
gettimeofday(&timeEnd, NULL);
|
gettimeofday(&timeEnd, NULL);
|
||||||
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
|
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
|
||||||
m_imager.stop();
|
m_imager.stop();
|
||||||
|
writeData2Disk->exitWriteData2Disk();
|
||||||
|
|
||||||
double frameInTheory=runTime * getFramerate();
|
m_iFrameCounter = m_iFrameCounter - indexofbuff;
|
||||||
double frameLossed=frameInTheory - m_iFrameCounter;
|
if (indexofbuff != 0)
|
||||||
double frameLossRate=frameLossed / frameInTheory;
|
{
|
||||||
|
m_pool->deleteElement(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
double frameInTheory=runTime * getFramerate() - indexofbuff;
|
||||||
|
|
||||||
|
double frameLossed=m_imager.m_image.acq_nframe - indexofbuff - m_iFrameCounter;
|
||||||
|
double frameLossRate=frameLossed / (m_imager.m_image.acq_nframe - indexofbuff);
|
||||||
|
|
||||||
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
|
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
|
||||||
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
|
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
|
||||||
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
|
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
|
||||||
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
|
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
|
||||||
std::cout<<"理论采集帧数为: "<<frameInTheory<<std::endl;
|
std::cout<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe - indexofbuff<<std::endl;
|
||||||
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
|
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
|
||||||
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
|
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
|
||||||
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
|
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
|
||||||
|
|
||||||
fclose(hHimesFile);
|
fclose(hHimesFile);
|
||||||
// timesFileHandle.close();
|
// timesFileHandle.close();
|
||||||
|
// timesFile.close();
|
||||||
|
|
||||||
timeStr = formatTimeStr(timeFormat);
|
timeStr = formatTimeStr(timeFormat);
|
||||||
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
|
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
|
||||||
@ -688,6 +729,18 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
|
|||||||
m_iImagerState=xiApiErrorCodes;
|
m_iImagerState=xiApiErrorCodes;
|
||||||
emit ximeaImageStatus(m_iImagerState);
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Timeout!"<<std::endl;
|
||||||
|
m_iImagerState=xiApiErrorCodes;
|
||||||
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Invalid arguments supplied!"<<std::endl;
|
||||||
|
m_iImagerState=xiApiErrorCodes;
|
||||||
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
|
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
|
||||||
@ -714,20 +767,26 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
QString ximeaError="ximeaError.txt";
|
|
||||||
ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app);
|
|
||||||
|
|
||||||
ximeaErrorFile<< xiApiErrorCodes << "\n";
|
|
||||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:未处理ximea异常代码:"<< xiApiErrorCodes <<std::endl;
|
|
||||||
|
|
||||||
ximeaErrorFile.close();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_iImagerState=99;
|
m_iImagerState=99;
|
||||||
emit ximeaImageStatus(m_iImagerState);
|
emit ximeaImageStatus(m_iImagerState);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeXiApiErrorCodes("/media/nvme/300TC/ximeaError.txt", xiApiErrorCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XimeaImager::writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes)
|
||||||
|
{
|
||||||
|
ofstream ximeaErrorFile(filePath.toStdString().c_str(),ios::app);
|
||||||
|
|
||||||
|
char * timeFormat="%Y%m%d_%H%M%S";
|
||||||
|
QString timeStr = formatTimeStr(timeFormat);
|
||||||
|
|
||||||
|
ximeaErrorFile<< timeStr.toStdString().c_str() << ": " << xiApiErrorCodes << "\n";
|
||||||
|
|
||||||
|
std::cout<<"XimeaImager::writeXiApiErrorCodes-----------:xiApiErrorCodes: "<<timeStr.toStdString().c_str()<< ": " << xiApiErrorCodes<<std::endl;
|
||||||
|
|
||||||
|
ximeaErrorFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XimeaImager::stopRecord()
|
void XimeaImager::stopRecord()
|
||||||
@ -787,6 +846,7 @@ void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
|
|||||||
|
|
||||||
WriteData2Disk::WriteData2Disk()
|
WriteData2Disk::WriteData2Disk()
|
||||||
{
|
{
|
||||||
|
isExitWriteData2Disk = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteData2Disk::write2Disk()
|
void WriteData2Disk::write2Disk()
|
||||||
@ -794,57 +854,59 @@ void WriteData2Disk::write2Disk()
|
|||||||
QString imageFileName=m_QbaseFileName+".bil";
|
QString imageFileName=m_QbaseFileName+".bil";
|
||||||
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
||||||
|
|
||||||
int sleepCounters=1;
|
|
||||||
int frameCounter = 0;
|
int frameCounter = 0;
|
||||||
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2];
|
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2*m_iNumber_WriteDisk];
|
||||||
|
isExitWriteData2Disk = false;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
r_qtx.lock();
|
r_qtx.lock();
|
||||||
bool bempty=m_q->empty();
|
bool bempty=m_q->empty();
|
||||||
r_qtx.unlock();
|
r_qtx.unlock();
|
||||||
if(bempty)
|
if(bempty && isExitWriteData2Disk)
|
||||||
|
{
|
||||||
|
std::cout<<"WriteData2Disk::write2Disk-----------------------队列为空,采集线程已经退出!"<<std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(bempty && !isExitWriteData2Disk)
|
||||||
{
|
{
|
||||||
QThread::msleep(sleepCounters * sleepCounters * 10);
|
|
||||||
// std::cout<<"WriteData2Disk::write2Disk-----------------------队列第几次为空:" << sleepCounters <<std::endl;
|
|
||||||
sleepCounters++;
|
|
||||||
|
|
||||||
if (sleepCounters == 10 && frameCounter != 0)//如果sleepCounters == 10时,队列还是空,就代表相机停止采集 → 退出此线程
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sleepCounters = 1;
|
|
||||||
|
|
||||||
|
|
||||||
r_qtx.lock();
|
r_qtx.lock();
|
||||||
DataBuffer * buffer = m_q->front();
|
DataBuffer * buffer = m_q->front();
|
||||||
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte);
|
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*m_iNumber_WriteDisk);
|
||||||
// m_pool->destroy(m_q->front());
|
// m_pool->destroy(m_q->front());
|
||||||
m_pool->deleteElement(buffer);
|
m_pool->deleteElement(buffer);
|
||||||
m_q->pop();
|
m_q->pop();
|
||||||
r_qtx.unlock();
|
r_qtx.unlock();
|
||||||
|
|
||||||
//构造rgb图像,用于推流到m300遥控器
|
//构造rgb图像,用于推流到m300遥控器
|
||||||
m_rgbImage->FillRgbImage(dataBuffer);
|
// m_rgbImage->FillRgbImage(dataBuffer);
|
||||||
|
|
||||||
|
|
||||||
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
|
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
|
||||||
fwrite(dataBuffer,1,m_iFrameSizeInByte, hFile);
|
fwrite(dataBuffer,1,m_iFrameSizeInByte*m_iNumber_WriteDisk, hFile);
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
}
|
}
|
||||||
m_rgbImage->m_VideoWriter.release();
|
m_rgbImage->m_VideoWriter.release();
|
||||||
|
fclose(hFile);
|
||||||
|
|
||||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
|
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
|
||||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter <<std::endl;
|
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter*m_iNumber_WriteDisk <<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
void WriteData2Disk::exitWriteData2Disk()
|
||||||
|
{
|
||||||
|
isExitWriteData2Disk = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
||||||
{
|
{
|
||||||
m_q = q;
|
m_q = q;
|
||||||
m_QbaseFileName = baseFileName;
|
m_QbaseFileName = baseFileName;
|
||||||
m_iFrameSizeInByte = frameSizeInByte;
|
m_iFrameSizeInByte = frameSizeInByte;
|
||||||
|
m_iNumber_WriteDisk = number_WriteDisk;
|
||||||
|
|
||||||
m_pool = pool;
|
m_pool = pool;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user