Subversion Repositories seema-scanner

Rev

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

Rev 27 Rev 36
Line 61... Line 61...
61
        res *= num;
61
        res *= num;
62
 
62
 
63
    return res;
63
    return res;
64
}
64
}
65
 
65
 
66
// Encoder
66
// Algorithm
67
EncoderGrayCode::EncoderGrayCode(unsigned int _screenCols, unsigned int _screenRows, CodecDir _dir) : Encoder(_screenCols, _screenRows, _dir){
67
AlgorithmGrayCode::AlgorithmGrayCode(unsigned int _screenCols, unsigned int _screenRows, CodecDir _dir) : Algorithm(_screenCols, _screenRows, _dir){
68
 
68
 
69
    // Number of horizontal encoding patterns
69
    // Number of horizontal encoding patterns
70
    Nhorz = 10;
70
    Nhorz = ceilf(log2f((float)screenCols));;
71
 
71
 
72
    // Number of vertical encoding patterns
72
    // Number of vertical encoding patterns
73
    Nvert = 8;
73
    Nvert = ceilf(log2f((float)screenRows));;
74
 
74
 
75
    // Set total pattern number
75
    // Set total pattern number
76
    if(dir & CodecDirHorizontal)
76
    if(dir & CodecDirHorizontal)
77
        this->N += Nhorz;
77
        this->N += Nhorz;
78
 
78
 
Line 110... Line 110...
110
            patterns.push_back(patternP);
110
            patterns.push_back(patternP);
111
        }
111
        }
112
    }
112
    }
113
}
113
}
114
 
114
 
115
cv::Mat EncoderGrayCode::getEncodingPattern(unsigned int depth){
115
cv::Mat AlgorithmGrayCode::getEncodingPattern(unsigned int depth){
116
    return patterns[depth];
116
    return patterns[depth];
117
}
117
}
118
 
118
 
119
// Decoder
119
// Algorithm
120
DecoderGrayCode::DecoderGrayCode(CodecDir _dir) : Decoder(_dir){
120
AlgorithmGrayCode::AlgorithmGrayCode(CodecDir _dir, int _screenResX, int _screenResY) : Algorithm(_dir, _screenResX, _screenResY){
121
 
121
 
122
    // Number of horizontal encoding patterns
122
    // Number of horizontal encoding patterns
123
    Nhorz = 10;
123
    Nhorz = ceilf(log2f((float)screenCols));;
124
 
124
 
125
    // Number of vertical encoding patterns
125
    // Number of vertical encoding patterns
126
    Nvert = 8;
126
    Nvert = ceilf(log2f((float)screenRows));;
127
 
-
 
128
}
127
}
129
 
128
 
130
void DecoderGrayCode::decodeFrames(const std::vector<cv::Mat> frames, cv::Mat &up, cv::Mat &vp, cv::Mat &mask, cv::Mat &shading){
129
void AlgorithmGrayCode::getCorrespondences(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){
131
 
-
 
132
    // Get shading (max) image
-
 
133
    shading = cv::Scalar(0);
-
 
134
    for(unsigned int f=0; f<frames.size(); f++){
-
 
135
        shading = cv::max(shading, frames[f]);
-
 
136
    }
-
 
137
 
130
 
138
    // Get min image
-
 
139
    cv::Mat minImage(shading.size(), CV_8U, cv::Scalar(255));
-
 
140
    for(unsigned int f=0; f<frames.size(); f++){
-
 
141
        minImage = cv::min(minImage, frames[f]);
-
 
142
    }
-
 
143
 
131
 
144
    // Threshold shading image for mask
-
 
145
    mask = (shading/minImage) > 2;
-
 
146
 
132
 
147
    // Binarize frames. TODO: subpixel interpolation.
-
 
148
    vector<cv::Mat> framesBinary(frames.size());
-
 
149
    for(unsigned int i=0; i<frames.size(); i++){
-
 
150
        // Foreground pixels 1, background 0
-
 
151
        //cv::threshold(frames[i], framesBinary[i], 80, 1, cv::THRESH_BINARY);
-
 
152
        framesBinary[i].create(frames[0].size(), CV_8U);
-
 
153
        framesBinary[i] = cv::abs(shading-frames[i]) < cv::abs(frames[i]-minImage);
-
 
154
        cv::threshold(framesBinary[i], framesBinary[i], 1, 1, cv::THRESH_BINARY);
-
 
155
    }
-
 
156
 
-
 
157
    if(dir & CodecDirHorizontal){
-
 
158
        vector<cv::Mat> framesHorz(framesBinary.begin(), framesBinary.begin()+Nhorz);
-
 
159
 
133
 
160
        // Construct up image.
-
 
161
        for(int i = 0; i < up.rows; i++){
-
 
162
            for(int j = 0; j < up.cols; j++){
-
 
163
                unsigned int enc = 0;
-
 
164
                for(unsigned int f=0; f<framesHorz.size(); f++){
-
 
165
                    // Gray decimal
-
 
166
                    enc += powi(2, Nhorz-f-1)*framesHorz[f].at<unsigned char>(i,j);
-
 
167
                }
-
 
168
                // Standard decimal
-
 
169
                enc = grayToBinary(enc, Nhorz);
-
 
170
                up.at<float>(i,j) = enc;
-
 
171
            }
-
 
172
        }
-
 
173
    }
-
 
174
    if(dir & CodecDirVertical){
-
 
175
        vector<cv::Mat> framesVert(framesBinary.end()-Nvert, framesBinary.end());
-
 
176
 
134
 
177
        // Construct vp image.
-
 
178
        for(int i = 0; i < vp.rows; i++){
-
 
179
            for(int j = 0; j < vp.cols; j++){
-
 
180
                unsigned int enc = 0;
-
 
181
                for(unsigned int f=0; f<framesVert.size(); f++){
-
 
182
                    // Gray decimal
-
 
183
                    enc += powi(2, Nvert-f-1)*framesVert[f].at<unsigned char>(i,j);
-
 
184
                }
-
 
185
                // Standard decimal
-
 
186
                enc = grayToBinary(enc, Nvert);
-
 
187
                vp.at<float>(i,j) = enc;
-
 
188
            }
-
 
189
        }
-
 
190
    }
-
 
191
}
135
}