2022-06-13 12:01:30 +08:00
|
|
|
|
#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>
|
2023-06-21 16:43:33 +08:00
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/mman.h>
|
2024-01-29 17:21:07 +08:00
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <vector>
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2022-08-15 17:36:19 +08:00
|
|
|
|
#include <QDateTime>
|
2022-06-13 12:01:30 +08:00
|
|
|
|
#include <qthread.h>
|
2022-10-09 23:00:15 +08:00
|
|
|
|
#include <QDir>
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
2022-08-01 19:10:25 +08:00
|
|
|
|
#include "configfile.h"
|
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
#include "irisximeaimager.h"
|
|
|
|
|
#include "math.h"
|
|
|
|
|
#include "utility_tc.h"
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
#include "MemoryPool.h"
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <QMutex>
|
2024-01-23 09:35:01 +08:00
|
|
|
|
#include <QUdpSocket>
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
2023-03-19 16:44:12 +08:00
|
|
|
|
#include "rgbImage.h"
|
|
|
|
|
|
2024-01-23 09:35:01 +08:00
|
|
|
|
#define PUSH_FLOW_PORT 666
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
//#ifdef WIN32
|
|
|
|
|
//#include <xiApi.h> // Windows
|
|
|
|
|
//#else
|
|
|
|
|
//#include <m3api/xiApi.h> // Linux, OSX
|
|
|
|
|
//#endif
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
//struct DataBuffer
|
|
|
|
|
//{
|
|
|
|
|
// unsigned short data[409200/2];
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
class DataBuffer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DataBuffer();
|
|
|
|
|
~DataBuffer();
|
|
|
|
|
|
2023-06-21 16:43:33 +08:00
|
|
|
|
unsigned short data[41040000];//1368*300*100=41040000,为了兼容所有设置spectral bin和spatial bin
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-13 17:08:17 +08:00
|
|
|
|
class XimeaImager;
|
2022-08-15 17:36:19 +08:00
|
|
|
|
class RecordXimeaTemperature : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2023-09-13 17:08:17 +08:00
|
|
|
|
RecordXimeaTemperature(Iris::IrisXimeaImager * imager, XimeaImager * ximeaImager);
|
2022-08-15 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
void stopRecordTemperature();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Iris::IrisXimeaImager * m_imager;
|
|
|
|
|
|
|
|
|
|
bool m_bIsRecord;
|
2023-09-13 17:08:17 +08:00
|
|
|
|
XimeaImager * m_ximeaImager;
|
2022-08-15 17:36:19 +08:00
|
|
|
|
public slots:
|
|
|
|
|
void recordTemperature(QString filePath);
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
//queue<DataBuffer *> q;
|
|
|
|
|
//static QMutex r_qtx{ QMutex::Recursive };
|
|
|
|
|
static std::mutex r_qtx;
|
|
|
|
|
|
|
|
|
|
class WriteData2Disk : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
WriteData2Disk();
|
2023-06-30 15:21:23 +08:00
|
|
|
|
void setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
queue<DataBuffer *> * m_q;
|
2023-06-30 15:21:23 +08:00
|
|
|
|
queue<int> * m_qFrameCounter;
|
2022-12-24 16:59:41 +08:00
|
|
|
|
QString m_QbaseFileName;
|
|
|
|
|
int m_iFrameSizeInByte;
|
2023-06-21 16:43:33 +08:00
|
|
|
|
int m_iNumber_WriteDisk;
|
2022-12-24 16:59:41 +08:00
|
|
|
|
MemoryPool<DataBuffer> * m_pool;
|
2023-06-25 21:20:45 +08:00
|
|
|
|
bool isExitWriteData2Disk;
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
2023-03-19 16:44:12 +08:00
|
|
|
|
rgbImage * m_rgbImage;
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
public slots:
|
|
|
|
|
void write2Disk();
|
2023-06-25 21:20:45 +08:00
|
|
|
|
void exitWriteData2Disk();
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-29 17:21:07 +08:00
|
|
|
|
class PushFlow : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PushFlow();
|
|
|
|
|
void setParm(rgbImage * img, int width, int height, int framerateVideo);
|
|
|
|
|
void exitPushFlow();
|
|
|
|
|
void setVedioFilePath(QString path);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_QVedioFilePath;
|
|
|
|
|
bool isExitPushFlow;
|
|
|
|
|
|
|
|
|
|
rgbImage * m_rgbImage;
|
|
|
|
|
|
|
|
|
|
int m_iWidth;
|
|
|
|
|
int m_iHeight;
|
|
|
|
|
int m_iFramerateVideo;
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void encodePushFlow();
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
class XimeaImager : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
XimeaImager();
|
2023-03-19 16:44:12 +08:00
|
|
|
|
~XimeaImager();
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
void setFramerate(double framerate);
|
|
|
|
|
double getFramerate();
|
2023-08-29 13:46:40 +08:00
|
|
|
|
double setExposureTime(float exposureTime_in_us);
|
2023-05-24 16:38:10 +08:00
|
|
|
|
int wrapSetExposureTime(float exposureTime_in_us);
|
2022-06-13 12:01:30 +08:00
|
|
|
|
double getExposureTime();
|
|
|
|
|
double autoExposure();
|
|
|
|
|
void setGain(double gain);
|
|
|
|
|
double getGain();
|
|
|
|
|
int getSampleCount();
|
|
|
|
|
int getBandCount();
|
|
|
|
|
|
|
|
|
|
int getWindowStartBand();
|
|
|
|
|
int getWindowEndBand();
|
|
|
|
|
double geWavelengthAtBand(int x);
|
|
|
|
|
|
2024-01-29 17:21:07 +08:00
|
|
|
|
static int findClosestIndex(const std::vector<double>& numbers, double target);
|
|
|
|
|
void getRgbBandNumber(int &redBandNumber, int &greenBandNumber, int &blueBandNumber);
|
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
void stopRecord();
|
|
|
|
|
int getFrameCounter();
|
2023-06-21 16:43:33 +08:00
|
|
|
|
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
|
|
|
|
|
|
|
|
|
|
int getImagerState() const;
|
|
|
|
|
private:
|
2022-06-22 21:45:22 +08:00
|
|
|
|
//0-61:ximea官方错误代码;99:发生的ximea官方错误代码,没有处理;100:未打开;101:打开;102:设置帧率;103:自动曝光;104:正在采集;
|
2022-06-13 12:01:30 +08:00
|
|
|
|
int m_iImagerState;
|
|
|
|
|
int m_iImagerStateTemp;
|
|
|
|
|
|
2023-06-28 11:59:46 +08:00
|
|
|
|
int m_iOffsetyOfSpectralBin1, m_iOffsetyOfSpectralBin2;
|
|
|
|
|
int m_iHeightOfSpectralBin1, m_iHeightOfSpectralBin2;
|
|
|
|
|
|
2022-08-15 17:36:19 +08:00
|
|
|
|
QThread * m_recordTempThread;
|
|
|
|
|
RecordXimeaTemperature * m_ximeaTemperature;
|
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
QThread * writeData2DiskThread;
|
|
|
|
|
WriteData2Disk * writeData2Disk;
|
|
|
|
|
queue<DataBuffer *> * q;
|
2023-06-30 15:21:23 +08:00
|
|
|
|
queue<int> * m_qFrameCounter;
|
2022-12-24 16:59:41 +08:00
|
|
|
|
MemoryPool<DataBuffer> * m_pool;
|
|
|
|
|
|
2024-01-29 17:21:07 +08:00
|
|
|
|
QThread * m_pushFlowThread;
|
|
|
|
|
PushFlow * m_pushFlow;
|
|
|
|
|
int m_iFlowSwitch;
|
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
QString m_baseFileName;
|
2022-08-15 17:36:19 +08:00
|
|
|
|
QString m_ximeaTemperatureCSVPath;
|
2022-06-13 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
Iris::IrisXimeaImager m_imager;
|
|
|
|
|
unsigned short * m_buffer;
|
2022-12-24 16:59:41 +08:00
|
|
|
|
// MemoryPool<unsigned short> m_pool;
|
2022-06-13 12:01:30 +08:00
|
|
|
|
bool m_bRecordControl;
|
|
|
|
|
int m_iFrameCounter;
|
|
|
|
|
int m_iFrameSizeInByte;
|
2023-03-19 16:44:12 +08:00
|
|
|
|
rgbImage * m_rgbImage;
|
2022-06-13 12:01:30 +08:00
|
|
|
|
void writeHdr();
|
|
|
|
|
|
|
|
|
|
void processXiApiErrorCodes(int xiApiErrorCodes);
|
|
|
|
|
|
2023-06-30 15:21:23 +08:00
|
|
|
|
inline double getSbgTime(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
|
2022-06-13 12:01:30 +08:00
|
|
|
|
{
|
2023-06-30 15:21:23 +08:00
|
|
|
|
double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
|
|
|
|
|
return ximeaTime + timeDifferenceBetweenSbgAndXimea;
|
2022-06-13 12:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 19:10:25 +08:00
|
|
|
|
Configfile m_configfile;
|
2023-08-29 13:46:40 +08:00
|
|
|
|
ParameterConfigfile m_parameterConfigfile;
|
2022-08-01 19:10:25 +08:00
|
|
|
|
|
2022-12-24 16:59:41 +08:00
|
|
|
|
|
|
|
|
|
|
2022-06-13 12:01:30 +08:00
|
|
|
|
public slots:
|
|
|
|
|
void openImger();
|
|
|
|
|
void closeImger();
|
|
|
|
|
|
2023-06-30 15:21:23 +08:00
|
|
|
|
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
|
2022-06-13 12:01:30 +08:00
|
|
|
|
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void recordFinished();
|
|
|
|
|
void ximeaImageStatus(int);
|
2022-08-15 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
void recordXimeaTemperatureSignal(QString);
|
2022-12-24 16:59:41 +08:00
|
|
|
|
void startWriteDiskSignal();
|
2024-01-29 17:21:07 +08:00
|
|
|
|
void startPushFlowSignal();
|
2023-05-24 16:38:10 +08:00
|
|
|
|
|
|
|
|
|
void autoExposeMaxValueOfOneFrame(int, double);
|
|
|
|
|
void frameRateSignal(double);
|
2023-06-27 14:01:19 +08:00
|
|
|
|
void binSignal(int, int);
|
2022-06-13 12:01:30 +08:00
|
|
|
|
};
|
|
|
|
|
#endif // XIMEAIMAGER_H
|