Subversion Repositories seema-scanner

Rev

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

Rev 251 Rev 257
Line 105... Line 105...
105
                                   cv::Mat& phase,
105
                                   cv::Mat& phase,
106
                                   cv::Mat& energy) {
106
                                   cv::Mat& energy) {
107
 
107
 
108
    std::vector<cv::Mat> fourier = getDFTComponents(frames);
108
    std::vector<cv::Mat> fourier = getDFTComponents(frames);
109
 
109
 
-
 
110
 
110
    cv::phase(fourier[2], -fourier[3], phase);
111
    cv::phase(fourier[2], -fourier[3], phase);
111
 
112
 
112
    // Signal energy at unit frequency
113
    // Signal energy at unit frequency
113
    cv::magnitude(fourier[2], -fourier[3], amplitude);
114
    cv::magnitude(fourier[2], -fourier[3], amplitude);
114
 
115
 
Line 232... Line 233...
232
 
233
 
233
    #pragma omp parallel sections
234
    #pragma omp parallel sections
234
    {
235
    {
235
        #pragma omp section
236
        #pragma omp section
236
        {
237
        {
237
 
-
 
238
            // Gray-scale and remap/rectify
238
            // Gray-scale and remap/rectify
239
            std::vector<cv::Mat> frames0Rect(N);
239
            std::vector<cv::Mat> frames0Rect(N);
240
 
240
 
241
            for(unsigned int i=0; i<N; i++){
241
            for(unsigned int i=0; i<N; i++){
242
                cv::Mat temp;
242
                cv::Mat temp;
243
                if(frames0[i].depth() == CV_8U)
243
                if(frames0[i].depth() == CV_8U)
244
                    cv::cvtColor(frames0[i], temp, CV_BayerBG2GRAY);
244
                    cv::cvtColor(frames0[i], temp, CV_BayerBG2GRAY);
-
 
245
                else if(frames0[i].channels() == 3)
-
 
246
                    cv::cvtColor(frames0[i], temp, CV_RGB2GRAY);
245
                else
247
                else
246
                    temp = frames0[i];
248
                    temp = frames0[i];
-
 
249
 
247
                cv::remap(temp, frames0Rect[i],
250
                cv::remap(temp, frames0Rect[i],
248
                          stereoRect.map0X, stereoRect.map0Y,
251
                          stereoRect.map0X, stereoRect.map0Y,
249
                          CV_INTER_LINEAR);
252
                          CV_INTER_LINEAR);
250
            }
253
            }
251
 
254
 
-
 
255
            if(frames0[0].depth() == CV_8U) {
-
 
256
                cv::Mat temp;
-
 
257
                cv::cvtColor(frames0[0], temp, CV_BayerBG2RGB);
252
            // If images are HDR (float), we need to convert to uchar
258
                cv::remap(temp, color0, stereoRect.map0X, stereoRect.map0Y,
-
 
259
                          CV_INTER_LINEAR);
-
 
260
            }
-
 
261
            else if(frames0[0].channels() == 1) {
253
            frames0Rect[0].convertTo(color0, CV_32FC3);
262
                frames0Rect[0].convertTo(color0, CV_32FC3);
-
 
263
            }
-
 
264
            else {
-
 
265
                cv::remap(frames0[0], color0, stereoRect.map0X, stereoRect.map0Y,
-
 
266
                          CV_INTER_LINEAR);
-
 
267
            }
-
 
268
 
-
 
269
            cv::Mat tmp;
-
 
270
            color0.convertTo(tmp, CV_8U, 255.0);
-
 
271
            cv::imwrite("color0.jpg", tmp);
254
 
272
 
255
            // Occlusion masks
273
            // Occlusion masks
256
            cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
274
            cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0);
-
 
275
            if(frames0Rect[0].depth() == CV_8U)
257
            occlusion0 = (occlusion0 > 25) & (occlusion0 < 250);
276
                occlusion0 = (occlusion0 > 25) & (occlusion0 < 250);
-
 
277
            else
-
 
278
                occlusion0 = (occlusion0 > 25.0 / 255.0) & (occlusion0 < 250.0 / 255.0);
258
 
279
 
259
            // Decode camera0
280
            // Decode camera0
260
            std::vector<cv::Mat> frames0Primary(frames0Rect.begin()+2,
281
            std::vector<cv::Mat> frames0Primary(frames0Rect.begin()+2,
261
                                                frames0Rect.begin()+2+nStepsPrimary);
282
                                                frames0Rect.begin()+2+nStepsPrimary);
262
            std::vector<cv::Mat> frames0Secondary(frames0Rect.begin()+2+nStepsPrimary,
283
            std::vector<cv::Mat> frames0Secondary(frames0Rect.begin()+2+nStepsPrimary,
Line 275... Line 296...
275
                                          amplitude0Secondary,
296
                                          amplitude0Secondary,
276
                                          up0Secondary,
297
                                          up0Secondary,
277
                                          energy0Secondary);
298
                                          energy0Secondary);
278
 
299
 
279
            unWrapPhaseMap(up0Primary, up0Secondary, up0);
300
            unWrapPhaseMap(up0Primary, up0Secondary, up0);
280
 
-
 
281
            // Threshold on energy at primary frequency
301
            // Threshold on energy at primary frequency
-
 
302
            if(frames0Rect[0].depth() == CV_8U)
282
            occlusion0 = occlusion0 & (amplitude0Primary > 5.0*nStepsPrimary);
303
                occlusion0 = occlusion0 & (amplitude0Primary > 5.0*nStepsPrimary);
-
 
304
            else
-
 
305
                occlusion0 = occlusion0 & (amplitude0Primary * 255.0 > 5.0*nStepsPrimary);
-
 
306
 
283
            // Threshold on energy ratios
307
            // Threshold on energy ratios
284
            occlusion0 = occlusion0 & (amplitude0Primary > 0.25*energy0Primary);
308
            occlusion0 = occlusion0 & (amplitude0Primary > 0.25*energy0Primary);
285
            occlusion0 = occlusion0 & (amplitude0Secondary > 0.25*energy0Secondary);
309
            occlusion0 = occlusion0 & (amplitude0Secondary > 0.25*energy0Secondary);
286
 
310
 
287
            // // Erode occlusion masks
311
            // // Erode occlusion masks
Line 291... Line 315...
291
            cv::Mat edges0;
315
            cv::Mat edges0;
292
            cv::Sobel(up0, edges0, -1, 1, 1, 5);
316
            cv::Sobel(up0, edges0, -1, 1, 1, 5);
293
            occlusion0 = occlusion0 & (abs(edges0) < 10);
317
            occlusion0 = occlusion0 & (abs(edges0) < 10);
294
 
318
 
295
            #ifdef SM_DEBUG
319
            #ifdef SM_DEBUG
-
 
320
                cv::Mat tmp;
-
 
321
                double min, max;
-
 
322
                cv::minMaxLoc(up0Primary, &min, &max);
-
 
323
                up0Primary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
324
                cv::imwrite("up0Primary.jpg", tmp & occlusion0);
-
 
325
                cv::minMaxLoc(up0Secondary, &min, &max);
-
 
326
                up0Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
327
                cv::imwrite("up0Secondary.jpg", tmp & occlusion0);
-
 
328
                cv::minMaxLoc(up0, &min, &max);
-
 
329
                up0.convertTo(tmp, CV_8U, 255.0 / (max - min),- min * 255.0 / (max - min));
-
 
330
                cv::imwrite("up0.jpg", tmp & occlusion0);
-
 
331
                cv::minMaxLoc(amplitude0Primary, &min, &max);
-
 
332
                amplitude0Primary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
333
                cv::imwrite("amplitude0Primary.jpg", tmp & occlusion0);
-
 
334
                cv::minMaxLoc(amplitude0Secondary, &min, &max);
-
 
335
                amplitude0Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
336
                cv::imwrite("amplitude0Secondary.jpg", tmp & occlusion0);
-
 
337
                cv::minMaxLoc(energy0Primary, &min, &max);
-
 
338
                energy0Primary.convertTo(tmp, CV_8U, 255.0 / (max - min),- min * 255.0 / (max - min));
-
 
339
                cv::imwrite("energy0Primary.jpg", tmp & occlusion0);
-
 
340
                cv::minMaxLoc(energy0Secondary, &min, &max);
-
 
341
                energy0Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
342
                cv::imwrite("energy0Secondary.jpg", tmp & occlusion0);
-
 
343
 
296
                cvtools::writeMat(up0Primary, "up0Primary.mat", "up0Primary");
344
                cvtools::writeMat(up0Primary, "up0Primary.mat", "up0Primary");
297
                cvtools::writeMat(up0Secondary, "up0Secondary.mat", "up0Secondary");
345
                cvtools::writeMat(up0Secondary, "up0Secondary.mat", "up0Secondary");
298
                cvtools::writeMat(up0, "up0.mat", "up0");
346
                cvtools::writeMat(up0, "up0.mat", "up0");
299
                cvtools::writeMat(amplitude0Primary,
347
                cvtools::writeMat(amplitude0Primary,
300
                                  "amplitude0Primary.mat", "amplitude0Primary");
348
                                  "amplitude0Primary.mat", "amplitude0Primary");
Line 318... Line 366...
318
 
366
 
319
            for(unsigned int i=0; i<N; i++){
367
            for(unsigned int i=0; i<N; i++){
320
                cv::Mat temp;
368
                cv::Mat temp;
321
                if(frames1[i].depth() == CV_8U)
369
                if(frames1[i].depth() == CV_8U)
322
                    cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
370
                    cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
-
 
371
                else if(frames1[i].channels() == 3)
-
 
372
                    cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
323
                else
373
                else
324
                    temp = frames1[i];
374
                    temp = frames1[i];
325
                cv::remap(temp, frames1Rect[i],
375
                cv::remap(temp, frames1Rect[i],
326
                          stereoRect.map1X, stereoRect.map1Y,
376
                          stereoRect.map1X, stereoRect.map1Y,
327
                          CV_INTER_LINEAR);
377
                          CV_INTER_LINEAR);
328
            }
378
            }
329
 
379
 
-
 
380
            if(frames1[0].depth() == CV_8U) {
-
 
381
                cv::Mat temp;
-
 
382
                cv::cvtColor(frames1[0], temp, CV_BayerBG2RGB);
330
            // If images are HDR (float), we need to convert to uchar
383
                cv::remap(temp, color1, stereoRect.map1X, stereoRect.map1Y,
-
 
384
                          CV_INTER_LINEAR);
-
 
385
            }
-
 
386
            else if(frames1[0].channels() == 1) {
331
            frames1Rect[0].convertTo(color1, CV_32FC3);
387
                frames1Rect[0].convertTo(color1, CV_32FC3);
-
 
388
            }
-
 
389
            else {
-
 
390
                cv::remap(frames1[0], color1, stereoRect.map1X, stereoRect.map1Y,
-
 
391
                          CV_INTER_LINEAR);
-
 
392
            }
332
 
393
 
333
            // Occlusion masks
394
            // Occlusion masks
334
            cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
395
            cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1);
-
 
396
            if(frames1Rect[0].depth() == CV_8U)
335
            occlusion1 = (occlusion1 > 25) & (occlusion1 < 250);
397
                occlusion1 = (occlusion1 > 25) & (occlusion1 < 250);
-
 
398
            else
-
 
399
                occlusion1 = (occlusion1 > 25.0 / 255.0) & (occlusion1 < 250.0 / 255.0);
336
 
400
 
337
            // Decode camera1
401
            // Decode camera1
338
            std::vector<cv::Mat> frames1Primary(frames1Rect.begin()+2,
402
            std::vector<cv::Mat> frames1Primary(frames1Rect.begin()+2,
339
                                                frames1Rect.begin()+2+nStepsPrimary);
403
                                                frames1Rect.begin()+2+nStepsPrimary);
340
            std::vector<cv::Mat> frames1Secondary(frames1Rect.begin()+2+nStepsPrimary,
404
            std::vector<cv::Mat> frames1Secondary(frames1Rect.begin()+2+nStepsPrimary,
Line 355... Line 419...
355
                                          energy1Secondary);
419
                                          energy1Secondary);
356
 
420
 
357
            unWrapPhaseMap(up1Primary, up1Secondary, up1);
421
            unWrapPhaseMap(up1Primary, up1Secondary, up1);
358
 
422
 
359
            // Threshold on energy at primary frequency
423
            // Threshold on energy at primary frequency
-
 
424
            if(frames1Rect[0].depth() == CV_8U)
360
            occlusion1 = occlusion1 & (amplitude1Primary > 5.0*nStepsPrimary);
425
                occlusion1 = occlusion1 & (amplitude1Primary > 5.0*nStepsPrimary);
-
 
426
            else
-
 
427
                occlusion1 = occlusion1 & (amplitude1Primary * 255.0 > 5.0*nStepsPrimary);
-
 
428
 
361
            // Threshold on energy ratios
429
            // Threshold on energy ratios
362
            occlusion1 = occlusion1 & (amplitude1Primary > 0.25*energy1Primary);
430
            occlusion1 = occlusion1 & (amplitude1Primary > 0.25*energy1Primary);
363
            occlusion1 = occlusion1 & (amplitude1Secondary > 0.25*energy1Secondary);
431
            occlusion1 = occlusion1 & (amplitude1Secondary > 0.25*energy1Secondary);
364
 
432
 
365
            // // Erode occlusion masks
433
            // // Erode occlusion masks
Line 370... Line 438...
370
            cv::Mat edges1;
438
            cv::Mat edges1;
371
            cv::Sobel(up1, edges1, -1, 1, 1, 5);
439
            cv::Sobel(up1, edges1, -1, 1, 1, 5);
372
            occlusion1 = occlusion1 & (abs(edges1) < 10);
440
            occlusion1 = occlusion1 & (abs(edges1) < 10);
373
 
441
 
374
            #ifdef SM_DEBUG
442
            #ifdef SM_DEBUG
-
 
443
                cv::Mat tmp;
-
 
444
                double min, max;
-
 
445
                cv::minMaxLoc(up1Primary, &min, &max);
-
 
446
                up1Primary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
447
                cv::imwrite("up1Primary.jpg", tmp & occlusion1);
-
 
448
                cv::minMaxLoc(up1Secondary, &min, &max);
-
 
449
                up1Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
450
                cv::imwrite("up1Secondary.jpg", tmp & occlusion1);
-
 
451
                cv::minMaxLoc(up1, &min, &max);
-
 
452
                up1.convertTo(tmp, CV_8U, 255.0 / (max - min),- min * 255.0 / (max - min));
-
 
453
                cv::imwrite("up1.jpg", tmp & occlusion1);
-
 
454
                cv::minMaxLoc(amplitude1Primary, &min, &max);
-
 
455
                amplitude1Primary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
456
                cv::imwrite("amplitude1Primary.jpg", tmp & occlusion1);
-
 
457
                cv::minMaxLoc(amplitude1Secondary, &min, &max);
-
 
458
                amplitude1Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
459
                cv::imwrite("amplitude1Secondary.jpg", tmp & occlusion1);
-
 
460
                cv::minMaxLoc(energy1Primary, &min, &max);
-
 
461
                energy1Primary.convertTo(tmp, CV_8U, 255.0 / (max - min),- min * 255.0 / (max - min));
-
 
462
                cv::imwrite("energy1Primary.jpg", tmp & occlusion1);
-
 
463
                cv::minMaxLoc(energy1Secondary, &min, &max);
-
 
464
                energy1Secondary.convertTo(tmp, CV_8U, 255.0 / (max - min), -min * 255.0 / (max - min));
-
 
465
                cv::imwrite("energy1Secondary.jpg", tmp & occlusion1);
-
 
466
 
375
                cvtools::writeMat(up1Primary, "up1Primary.mat", "up1Primary");
467
                cvtools::writeMat(up1Primary, "up1Primary.mat", "up1Primary");
376
                cvtools::writeMat(up1Secondary, "up1Secondary.mat", "up1Secondary");
468
                cvtools::writeMat(up1Secondary, "up1Secondary.mat", "up1Secondary");
377
                cvtools::writeMat(up1, "up1.mat", "up1");
469
                cvtools::writeMat(up1, "up1.mat", "up1");
378
                cvtools::writeMat(amplitude1Primary,
470
                cvtools::writeMat(amplitude1Primary,
379
                                  "amplitude1Primary.mat", "amplitude1Primary");
471
                                  "amplitude1Primary.mat", "amplitude1Primary");
Line 412... Line 504...
412
        for(unsigned int i=0; i<nMatches; i++){
504
        for(unsigned int i=0; i<nMatches; i++){
413
 
505
 
414
            cv::Vec3f c0 = color0.at<cv::Vec3f>(int(q0[i][1]), int(q0[i][0]));
506
            cv::Vec3f c0 = color0.at<cv::Vec3f>(int(q0[i][1]), int(q0[i][0]));
415
            cv::Vec3f c1 = color1.at<cv::Vec3f>(int(q1[i][1]), int(q1[i][0]));
507
            cv::Vec3f c1 = color1.at<cv::Vec3f>(int(q1[i][1]), int(q1[i][0]));
416
 
508
 
417
            color[i] = 0.5*c0 + 0.5*c1;
509
            color[i] = (0.5*c0 + 0.5*c1);
418
        }
510
        }
419
    }
511
    }
420
 
512
 
421
    // Triangulate points
513
    // Triangulate points
422
    triangulate(stereoRect, q0, q1, Q);
514
    triangulate(stereoRect, q0, q1, Q);