Subversion Repositories seema-scanner

Rev

Rev 39 | Rev 42 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 jakw 1
#include "AlgorithmPhaseShift.h"
4 jakw 2
#include <math.h>
3
 
4
#include "cvtools.h"
5
 
6
#ifndef M_PI
7
    #define M_PI 3.14159265358979323846
8
#endif
9
 
10
static unsigned int nPhases = 8;
11
 
41 jakw 12
// Algorithm
4 jakw 13
static cv::Mat computePhaseVector(unsigned int length, float phase, float pitch){
14
 
15
    cv::Mat phaseVector(length, 1, CV_8UC3);
16
    //phaseVector.setTo(0);
17
 
18
    const float pi = M_PI;
19
 
20
    // Loop through vector
21
    for(int i=0; i<phaseVector.rows; i++){
22
        // Amplitude of channels
23
        float amp = 0.5*(1+cos(2*pi*i/pitch + phase));
24
        phaseVector.at<cv::Vec3b>(i, 0) = cv::Vec3b(255.0*amp,255.0*amp,255.0*amp);
25
    }
26
 
27
    return phaseVector;
28
}
29
 
41 jakw 30
AlgorithmPhaseShift::AlgorithmPhaseShift(unsigned int _screenCols, unsigned int _screenRows, CodingDir _dir) : Algorithm(_screenCols, _screenRows, _dir){
4 jakw 31
 
32
    // Set N
41 jakw 33
    if(dir == CodingDirBoth)
4 jakw 34
        this->N = 12;
35
    else
36
        this->N = 6;
37
 
38
    // Precompute encoded patterns
39
    const float pi = M_PI;
40
 
41 jakw 41
    if(dir & CodingDirHorizontal){
4 jakw 42
        // Horizontally encoding patterns
43
        for(unsigned int i=0; i<3; i++){
44
            float phase = 2.0*pi/3.0 * (1.0 - (float)i);
45
            float pitch = (float)screenCols/(float)nPhases;
46
            cv::Mat patternI(1,1,CV_8U);
47
            patternI = computePhaseVector(screenCols, phase, pitch);
48
            patternI = patternI.t();
49
            patterns.push_back(patternI);
50
        }
51
 
52
        // Phase cue patterns
53
        for(unsigned int i=0; i<3; i++){
54
            float phase = 2.0*pi/3.0 * (1.0 - (float)i);
55
            float pitch = screenCols;
56
            cv::Mat patternI;
57
            patternI = computePhaseVector(screenCols, phase, pitch);
58
            patternI = patternI.t();
59
            patterns.push_back(patternI);
60
        }
61
    }
41 jakw 62
    if(dir & CodingDirVertical){
4 jakw 63
        // Precompute vertically encoding patterns
64
        for(unsigned int i=0; i<3; i++){
65
            float phase = 2.0*pi/3.0 * (1.0 - (float)i);
66
            float pitch = (float)screenRows/(float)nPhases;
67
            cv::Mat patternI;
68
            patternI = computePhaseVector(screenRows, phase, pitch);
69
            patterns.push_back(patternI);
70
        }
71
 
72
        // Precompute vertically phase cue patterns
73
        for(unsigned int i=0; i<3; i++){
74
            float phase = 2.0*pi/3.0 * (1.0 - (float)i);
75
            float pitch = screenRows;
76
            cv::Mat patternI;
77
            patternI = computePhaseVector(screenRows, phase, pitch);
78
            patterns.push_back(patternI);
79
        }
80
    }
81
}
82
 
41 jakw 83
cv::Mat AlgorithmPhaseShift::getEncodingPattern(unsigned int depth){
4 jakw 84
    return patterns[depth];
85
}
86
 
87
 
88
static cv::Mat absolutePhase(cv::Mat _I1, cv::Mat _I2, cv::Mat _I3){
89
 
90
    const float pi = M_PI;
91
 
92
    // Mat_ wrapper for easier indexing
93
    cv::Mat_<float> I1(_I1);
94
    cv::Mat_<float> I2(_I2);
95
    cv::Mat_<float> I3(_I3);
96
 
97
    cv::Mat absPhase(I1.size(), CV_32F);
98
 
99
    for(int i = 0; i < absPhase.rows; i++){
100
        for(int j = 0; j < absPhase.cols; j++){
101
            float phase = atan2(sqrt(3.0) * (I1(i,j)-I3(i,j)), I1(i,j) + I3(i,j) - 2.0*I2(i,j)) + pi;
102
            absPhase.at<float>(i,j) = phase;
103
        }
104
    }
105
 
106
    //absPhase.addref();
107
    return absPhase;
108
}
109
 
41 jakw 110
void AlgorithmPhaseShift::getCorrespondences(SMCalibrationParameters calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point2f>& q0, std::vector<cv::Point2f>& q1, std::vector<cv::Point3f>& color){
4 jakw 111
 
112
}