217 lines
5.0 KiB
C++
217 lines
5.0 KiB
C++
#ifndef XIMEAIMAGER_H
|
||
#define XIMEAIMAGER_H
|
||
|
||
/*
|
||
This is the reference example application code for XIMEA cameras.
|
||
You can use it to simplify development of your camera application.
|
||
|
||
Sample name:
|
||
xiAPI / Capture-10-images
|
||
|
||
Description:
|
||
Open camera, capture 10 images while printing first pixel from each image.
|
||
|
||
Workflow:
|
||
1: Open camera
|
||
2: Set parameters
|
||
3: Start acquisition
|
||
4: Each image captured - print dimensions and value of the first pixel
|
||
*/
|
||
|
||
#include <stdio.h>
|
||
#include <iostream>
|
||
#include <sys/time.h>
|
||
#include <memory.h>
|
||
#include <fstream>
|
||
#include <unistd.h>
|
||
#include <exception>
|
||
#include <fcntl.h>
|
||
#include <sys/mman.h>
|
||
|
||
#include <QObject>
|
||
#include <QDateTime>
|
||
#include <qthread.h>
|
||
#include <QDir>
|
||
|
||
#include "configfile.h"
|
||
|
||
#include "irisximeaimager.h"
|
||
#include "math.h"
|
||
#include "utility_tc.h"
|
||
|
||
#include "MemoryPool.h"
|
||
#include <queue>
|
||
#include <QMutex>
|
||
|
||
#include "rgbImage.h"
|
||
|
||
|
||
|
||
//#ifdef WIN32
|
||
//#include <xiApi.h> // Windows
|
||
//#else
|
||
//#include <m3api/xiApi.h> // Linux, OSX
|
||
//#endif
|
||
|
||
//struct DataBuffer
|
||
//{
|
||
// unsigned short data[409200/2];
|
||
//};
|
||
|
||
class DataBuffer
|
||
{
|
||
public:
|
||
DataBuffer();
|
||
~DataBuffer();
|
||
|
||
unsigned short data[41040000];//1368*300*100=41040000,为了兼容所有设置spectral bin和spatial bin
|
||
|
||
private:
|
||
|
||
};
|
||
|
||
class RecordXimeaTemperature : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
RecordXimeaTemperature(Iris::IrisXimeaImager * imager);
|
||
|
||
void stopRecordTemperature();
|
||
|
||
private:
|
||
Iris::IrisXimeaImager * m_imager;
|
||
|
||
bool m_bIsRecord;
|
||
public slots:
|
||
void recordTemperature(QString filePath);
|
||
|
||
signals:
|
||
|
||
};
|
||
|
||
//queue<DataBuffer *> q;
|
||
//static QMutex r_qtx{ QMutex::Recursive };
|
||
static std::mutex r_qtx;
|
||
|
||
class WriteData2Disk : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
WriteData2Disk();
|
||
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||
|
||
private:
|
||
queue<DataBuffer *> * m_q;
|
||
QString m_QbaseFileName;
|
||
int m_iFrameSizeInByte;
|
||
int m_iNumber_WriteDisk;
|
||
MemoryPool<DataBuffer> * m_pool;
|
||
|
||
rgbImage * m_rgbImage;
|
||
|
||
public slots:
|
||
void write2Disk();
|
||
|
||
signals:
|
||
};
|
||
|
||
class XimeaImager : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
XimeaImager();
|
||
~XimeaImager();
|
||
|
||
void setFramerate(double framerate);
|
||
double getFramerate();
|
||
double setExposureTime(float exposureTime);
|
||
int wrapSetExposureTime(float exposureTime_in_us);
|
||
double getExposureTime();
|
||
double autoExposure();
|
||
void setGain(double gain);
|
||
double getGain();
|
||
int getSampleCount();
|
||
int getBandCount();
|
||
|
||
int getWindowStartBand();
|
||
int getWindowEndBand();
|
||
double geWavelengthAtBand(int x);
|
||
|
||
void stopRecord();
|
||
int getFrameCounter();
|
||
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
|
||
|
||
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
|
||
|
||
int getImagerState() const;
|
||
private:
|
||
//0-61:ximea官方错误代码;99:发生的ximea官方错误代码,没有处理;100:未打开;101:打开;102:设置帧率;103:自动曝光;104:正在采集;
|
||
int m_iImagerState;
|
||
int m_iImagerStateTemp;
|
||
|
||
QThread * m_recordTempThread;
|
||
RecordXimeaTemperature * m_ximeaTemperature;
|
||
|
||
QThread * writeData2DiskThread;
|
||
WriteData2Disk * writeData2Disk;
|
||
queue<DataBuffer *> * q;
|
||
MemoryPool<DataBuffer> * m_pool;
|
||
|
||
QString m_baseFileName;
|
||
QString m_ximeaTemperatureCSVPath;
|
||
|
||
Iris::IrisXimeaImager m_imager;
|
||
unsigned short * m_buffer;
|
||
// MemoryPool<unsigned short> m_pool;
|
||
bool m_bRecordControl;
|
||
int m_iFrameCounter;
|
||
int m_iFrameSizeInByte;
|
||
rgbImage * m_rgbImage;
|
||
void writeHdr();
|
||
|
||
void processXiApiErrorCodes(int xiApiErrorCodes);
|
||
|
||
inline double getSbgTime(double TimeDifferenceBetweensOSAndSbg)
|
||
{
|
||
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;
|
||
}
|
||
|
||
Configfile m_configfile;
|
||
|
||
|
||
|
||
public slots:
|
||
void openImger();
|
||
void closeImger();
|
||
|
||
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
|
||
|
||
signals:
|
||
void recordFinished();
|
||
void ximeaImageStatus(int);
|
||
|
||
void recordXimeaTemperatureSignal(QString);
|
||
void startWriteDiskSignal();
|
||
|
||
void autoExposeMaxValueOfOneFrame(int, double);
|
||
void frameRateSignal(double);
|
||
};
|
||
#endif // XIMEAIMAGER_H
|