Subversion Repositories seema-scanner

Rev

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

Rev 120 Rev 121
Line 246... Line 246...
246
//    cv::imwrite("frames1[0].png", frames1[0]);
246
//    cv::imwrite("frames1[0].png", frames1[0]);
247
//    cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
247
//    cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
248
 
248
 
249
    // color debayer and remap
249
    // color debayer and remap
250
    cv::Mat color0Rect, color1Rect;
250
    cv::Mat color0Rect, color1Rect;
251
    frames0[0].convertTo(color0Rect, CV_8UC1, 1.0/256.0);
251
//    frames0[0].convertTo(color0Rect, CV_8UC1, 1.0/256.0);
252
    cv::cvtColor(color0Rect, color0Rect, CV_BayerBG2RGB);
252
    cv::cvtColor(frames0[0], color0Rect, CV_BayerBG2RGB);
253
    cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
253
    cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
254
 
254
 
255
    frames1[0].convertTo(color1Rect, CV_8UC1, 1.0/256.0);
255
//    frames1[0].convertTo(color1Rect, CV_8UC1, 1.0/256.0);
256
    cv::cvtColor(color1Rect, color1Rect, CV_BayerBG2RGB);
256
    cv::cvtColor(frames1[0], color1Rect, CV_BayerBG2RGB);
257
    cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
257
    cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
258
 
258
 
259
    int frameRectRows = frames0Rect[0].rows;
259
    int frameRectRows = frames0Rect[0].rows;
260
    int frameRectCols = frames0Rect[0].cols;
260
    int frameRectCols = frames0Rect[0].cols;
261
 
261
 
Line 265... Line 265...
265
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
265
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
266
 
266
 
267
    // occlusion masks
267
    // occlusion masks
268
    cv::Mat occlusion0Rect, occlusion1Rect;
268
    cv::Mat occlusion0Rect, occlusion1Rect;
269
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
269
    cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
270
    occlusion0Rect = (occlusion0Rect > 16000) & (occlusion0Rect < 54000);
270
    occlusion0Rect = (occlusion0Rect > 20) & (occlusion0Rect < 250);
271
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
271
    cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
272
    occlusion1Rect = (occlusion1Rect > 16000) & (occlusion1Rect < 54000);
272
    occlusion1Rect = (occlusion1Rect > 20) & (occlusion1Rect < 250);
273
 
273
 
274
    // erode occlusion masks
274
    // erode occlusion masks
275
    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
275
    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
276
    cv::erode(occlusion0Rect, occlusion0Rect, strel);
276
    cv::erode(occlusion0Rect, occlusion0Rect, strel);
277
    cv::erode(occlusion1Rect, occlusion1Rect, strel);
277
    cv::erode(occlusion1Rect, occlusion1Rect, strel);
Line 299... Line 299...
299
    cv::Mat M0 = frames0Rect[0]-frames0Rect[1];
299
    cv::Mat M0 = frames0Rect[0]-frames0Rect[1];
300
//cvtools::writeMat(A0, "A0.mat", "A0");
300
//cvtools::writeMat(A0, "A0.mat", "A0");
301
//cvtools::writeMat(M0, "M0.mat", "M0");
301
//cvtools::writeMat(M0, "M0.mat", "M0");
302
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
302
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
303
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
303
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
304
    cv::divide(65536.0, M0, M0, CV_32F);
304
    cv::divide(256.0, M0, M0, CV_32F);
305
    cv::Mat A1 = frames1Rect[1];
305
    cv::Mat A1 = frames1Rect[1];
306
    cv::Mat M1 = frames1Rect[0]-frames1Rect[1];
306
    cv::Mat M1 = frames1Rect[0]-frames1Rect[1];
307
    cv::divide(65536.0, M1, M1, CV_32F);
307
    cv::divide(256.0, M1, M1, CV_32F);
308
 
308
 
309
    for(int i=2; i<N; i++){
309
    for(int i=2; i<N; i++){
310
        cv::multiply(frames0Rect[i]-A0, M0, frames0Rect[i], 1.0, CV_16UC1);
310
        cv::multiply(frames0Rect[i]-A0, M0, frames0Rect[i], 1.0, CV_8UC1);
311
        cv::multiply(frames1Rect[i]-A1, M1, frames1Rect[i], 1.0, CV_16UC1);
311
        cv::multiply(frames1Rect[i]-A1, M1, frames1Rect[i], 1.0, CV_8UC1);
312
    }
312
    }
313
 
313
 
314
//cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
314
//cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
315
//cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
315
//cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
316
 
316
 
Line 324... Line 324...
324
    // into gray code
324
    // into gray code
325
    for(int i=0; i<Nbits; i++){
325
    for(int i=0; i<Nbits; i++){
326
        cv::Mat temp, bit0, bit1;
326
        cv::Mat temp, bit0, bit1;
327
 
327
 
328
        cv::compare(frames0Rect[i*2+2], frames0Rect[i*2+3], temp, cv::CMP_GT);
328
        cv::compare(frames0Rect[i*2+2], frames0Rect[i*2+3], temp, cv::CMP_GT);
329
        //cvtools::rshift(temp, 8);
-
 
330
        temp.convertTo(bit0, CV_32S, 1.0/255.0);
329
        temp.convertTo(bit0, CV_32S, 1.0/255.0);
331
        cv::add(code0Rect, bit0*twopowi(Nbits-i-1), code0Rect, cv::noArray(), CV_32S);
330
        cv::add(code0Rect, bit0*twopowi(Nbits-i-1), code0Rect, cv::noArray(), CV_32S);
332
 
331
 
333
        cv::compare(frames1Rect[i*2+2], frames1Rect[i*2+3], temp, cv::CMP_GT);
332
        cv::compare(frames1Rect[i*2+2], frames1Rect[i*2+3], temp, cv::CMP_GT);
334
        //cvtools::rshift(temp, 8);
-
 
335
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
333
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
336
        cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::noArray(), CV_32S);
334
        cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::noArray(), CV_32S);
337
    }
335
    }
338
 
336
 
339
cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
337
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
340
cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
338
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
341
 
339
 
342
 
340
 
343
//    // convert to standard binary
341
//    // convert to standard binary
344
//    cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
342
//    cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
345
//    cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
343
//    cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
Line 416... Line 414...
416
 
414
 
417
            // refine for camera 0
415
            // refine for camera 0
418
            float c0 = matchedEdges0[i][0];
416
            float c0 = matchedEdges0[i][0];
419
            float c1 = c0+1;
417
            float c1 = c0+1;
420
 
418
 
421
            float pos0 = frames0Rect[2*level+2].at<unsigned short>(row, c0);
419
            float pos0 = frames0Rect[2*level+2].at<unsigned char>(row, c0);
422
            float pos1 = frames0Rect[2*level+2].at<unsigned short>(row, c1);
420
            float pos1 = frames0Rect[2*level+2].at<unsigned char>(row, c1);
423
            float neg0 = frames0Rect[2*level+3].at<unsigned short>(row, c0);
421
            float neg0 = frames0Rect[2*level+3].at<unsigned char>(row, c0);
424
            float neg1 = frames0Rect[2*level+3].at<unsigned short>(row, c1);
422
            float neg1 = frames0Rect[2*level+3].at<unsigned char>(row, c1);
425
 
423
 
426
            float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
424
            float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
427
            q0Rect.push_back(cv::Point2f(col, row));
425
            q0Rect.push_back(cv::Point2f(col, row));
428
 
426
 
429
            // refine for camera 1
427
            // refine for camera 1
430
            c0 = matchedEdges1[i][0];
428
            c0 = matchedEdges1[i][0];
431
            c1 = c0+1;
429
            c1 = c0+1;
432
 
430
 
433
            pos0 = frames1Rect[2*level+2].at<unsigned short>(row, c0);
431
            pos0 = frames1Rect[2*level+2].at<unsigned char>(row, c0);
434
            pos1 = frames1Rect[2*level+2].at<unsigned short>(row, c1);
432
            pos1 = frames1Rect[2*level+2].at<unsigned char>(row, c1);
435
            neg0 = frames1Rect[2*level+3].at<unsigned short>(row, c0);
433
            neg0 = frames1Rect[2*level+3].at<unsigned char>(row, c0);
436
            neg1 = frames1Rect[2*level+3].at<unsigned short>(row, c1);
434
            neg1 = frames1Rect[2*level+3].at<unsigned char>(row, c1);
437
 
435
 
438
            col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
436
            col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
439
            q1Rect.push_back(cv::Point2f(col, row));
437
            q1Rect.push_back(cv::Point2f(col, row));
440
 
438
 
441
        }
439
        }