Subversion Repositories seema-scanner

Rev

Rev 190 | Rev 207 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 190 Rev 192
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 nStepsFirst = 8; // number of shifts/steps in First
17
static unsigned int nStepsFirst = 8; // number of shifts/steps in First
22
static unsigned int nStepsSecond = 8; // number of shifts/steps in Second
18
static unsigned int nStepsSecond = 8; // number of shifts/steps in Second
23
static unsigned int nStepsThird = 8; // number of shifts/steps in Third
19
static unsigned int nStepsThird = 8; // number of shifts/steps in Third
24
static float nPeriodsFirst = 24; // First period
20
static float nPeriodsFirst = 24; // First period
25
static float nPeriodsSecond = 30; // First period
21
static float nPeriodsSecond = 30; // First period
Line 39... Line 35...
39
    // all off pattern
35
    // all off pattern
40
    cv::Mat allOff(1, screenCols, CV_8UC3, cv::Scalar::all(0));
36
    cv::Mat allOff(1, screenCols, CV_8UC3, cv::Scalar::all(0));
41
    patterns.push_back(allOff);
37
    patterns.push_back(allOff);
42
 
38
 
43
    // Precompute encoded patterns
39
    // Precompute encoded patterns
44
    const float pi = M_PI;
-
 
45
 
40
 
46
    // First encoding patterns
41
    // First encoding patterns
47
    for(unsigned int i=0; i<nStepsFirst; i++){
42
    for(unsigned int i=0; i<nStepsFirst; i++){
48
        float phase = 2.0*pi/nStepsFirst * i;
43
        float phase = 2.0*CV_PI/nStepsFirst * i;
49
        float pitch = screenCols/nPeriodsFirst;
44
        float pitch = screenCols/nPeriodsFirst;
50
        cv::Mat patternI(1,1,CV_8U);
45
        cv::Mat patternI(1,1,CV_8U);
51
        patternI = computePhaseVector(screenCols, phase, pitch);
46
        patternI = computePhaseVector(screenCols, phase, pitch);
52
        patterns.push_back(patternI.t());
47
        patterns.push_back(patternI.t());
53
    }
48
    }
54
 
49
 
55
    // Second encoding patterns
50
    // Second encoding patterns
56
    for(unsigned int i=0; i<nStepsSecond; i++){
51
    for(unsigned int i=0; i<nStepsSecond; i++){
57
        float phase = 2.0*pi/nStepsSecond * i;
52
        float phase = 2.0*CV_PI/nStepsSecond * i;
58
        float pitch = screenCols/nPeriodsSecond;
53
        float pitch = screenCols/nPeriodsSecond;
59
        cv::Mat patternI(1,1,CV_8U);
54
        cv::Mat patternI(1,1,CV_8U);
60
        patternI = computePhaseVector(screenCols, phase, pitch);
55
        patternI = computePhaseVector(screenCols, phase, pitch);
61
        patterns.push_back(patternI.t());
56
        patterns.push_back(patternI.t());
62
    }
57
    }
63
    // Third encoding patterns
58
    // Third encoding patterns
64
    for(unsigned int i=0; i<nStepsThird; i++){
59
    for(unsigned int i=0; i<nStepsThird; i++){
65
        float phase = 2.0*pi/nStepsThird * i;
60
        float phase = 2.0*CV_PI/nStepsThird * i;
66
        float pitch = screenCols/nPeriodsThird;
61
        float pitch = screenCols/nPeriodsThird;
67
        cv::Mat patternI(1,1,CV_8U);
62
        cv::Mat patternI(1,1,CV_8U);
68
        patternI = computePhaseVector(screenCols, phase, pitch);
63
        patternI = computePhaseVector(screenCols, phase, pitch);
69
        patterns.push_back(patternI.t());
64
        patterns.push_back(patternI.t());
70
    }
65
    }
Line 75... Line 70...
75
    return patterns[depth];
70
    return patterns[depth];
76
}
71
}
77
 
72
 
78
void AlgorithmPhaseShiftThreeFreq::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){
73
void AlgorithmPhaseShiftThreeFreq::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){
79
 
74
 
80
    const float pi = M_PI;
-
 
81
 
-
 
82
    assert(frames0.size() == N);
75
    assert(frames0.size() == N);
83
    assert(frames1.size() == N);
76
    assert(frames1.size() == N);
84
 
77
 
85
    int frameRows = frames0[0].rows;
78
    int frameRows = frames0[0].rows;
86
    int frameCols = frames0[0].cols;
79
    int frameCols = frames0[0].cols;
Line 128... Line 121...
128
    std::vector<cv::Mat> F0Third = getDFTComponents(frames0Third);
121
    std::vector<cv::Mat> F0Third = getDFTComponents(frames0Third);
129
    cv::Mat up0Third;
122
    cv::Mat up0Third;
130
    cv::phase(F0Third[2], -F0Third[3], up0Third);
123
    cv::phase(F0Third[2], -F0Third[3], up0Third);
131
 
124
 
132
    cv::Mat up0FS = up0Second - up0First;
125
    cv::Mat up0FS = up0Second - up0First;
133
    up0FS = cvtools::modulo(up0FS, 2.0*pi);
126
    up0FS = cvtools::modulo(up0FS, 2.0*CV_PI);
134
 
127
 
135
    cv::Mat up0ST = up0Third - up0Second;
128
    cv::Mat up0ST = up0Third - up0Second;
136
    up0ST = cvtools::modulo(up0ST, 2.0*pi);
129
    up0ST = cvtools::modulo(up0ST, 2.0*CV_PI);
137
 
130
 
138
    cv::Mat up0FST = up0ST - up0FS;
131
    cv::Mat up0FST = up0ST - up0FS;
139
    up0FST = cvtools::modulo(up0FST, 2.0*pi);
132
    up0FST = cvtools::modulo(up0FST, 2.0*CV_PI);
140
 
133
 
141
    cv::Mat up0F = unwrapWithCue(up0First, up0FST, nPeriodsFirst);
134
    cv::Mat up0F = unwrapWithCue(up0First, up0FST, nPeriodsFirst);
142
    cv::Mat up0S = unwrapWithCue(up0Second, up0FST, nPeriodsSecond);
135
    cv::Mat up0S = unwrapWithCue(up0Second, up0FST, nPeriodsSecond);
143
    cv::Mat up0T = unwrapWithCue(up0Third, up0FST, nPeriodsThird);
136
    cv::Mat up0T = unwrapWithCue(up0Third, up0FST, nPeriodsThird);
144
    cv::Mat up0Mean = 1.0/3.0 * (up0F + up0S + up0T);
137
    cv::Mat up0Mean = 1.0/3.0 * (up0F + up0S + up0T);
145
    cv::Mat up0Range = cv::max(up0F, cv::max(up0S, up0T)) - cv::min(up0F, cv::min(up0S, up0T));
138
    cv::Mat up0Range = cv::max(up0F, cv::max(up0S, up0T)) - cv::min(up0F, cv::min(up0S, up0T));
146
    cv::Mat up0 = up0Mean * screenCols/(2.0*pi);
139
    cv::Mat up0 = up0Mean * screenCols/(2.0*CV_PI);
147
 
140
 
148
    cv::Mat amplitude0;
141
    cv::Mat amplitude0;
149
    cv::magnitude(F0First[2], -F0First[3], amplitude0);
142
    cv::magnitude(F0First[2], -F0First[3], amplitude0);
150
 
143
 
151
    // Decode camera1
144
    // Decode camera1
Line 162... Line 155...
162
    std::vector<cv::Mat> F1Third = getDFTComponents(frames1Third);
155
    std::vector<cv::Mat> F1Third = getDFTComponents(frames1Third);
163
    cv::Mat up1Third;
156
    cv::Mat up1Third;
164
    cv::phase(F1Third[2], -F1Third[3], up1Third);
157
    cv::phase(F1Third[2], -F1Third[3], up1Third);
165
 
158
 
166
    cv::Mat up1FS = up1Second - up1First;
159
    cv::Mat up1FS = up1Second - up1First;
167
    up1FS = cvtools::modulo(up1FS, 2.0*pi);
160
    up1FS = cvtools::modulo(up1FS, 2.0*CV_PI);
168
 
161
 
169
    cv::Mat up1ST = up1Third - up1Second;
162
    cv::Mat up1ST = up1Third - up1Second;
170
    up1ST = cvtools::modulo(up1ST, 2.0*pi);
163
    up1ST = cvtools::modulo(up1ST, 2.0*CV_PI);
171
 
164
 
172
    cv::Mat up1FST = up1ST - up1FS;
165
    cv::Mat up1FST = up1ST - up1FS;
173
    up1FST = cvtools::modulo(up1FST, 2.0*pi);
166
    up1FST = cvtools::modulo(up1FST, 2.0*CV_PI);
174
 
167
 
175
    cv::Mat up1F = unwrapWithCue(up1First, up1FST, nPeriodsFirst);
168
    cv::Mat up1F = unwrapWithCue(up1First, up1FST, nPeriodsFirst);
176
    cv::Mat up1S = unwrapWithCue(up1Second, up1FST, nPeriodsSecond);
169
    cv::Mat up1S = unwrapWithCue(up1Second, up1FST, nPeriodsSecond);
177
    cv::Mat up1T = unwrapWithCue(up1Third, up1FST, nPeriodsThird);
170
    cv::Mat up1T = unwrapWithCue(up1Third, up1FST, nPeriodsThird);
178
    cv::Mat up1Mean = 1.0/3.0 * (up1F + up1S + up1T);
171
    cv::Mat up1Mean = 1.0/3.0 * (up1F + up1S + up1T);
179
    cv::Mat up1Range = cv::max(up1F, cv::max(up1S, up1T)) - cv::min(up1F, cv::min(up1S, up1T));
172
    cv::Mat up1Range = cv::max(up1F, cv::max(up1S, up1T)) - cv::min(up1F, cv::min(up1S, up1T));
180
    cv::Mat up1 = up1Mean * screenCols/(2.0*pi);
173
    cv::Mat up1 = up1Mean * screenCols/(2.0*CV_PI);
181
 
174
 
182
    cv::Mat amplitude1;
175
    cv::Mat amplitude1;
183
    cv::magnitude(F1First[2], -F1First[3], amplitude1);
176
    cv::magnitude(F1First[2], -F1First[3], amplitude1);
184
 
177
 
185
    #ifdef QT_DEBUG
178
    #ifdef QT_DEBUG