Line 12... |
Line 12... |
12 |
#include <math.h>
|
12 |
#include <math.h>
|
13 |
|
13 |
|
14 |
#include "cvtools.h"
|
14 |
#include "cvtools.h"
|
15 |
#include "algorithmtools.h"
|
15 |
#include "algorithmtools.h"
|
16 |
|
16 |
|
17 |
#ifndef M_PI
|
- |
|
18 |
#define M_PI 3.14159265358979323846
|
- |
|
19 |
#endif
|
- |
|
20 |
|
- |
|
21 |
static unsigned int nStepsPrimary = 16; // number of shifts/steps in primary
|
17 |
static unsigned int nStepsPrimary = 16; // number of shifts/steps in primary
|
22 |
static unsigned int nStepsSecondary = 8; // number of shifts/steps in secondary
|
18 |
static unsigned int nStepsSecondary = 8; // number of shifts/steps in secondary
|
23 |
static float nPeriodsPrimary = 40; // primary period
|
19 |
static float nPeriodsPrimary = 40; // primary period
|
24 |
|
20 |
|
25 |
AlgorithmPhaseShiftTwoFreq::AlgorithmPhaseShiftTwoFreq(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
|
21 |
AlgorithmPhaseShiftTwoFreq::AlgorithmPhaseShiftTwoFreq(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
|
Line 36... |
Line 32... |
36 |
|
32 |
|
37 |
// all off pattern
|
33 |
// all off pattern
|
38 |
cv::Mat allOff(1, screenCols, CV_8UC3, cv::Scalar::all(0));
|
34 |
cv::Mat allOff(1, screenCols, CV_8UC3, cv::Scalar::all(0));
|
39 |
patterns.push_back(allOff);
|
35 |
patterns.push_back(allOff);
|
40 |
|
36 |
|
41 |
// Precompute encoded patterns
|
- |
|
42 |
const float pi = M_PI;
|
- |
|
43 |
|
- |
|
44 |
// Primary encoding patterns
|
37 |
// Primary encoding patterns
|
45 |
for(unsigned int i=0; i<nStepsPrimary; i++){
|
38 |
for(unsigned int i=0; i<nStepsPrimary; i++){
|
46 |
float phase = 2.0*pi/nStepsPrimary * i;
|
39 |
float phase = 2.0*CV_PI/nStepsPrimary * i;
|
47 |
float pitch = screenCols/nPeriodsPrimary;
|
40 |
float pitch = screenCols/nPeriodsPrimary;
|
48 |
cv::Mat patternI(1,1,CV_8U);
|
41 |
cv::Mat patternI(1,1,CV_8U);
|
49 |
patternI = computePhaseVector(screenCols, phase, pitch);
|
42 |
patternI = computePhaseVector(screenCols, phase, pitch);
|
50 |
patterns.push_back(patternI.t());
|
43 |
patterns.push_back(patternI.t());
|
51 |
}
|
44 |
}
|
52 |
|
45 |
|
53 |
// Secondary encoding patterns
|
46 |
// Secondary encoding patterns
|
54 |
for(unsigned int i=0; i<nStepsSecondary; i++){
|
47 |
for(unsigned int i=0; i<nStepsSecondary; i++){
|
55 |
float phase = 2.0*pi/nStepsSecondary * i;
|
48 |
float phase = 2.0*CV_PI/nStepsSecondary * i;
|
56 |
float pitch = screenCols/nPeriodsSecondary;
|
49 |
float pitch = screenCols/nPeriodsSecondary;
|
57 |
cv::Mat patternI(1,1,CV_8U);
|
50 |
cv::Mat patternI(1,1,CV_8U);
|
58 |
patternI = computePhaseVector(screenCols, phase, pitch);
|
51 |
patternI = computePhaseVector(screenCols, phase, pitch);
|
59 |
patterns.push_back(patternI.t());
|
52 |
patterns.push_back(patternI.t());
|
60 |
}
|
53 |
}
|
Line 66... |
Line 59... |
66 |
return patterns[depth];
|
59 |
return patterns[depth];
|
67 |
}
|
60 |
}
|
68 |
|
61 |
|
69 |
void AlgorithmPhaseShiftTwoFreq::get3DPoints(SMCalibrationParameters calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
|
62 |
void AlgorithmPhaseShiftTwoFreq::get3DPoints(SMCalibrationParameters calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
|
70 |
|
63 |
|
71 |
const float pi = M_PI;
|
- |
|
72 |
|
- |
|
73 |
assert(frames0.size() == N);
|
64 |
assert(frames0.size() == N);
|
74 |
assert(frames1.size() == N);
|
65 |
assert(frames1.size() == N);
|
75 |
|
66 |
|
76 |
int frameRows = frames0[0].rows;
|
67 |
int frameRows = frames0[0].rows;
|
77 |
int frameCols = frames0[0].cols;
|
68 |
int frameCols = frames0[0].cols;
|
Line 115... |
Line 106... |
115 |
std::vector<cv::Mat> F0Secondary = getDFTComponents(frames0Secondary);
|
106 |
std::vector<cv::Mat> F0Secondary = getDFTComponents(frames0Secondary);
|
116 |
cv::Mat up0Secondary;
|
107 |
cv::Mat up0Secondary;
|
117 |
cv::phase(F0Secondary[2], -F0Secondary[3], up0Secondary);
|
108 |
cv::phase(F0Secondary[2], -F0Secondary[3], up0Secondary);
|
118 |
|
109 |
|
119 |
cv::Mat up0Equivalent = up0Secondary - up0Primary;
|
110 |
cv::Mat up0Equivalent = up0Secondary - up0Primary;
|
120 |
up0Equivalent = cvtools::modulo(up0Equivalent, 2.0*pi);
|
111 |
up0Equivalent = cvtools::modulo(up0Equivalent, 2.0*CV_PI);
|
121 |
cv::Mat up0 = unwrapWithCue(up0Primary, up0Equivalent, nPeriodsPrimary);
|
112 |
cv::Mat up0 = unwrapWithCue(up0Primary, up0Equivalent, nPeriodsPrimary);
|
122 |
up0 *= screenCols/(2.0*pi);
|
113 |
up0 *= screenCols/(2.0*CV_PI);
|
123 |
cv::Mat amplitude0;
|
114 |
cv::Mat amplitude0;
|
124 |
cv::magnitude(F0Primary[2], -F0Primary[3], amplitude0);
|
115 |
cv::magnitude(F0Primary[2], -F0Primary[3], amplitude0);
|
125 |
|
116 |
|
126 |
// Collected signal energy at higher frequencies
|
117 |
// Collected signal energy at higher frequencies
|
127 |
cv::Mat energy0Primary(frameRectRows, frameRectCols, CV_32F, cv::Scalar(0.0));
|
118 |
cv::Mat energy0Primary(frameRectRows, frameRectCols, CV_32F, cv::Scalar(0.0));
|
Line 159... |
Line 150... |
159 |
std::vector<cv::Mat> F1Secondary = getDFTComponents(frames1Secondary);
|
150 |
std::vector<cv::Mat> F1Secondary = getDFTComponents(frames1Secondary);
|
160 |
cv::Mat up1Secondary;
|
151 |
cv::Mat up1Secondary;
|
161 |
cv::phase(F1Secondary[2], -F1Secondary[3], up1Secondary);
|
152 |
cv::phase(F1Secondary[2], -F1Secondary[3], up1Secondary);
|
162 |
|
153 |
|
163 |
cv::Mat up1Equivalent = up1Secondary - up1Primary;
|
154 |
cv::Mat up1Equivalent = up1Secondary - up1Primary;
|
164 |
up1Equivalent = cvtools::modulo(up1Equivalent, 2.0*pi);
|
155 |
up1Equivalent = cvtools::modulo(up1Equivalent, 2.0*CV_PI);
|
165 |
cv::Mat up1 = unwrapWithCue(up1Primary, up1Equivalent, nPeriodsPrimary);
|
156 |
cv::Mat up1 = unwrapWithCue(up1Primary, up1Equivalent, nPeriodsPrimary);
|
166 |
up1 *= screenCols/(2.0*pi);
|
157 |
up1 *= screenCols/(2.0*CV_PI);
|
167 |
cv::Mat amplitude1;
|
158 |
cv::Mat amplitude1;
|
168 |
cv::magnitude(F1Primary[2], -F1Primary[3], amplitude1);
|
159 |
cv::magnitude(F1Primary[2], -F1Primary[3], amplitude1);
|
169 |
|
160 |
|
170 |
// Collected signal energy at higher frequencies
|
161 |
// Collected signal energy at higher frequencies
|
171 |
cv::Mat energy1Primary(frameRectRows, frameRectCols, CV_32F, cv::Scalar(0.0));
|
162 |
cv::Mat energy1Primary(frameRectRows, frameRectCols, CV_32F, cv::Scalar(0.0));
|