Subversion Repositories seema-scanner

Rev

Rev 236 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 236 Rev 245
Line 68... Line 68...
68
 
68
 
69
cv::Mat AlgorithmPhaseShiftThreeFreq::getEncodingPattern(unsigned int depth){
69
cv::Mat AlgorithmPhaseShiftThreeFreq::getEncodingPattern(unsigned int depth){
70
    return patterns[depth];
70
    return patterns[depth];
71
}
71
}
72
 
72
 
73
void AlgorithmPhaseShiftThreeFreq::get3DPoints(const 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(const SMCalibrationParameters & calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3f>& color){
74
 
74
 
75
    assert(frames0.size() == N);
75
    assert(frames0.size() == N);
76
    assert(frames1.size() == N);
76
    assert(frames1.size() == N);
77
 
77
 
78
    int frameRows = frames0[0].rows;
78
    int frameRows = frames0[0].rows;
Line 99... Line 99...
99
    // Gray-scale and remap
99
    // Gray-scale and remap
100
    std::vector<cv::Mat> frames0Rect(N);
100
    std::vector<cv::Mat> frames0Rect(N);
101
    std::vector<cv::Mat> frames1Rect(N);
101
    std::vector<cv::Mat> frames1Rect(N);
102
    for(unsigned int i=0; i<N; i++){
102
    for(unsigned int i=0; i<N; i++){
103
        cv::Mat temp;
103
        cv::Mat temp;
104
        cv::cvtColor(frames0[i], temp, CV_BayerBG2GRAY);
104
        cv::cvtColor(frames0[i], temp, CV_RGB2GRAY);
105
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
105
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
106
        cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
106
        cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
107
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
107
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
108
    }
108
    }
109
 
109
 
110
    // Decode camera0
110
    // Decode camera0
111
    std::vector<cv::Mat> frames0First(frames0Rect.begin()+2, frames0Rect.begin()+2+nStepsFirst);
111
    std::vector<cv::Mat> frames0First(frames0Rect.begin()+2, frames0Rect.begin()+2+nStepsFirst);
Line 190... Line 190...
190
 
190
 
191
        cvtools::writeMat(amplitude0, "amplitude0.mat", "amplitude0");
191
        cvtools::writeMat(amplitude0, "amplitude0.mat", "amplitude0");
192
        cvtools::writeMat(amplitude1, "amplitude1.mat", "amplitude1");
192
        cvtools::writeMat(amplitude1, "amplitude1.mat", "amplitude1");
193
    #endif
193
    #endif
194
 
194
 
195
    // color debayer and remap
195
    // color remap
196
    cv::Mat color0, color1;
196
    cv::Mat color0, color1;
197
    cv::cvtColor(frames0[0], color0, CV_BayerBG2RGB);
-
 
198
    cv::remap(color0, color0, map0X, map0Y, CV_INTER_LINEAR);
197
    cv::remap(frames0[0], color0, map0X, map0Y, CV_INTER_LINEAR);
199
 
-
 
200
    cv::cvtColor(frames1[0], color1, CV_BayerBG2RGB);
-
 
201
    cv::remap(color1, color1, map1X, map1Y, CV_INTER_LINEAR);
198
    cv::remap(frames1[0], color1, map1X, map1Y, CV_INTER_LINEAR);
202
 
199
 
203
    #ifdef QT_DEBUG
200
    #ifdef QT_DEBUG
204
        cvtools::writeMat(color0, "color0.mat", "color0");
201
        cvtools::writeMat(color0, "color0.mat", "color0");
205
        cvtools::writeMat(color1, "color1.mat", "color1");
202
        cvtools::writeMat(color1, "color1.mat", "color1");
206
    #endif
203
    #endif
207
 
204
 
208
    // Occlusion masks
205
    // Occlusion masks
209
    cv::Mat occlusion0, occlusion1;
206
    cv::Mat occlusion0, occlusion1;
210
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
207
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
211
    occlusion0 = (occlusion0 > 25) & (occlusion0 < 250);
208
    occlusion0 = (occlusion0 > 0.1) & (occlusion0 < 0.98);
212
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
209
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
213
    occlusion1 = (occlusion1 > 25) & (occlusion1 < 250);
210
    occlusion1 = (occlusion1 > 0.1) & (occlusion1 < 0.98);
214
 
211
 
215
    // Threshold on range
212
    // Threshold on range
216
    occlusion0 = occlusion0 & (up0Range < 0.05);
213
    occlusion0 = occlusion0 & (up0Range < 0.05);
217
    occlusion1 = occlusion1 & (up1Range < 0.05);
214
    occlusion1 = occlusion1 & (up1Range < 0.05);
218
 
215
 
219
//    // Erode occlusion masks
216
//    // Erode occlusion masks
220
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5));
217
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5));
221
//    cv::erode(occlusion0, occlusion0, strel);
218
//    cv::erode(occlusion0, occlusion0, strel);
222
//    cv::erode(occlusion1, occlusion1, strel);
219
//    cv::erode(occlusion1, occlusion1, strel);
223
 
220
 
224
    // Threshold on gradient of phase
221
    // Threshold on vertical gradient of phase
225
    cv::Mat edges0;
222
    cv::Mat edges0;
226
    cv::Sobel(up0, edges0, -1, 1, 1, 5);
223
    cv::Sobel(up0, edges0, -1, 0, 1, 5);
227
    occlusion0 = occlusion0 & (abs(edges0) < 150);
224
    occlusion0 = occlusion0 & (abs(edges0) < 100);
228
    cv::Mat edges1;
225
    cv::Mat edges1;
229
    cv::Sobel(up1, edges1, -1, 1, 1, 5);
226
    cv::Sobel(up1, edges1, -1, 0, 1, 5);
230
    occlusion1 = occlusion1 & (abs(edges1) < 150);
227
    occlusion1 = occlusion1 & (abs(edges1) < 100);
231
 
228
 
232
    #ifdef QT_DEBUG
229
    #ifdef QT_DEBUG
233
        cvtools::writeMat(edges0, "edges0.mat", "edges0");
230
        cvtools::writeMat(edges0, "edges0.mat", "edges0");
234
        cvtools::writeMat(edges1, "edges1.mat", "edges1");
231
        cvtools::writeMat(edges1, "edges1.mat", "edges1");
235
    #endif
232
    #endif
Line 284... Line 281...
284
 
281
 
285
    // Retrieve color information
282
    // Retrieve color information
286
    color.resize(nMatches);
283
    color.resize(nMatches);
287
    for(int i=0; i<nMatches; i++){
284
    for(int i=0; i<nMatches; i++){
288
 
285
 
289
        cv::Vec3b c0 = color0.at<cv::Vec3b>(q0[i][1], q0[i][0]);
286
        cv::Vec3f c0 = color0.at<cv::Vec3f>(q0[i][1], q0[i][0]);
290
        cv::Vec3b c1 = color1.at<cv::Vec3b>(q1[i][1], q1[i][0]);
287
        cv::Vec3f c1 = color1.at<cv::Vec3f>(q1[i][1], q1[i][0]);
291
 
288
 
292
        color[i] = 0.5*c0 + 0.5*c1;
289
        color[i] = 0.5*c0 + 0.5*c1;
293
    }
290
    }
294
 
291
 
295
    // Triangulate by means of disparity projection
292
    // Triangulate by means of disparity projection