-
Notifications
You must be signed in to change notification settings - Fork 5
/
spectrometer.h
155 lines (121 loc) · 3.58 KB
/
spectrometer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef SPECTROMETER_H
#define SPECTROMETER_H
#include <QObject>
#include <QRect>
#include <QTimer>
#include <QImage>
#include <QVector>
#include <QPainter>
#include "jcampdx.h"
#include <opencv2/opencv.hpp>
#include <gsl/gsl_roots.h>
typedef struct{
int pixelNum;
double wavelength;
} CalibrationPoint;
class Spectrometer : public QObject
{
Q_OBJECT
public:
explicit Spectrometer(int videoSrc=1);
Tjcampdx getLastSpectrum();
Tjcampdx getBlackBodySpec(double max,double T);
void resetCalibration();
void setCalibration(QVector<CalibrationPoint> cal) {
calibration = cal;
calibrate();
}
bool isWlCalib(){
return isXCalibrated;
}
double getFocal() {return focal;}
double getSin() {return sin_angle_i;}
double getPas() {return pas;}
void addCalibrationPoint(CalibrationPoint);
bool isOk() {return ok;}
private slots:
void captureFrame();
public slots:
void setSpectrumRect(QRect rect);
QRect getSpectrumRect(){return spectrumRect;}
/*
void setReferenceSpec(Tjcampdx spec);
void unsetReference();
void setDarkSpec(Tjcampdx spec);
void resetDark(){useDark = false;}
*/
void setSaturation(double sat);
void setGain(double gain);
/*
void calibrateBB(Tjcampdx spectra, double T, double max);
void resetYCalibration(){
isYCalibrated = false;
}
*/
void setFrameRate(int frameRate);
double getFrameRate(){
if(timerCapture.interval()>0)
return 1000/timerCapture.interval();
else
return 15;
}
void setIntegNum(int num){
iFrame = 0;
nFramesInteg = num;
}
void startMeasure(int integNum=1);
void setParameters(double f,double s,double d){
focal = f;
sin_angle_i = s;
pas = d;
isXCalibrated = true;
}
signals:
void newSpectrum(Tjcampdx spectrum);
void measureFinished(Tjcampdx spectrum);
void newSpectrum_rgb(Tjcampdx spectrum_r,Tjcampdx spectrum_g,Tjcampdx spectrum_b);
void newFrame(QImage* frame);
void saturation();
void measureProgressed(int progress);
private:
QRect spectrumRect;
QTimer timerCapture;
cv::VideoCapture cap;
QImage lastFrame;
//Frame integration
int nFramesInteg; // frames to integrate for one spectrum
int iFrame; // index of current frame
int nMeasure;
int iMeasure;
// Calibration
// parametres pour le calcul de f
struct calcFParams {double l1; double l2; double x1; double x2;double a;};
static double calcFFunc(double f,void* params);
void calibrate();
QVector<CalibrationPoint> calibration;
double focal; // Distance focale image de la lentille
double sin_angle_i; // Angle d'incidence sur le réseau
double pas; // Pas du réseau
double imageWidth=640;
bool measuring;
//bool useReference;
//bool useDark;
bool isXCalibrated;
//bool isYCalibrated;
bool ok;
//Tjcampdx referenceSpec;
//Tjcampdx darkSpec;
//Tjcampdx calibSpectrum;
QVector<double> pixDataMeasure;
QVector<double> pixData,pixDataf;
QVector<double> pixDataRed,pixDataRedf;
QVector<double> pixDataGreen,pixDataGreenf;
QVector<double> pixDataBlue,pixDataBluef;
QVector<double> pixNum,pixNumf;
QVector<double> pixToWavelength(QVector<double> pix);
double pixNumToWaveLength(double pixnum);
void getSpectrumFromImage(QImage* image);
double blackBodyIntens(double lambda, double T);
double blackBodyIntensNorm(double lambda, double T);
};
#endif // SPECTROMETER_H