Files
ximeaAirborneSystem/Header_Files/ximeaimager.h
tangchao0503 a91f5f5b04 1、添加配置文件控制推流参数;
2、解决遥控器解码时帧序混乱的问题(gop_size = 1);
3、完善代码;
2024-01-29 17:21:07 +08:00

255 lines
5.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 <cmath>
#include <vector>
#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 <QUdpSocket>
#include "rgbImage.h"
#define PUSH_FLOW_PORT 666
//#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 XimeaImager;
class RecordXimeaTemperature : public QObject
{
Q_OBJECT
public:
RecordXimeaTemperature(Iris::IrisXimeaImager * imager, XimeaImager * ximeaImager);
void stopRecordTemperature();
private:
Iris::IrisXimeaImager * m_imager;
bool m_bIsRecord;
XimeaImager * m_ximeaImager;
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, 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;
MemoryPool<DataBuffer> * m_pool;
bool isExitWriteData2Disk;
rgbImage * m_rgbImage;
public slots:
void write2Disk();
void exitWriteData2Disk();
signals:
};
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:
};
class XimeaImager : public QObject
{
Q_OBJECT
public:
XimeaImager();
~XimeaImager();
void setFramerate(double framerate);
double getFramerate();
double setExposureTime(float exposureTime_in_us);
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);
static int findClosestIndex(const std::vector<double>& numbers, double target);
void getRgbBandNumber(int &redBandNumber, int &greenBandNumber, int &blueBandNumber);
void stopRecord();
int getFrameCounter();
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
int getImagerState() const;
private:
//0-61ximea官方错误代码99发生的ximea官方错误代码没有处理100未打开101打开102设置帧率103自动曝光104正在采集
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;
QThread * m_pushFlowThread;
PushFlow * m_pushFlow;
int m_iFlowSwitch;
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(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
{
double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
return ximeaTime + timeDifferenceBetweenSbgAndXimea;
}
Configfile m_configfile;
ParameterConfigfile m_parameterConfigfile;
public slots:
void openImger();
void closeImger();
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
signals:
void recordFinished();
void ximeaImageStatus(int);
void recordXimeaTemperatureSignal(QString);
void startWriteDiskSignal();
void startPushFlowSignal();
void autoExposeMaxValueOfOneFrame(int, double);
void frameRateSignal(double);
void binSignal(int, int);
};
#endif // XIMEAIMAGER_H