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 193... Line 193...
193
    std::vector<cv::Mat> upm(M);
193
    std::vector<cv::Mat> upm(M);
194
    for(int m=0; m<M; m++){
194
    for(int m=0; m<M; m++){
195
        upm[m] = unwrapWithCue(phim[m], upCue, fm[m]/Fm[M-1]);
195
        upm[m] = unwrapWithCue(phim[m], upCue, fm[m]/Fm[M-1]);
196
    }
196
    }
197
 
197
 
198
    #if 1
198
    #if 0
199
        for(int m=0; m<M; m++)
199
        for(int m=0; m<M; m++)
200
            cvtools::writeMat(upm[m], QString("upm_%1.mat").arg(m).toStdString().c_str());
200
            cvtools::writeMat(upm[m], QString("upm_%1.mat").arg(m).toStdString().c_str());
201
    #endif
201
    #endif
202
 
202
 
203
    // Determine range of phases (for outlier detection)
203
    // Determine range of phases (for outlier detection)
Line 206... Line 206...
206
    for(int m=1; m<M; m++){
206
    for(int m=1; m<M; m++){
207
        upMin = cv::min(upm[m], upMin);
207
        upMin = cv::min(upm[m], upMin);
208
        upMax = cv::max(upm[m], upMax);
208
        upMax = cv::max(upm[m], upMax);
209
    }
209
    }
210
 
210
 
211
    #if 1
211
    #if 0
212
        cvtools::writeMat(upMin, "upMin.mat");
212
        cvtools::writeMat(upMin, "upMin.mat");
213
        cvtools::writeMat(upMax, "upMax.mat");
213
        cvtools::writeMat(upMax, "upMax.mat");
214
    #endif
214
    #endif
215
 
215
 
216
    upRange = upMax-upMin;
216
    upRange = upMax-upMin;
Line 220... Line 220...
220
    for(int m=1; m<M; m++)
220
    for(int m=1; m<M; m++)
221
        up += upm[m];
221
        up += upm[m];
222
    up /= M;
222
    up /= M;
223
}
223
}
224
 
224
 
225
void AlgorithmPhaseShiftEmbedded::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){
225
void AlgorithmPhaseShiftEmbedded::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){
226
 
226
 
227
    assert(frames0.size() == N);
227
    assert(frames0.size() == N);
228
    assert(frames1.size() == N);
228
    assert(frames1.size() == N);
229
 
229
 
230
    int frameRows = frames0[0].rows;
230
    int frameRows = frames0[0].rows;
Line 250... Line 250...
250
    // Gray-scale and remap
250
    // Gray-scale and remap
251
    std::vector<cv::Mat> frames0Rect(N);
251
    std::vector<cv::Mat> frames0Rect(N);
252
    std::vector<cv::Mat> frames1Rect(N);
252
    std::vector<cv::Mat> frames1Rect(N);
253
    for(unsigned int i=0; i<N; i++){
253
    for(unsigned int i=0; i<N; i++){
254
        cv::Mat temp;
254
        cv::Mat temp;
255
        cv::cvtColor(frames0[i], temp, CV_BayerBG2GRAY);
255
        cv::cvtColor(frames0[i], temp, CV_RGB2GRAY);
256
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
256
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
257
        cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
257
        cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
258
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
258
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
259
    }
259
    }
260
 
260
 
261
    // Decode camera 0
261
    // Decode camera 0
262
    std::vector<cv::Mat> frames0Patterns(frames0Rect.begin()+2, frames0Rect.end());
262
    std::vector<cv::Mat> frames0Patterns(frames0Rect.begin()+2, frames0Rect.end());
Line 281... Line 281...
281
        cvtools::writeMat(up1, "up1.mat", "up1");
281
        cvtools::writeMat(up1, "up1.mat", "up1");
282
    #endif
282
    #endif
283
 
283
 
284
    // Color debayer and remap
284
    // Color debayer and remap
285
    cv::Mat color0, color1;
285
    cv::Mat color0, color1;
286
    cv::cvtColor(frames0[0], color0, CV_BayerBG2RGB);
-
 
287
    cv::remap(color0, color0, map0X, map0Y, CV_INTER_LINEAR);
286
    cv::remap(frames0[0], color0, map0X, map0Y, CV_INTER_LINEAR);
288
 
-
 
289
    cv::cvtColor(frames1[0], color1, CV_BayerBG2RGB);
-
 
290
    cv::remap(color1, color1, map1X, map1Y, CV_INTER_LINEAR);
287
    cv::remap(frames1[0], color1, map1X, map1Y, CV_INTER_LINEAR);
291
 
288
 
292
    #ifdef QT_DEBUG
289
    #ifdef QT_DEBUG
293
        cvtools::writeMat(color0, "color0.mat", "color0");
290
        cvtools::writeMat(color0, "color0.mat", "color0");
294
        cvtools::writeMat(color1, "color1.mat", "color1");
291
        cvtools::writeMat(color1, "color1.mat", "color1");
295
    #endif
292
    #endif
296
 
293
 
297
    // Occlusion masks
294
    // Occlusion masks
298
    cv::Mat occlusion0, occlusion1;
295
    cv::Mat occlusion0, occlusion1;
299
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
296
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
300
    occlusion0 = (occlusion0 > 25) & (occlusion0 < 250);
297
    occlusion0 = (occlusion0 > 0.1) & (occlusion0 < 0.98);
301
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
298
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
302
    occlusion1 = (occlusion1 > 25) & (occlusion1 < 250);
299
    occlusion1 = (occlusion1 > 0.1) & (occlusion1 < 0.98);
303
 
300
 
304
//    // Threshold on energy at primary frequency
301
//    // Threshold on energy at primary frequency
305
//    occlusion0 = occlusion0 & (amplitude0 > 5.0*nStepsPrimary);
302
//    occlusion0 = occlusion0 & (amplitude0 > 5.0*nStepsPrimary);
306
//    occlusion1 = occlusion1 & (amplitude1 > 5.0*nStepsPrimary);
303
//    occlusion1 = occlusion1 & (amplitude1 > 5.0*nStepsPrimary);
307
 
304
 
308
//    // Erode occlusion masks
305
//    // Erode occlusion masks
309
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5));
306
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5));
310
//    cv::erode(occlusion0, occlusion0, strel);
307
//    cv::erode(occlusion0, occlusion0, strel);
311
//    cv::erode(occlusion1, occlusion1, strel);
308
//    cv::erode(occlusion1, occlusion1, strel);
312
 
309
 
313
    // Threshold on gradient of phase
310
//    // Threshold on gradient of phase
314
    cv::Mat edges0;
311
//    cv::Mat edges0;
315
    cv::Sobel(up0, edges0, -1, 1, 1, 5);
312
//    cv::Sobel(up0, edges0, -1, 1, 1, 5);
316
    occlusion0 = occlusion0 & (abs(edges0) < 150);
313
//    occlusion0 = occlusion0 & (abs(edges0) < 150);
317
 
314
 
318
    cv::Mat edges1;
315
//    cv::Mat edges1;
319
    cv::Sobel(up1, edges1, -1, 1, 1, 5);
316
//    cv::Sobel(up1, edges1, -1, 1, 1, 5);
320
    occlusion1 = occlusion1 & (abs(edges1) < 150);
317
//    occlusion1 = occlusion1 & (abs(edges1) < 150);
321
 
318
 
322
    #ifdef QT_DEBUG
319
    #ifdef QT_DEBUG
323
        cvtools::writeMat(occlusion0, "occlusion0.mat", "occlusion0");
320
        cvtools::writeMat(occlusion0, "occlusion0.mat", "occlusion0");
324
        cvtools::writeMat(occlusion1, "occlusion1.mat", "occlusion1");
321
        cvtools::writeMat(occlusion1, "occlusion1.mat", "occlusion1");
325
    #endif
322
    #endif
Line 368... Line 365...
368
 
365
 
369
    // Retrieve color information
366
    // Retrieve color information
370
    color.resize(nMatches);
367
    color.resize(nMatches);
371
    for(int i=0; i<nMatches; i++){
368
    for(int i=0; i<nMatches; i++){
372
 
369
 
373
        cv::Vec3b c0 = color0.at<cv::Vec3b>(q0[i][1], q0[i][0]);
370
        cv::Vec3f c0 = color0.at<cv::Vec3f>(q0[i][1], q0[i][0]);
374
        cv::Vec3b c1 = color1.at<cv::Vec3b>(q1[i][1], q1[i][0]);
371
        cv::Vec3f c1 = color1.at<cv::Vec3f>(q1[i][1], q1[i][0]);
375
 
372
 
376
        color[i] = 0.5*c0 + 0.5*c1;
373
        color[i] = 0.5*c0 + 0.5*c1;
377
    }
374
    }
378
 
375
 
379
    // Triangulate by means of disparity projection
376
    // Triangulate by means of disparity projection