Subversion Repositories seema-scanner

Rev

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

Rev 122 Rev 167
Line 38... Line 38...
38
static bool getBit(int decimal, int N){
38
static bool getBit(int decimal, int N){
39
 
39
 
40
    return decimal & 1 << (N-1);
40
    return decimal & 1 << (N-1);
41
}
41
}
42
 
42
 
43
/*
43
///*
44
 * Return the number of bits set in an integer
44
// * Return the number of bits set in an integer
45
 */
45
// */
46
static int countBits(int n) {
46
//static int countBits(int n) {
47
  unsigned int c; // c accumulates the total bits set in v
47
//  unsigned int c; // c accumulates the total bits set in v
48
  for (c = 0; n>0; c++)
48
//  for (c = 0; n>0; c++)
49
    n &= n - 1; // clear the least significant bit set
49
//    n &= n - 1; // clear the least significant bit set
50
  return c;
50
//  return c;
51
}
51
//}
52
 
52
 
53
/*
53
/*
54
 * Return the position of the least significant bit that is set
54
 * Return the position of the least significant bit that is set
55
 */
55
 */
56
static int leastSignificantBitSet(int x){
56
static int leastSignificantBitSet(int x){
Line 260... Line 260...
260
        q[i] = cv::Point2f(x, y);
260
        q[i] = cv::Point2f(x, y);
261
 
261
 
262
    }
262
    }
263
}
263
}
264
 
264
 
265
static cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt){
265
//static cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt){
266
    assert(!img.empty());
266
//    assert(!img.empty());
267
    assert(img.channels() == 3);
267
//    assert(img.channels() == 3);
268
 
268
 
269
    int x = (int)pt.x;
269
//    int x = (int)pt.x;
270
    int y = (int)pt.y;
270
//    int y = (int)pt.y;
271
 
271
 
272
    int x0 = cv::borderInterpolate(x,   img.cols, cv::BORDER_REFLECT_101);
272
//    int x0 = cv::borderInterpolate(x,   img.cols, cv::BORDER_REFLECT_101);
273
    int x1 = cv::borderInterpolate(x+1, img.cols, cv::BORDER_REFLECT_101);
273
//    int x1 = cv::borderInterpolate(x+1, img.cols, cv::BORDER_REFLECT_101);
274
    int y0 = cv::borderInterpolate(y,   img.rows, cv::BORDER_REFLECT_101);
274
//    int y0 = cv::borderInterpolate(y,   img.rows, cv::BORDER_REFLECT_101);
275
    int y1 = cv::borderInterpolate(y+1, img.rows, cv::BORDER_REFLECT_101);
275
//    int y1 = cv::borderInterpolate(y+1, img.rows, cv::BORDER_REFLECT_101);
276
 
276
 
277
    float a = pt.x - (float)x;
277
//    float a = pt.x - (float)x;
278
    float c = pt.y - (float)y;
278
//    float c = pt.y - (float)y;
279
 
279
 
280
    uchar b = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[0] * a) * (1.f - c)
280
//    uchar b = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[0] * a) * (1.f - c)
281
                           + (img.at<cv::Vec3b>(y1, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[0] * a) * c);
281
//                           + (img.at<cv::Vec3b>(y1, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[0] * a) * c);
282
    uchar g = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[1] * a) * (1.f - c)
282
//    uchar g = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[1] * a) * (1.f - c)
283
                           + (img.at<cv::Vec3b>(y1, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[1] * a) * c);
283
//                           + (img.at<cv::Vec3b>(y1, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[1] * a) * c);
284
    uchar r = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[2] * a) * (1.f - c)
284
//    uchar r = (uchar)cvRound((img.at<cv::Vec3b>(y0, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y0, x1)[2] * a) * (1.f - c)
285
                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);
285
//                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);
286
 
286
 
287
    return cv::Vec3b(b, g, r);
287
//    return cv::Vec3b(b, g, r);
288
}
288
//}
289
 
289
 
290
void AlgorithmGrayCodeHorzVert::get3DPoints(SMCalibrationParameters calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
290
void AlgorithmGrayCodeHorzVert::get3DPoints(SMCalibrationParameters calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
291
 
291
 
292
    assert(frames0.size() == N);
292
    assert(frames0.size() == N);
293
    assert(frames1.size() == N);
293
    assert(frames1.size() == N);
Line 296... Line 296...
296
    int frameCols = frames0[0].cols;
296
    int frameCols = frames0[0].cols;
297
 
297
 
298
    // gray-scale
298
    // gray-scale
299
    std::vector<cv::Mat> frames0Gray(N);
299
    std::vector<cv::Mat> frames0Gray(N);
300
    std::vector<cv::Mat> frames1Gray(N);
300
    std::vector<cv::Mat> frames1Gray(N);
301
    for(int i=0; i<N; i++){
301
    for(unsigned int i=0; i<N; i++){
302
        cv::cvtColor(frames0[i], frames0Gray[i], CV_BayerBG2GRAY);
302
        cv::cvtColor(frames0[i], frames0Gray[i], CV_BayerBG2GRAY);
303
        cv::cvtColor(frames1[i], frames1Gray[i], CV_BayerBG2GRAY);
303
        cv::cvtColor(frames1[i], frames1Gray[i], CV_BayerBG2GRAY);
304
    }
304
    }
305
 
305
 
306
    // colors
306
    // colors
Line 331... Line 331...
331
    cv::Mat code1Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
331
    cv::Mat code1Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
332
    cv::Mat code0Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
332
    cv::Mat code0Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
333
    cv::Mat code1Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
333
    cv::Mat code1Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
334
 
334
 
335
    // horizontal codes into gray code
335
    // horizontal codes into gray code
336
    for(int i=0; i<NbitsHorz; i++){
336
    for(unsigned int i=0; i<NbitsHorz; i++){
337
        cv::Mat bit0;
337
        cv::Mat bit0;
338
        cv::compare(frames0Gray[i*2+2], frames0Gray[i*2+3], bit0, cv::CMP_GT);
338
        cv::compare(frames0Gray[i*2+2], frames0Gray[i*2+3], bit0, cv::CMP_GT);
339
        bit0.convertTo(bit0, CV_32S, 1.0/255.0);
339
        bit0.convertTo(bit0, CV_32S, 1.0/255.0);
340
        cv::add(code0Horz, bit0*twopowi(NbitsHorz-i-1), code0Horz, cv::Mat(), CV_32S);
340
        cv::add(code0Horz, bit0*twopowi(NbitsHorz-i-1), code0Horz, cv::Mat(), CV_32S);
341
 
341
 
Line 344... Line 344...
344
        bit1.convertTo(bit1, CV_32S, 1.0/255.0);
344
        bit1.convertTo(bit1, CV_32S, 1.0/255.0);
345
        cv::add(code1Horz, bit1*twopowi(NbitsHorz-i-1), code1Horz, cv::Mat(), CV_32S);
345
        cv::add(code1Horz, bit1*twopowi(NbitsHorz-i-1), code1Horz, cv::Mat(), CV_32S);
346
    }
346
    }
347
 
347
 
348
    // vertical codes into gray code
348
    // vertical codes into gray code
349
    for(int i=0; i<NbitsVert; i++){
349
    for(unsigned int i=0; i<NbitsVert; i++){
350
        cv::Mat bit0;
350
        cv::Mat bit0;
351
        cv::compare(frames0Gray[i*2+2*NbitsHorz+2], frames0Gray[i*2+2*NbitsHorz+3], bit0, cv::CMP_GT);
351
        cv::compare(frames0Gray[i*2+2*NbitsHorz+2], frames0Gray[i*2+2*NbitsHorz+3], bit0, cv::CMP_GT);
352
        bit0.convertTo(bit0, CV_32S, 1.0/255.0);
352
        bit0.convertTo(bit0, CV_32S, 1.0/255.0);
353
        cv::add(code0Vert, bit0*twopowi(NbitsVert-i-1), code0Vert, cv::Mat(), CV_32S);
353
        cv::add(code0Vert, bit0*twopowi(NbitsVert-i-1), code0Vert, cv::Mat(), CV_32S);
354
 
354
 
Line 382... Line 382...
382
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
382
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
383
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
383
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
384
 
384
 
385
    // match intersections
385
    // match intersections
386
    std::vector<intersection> matches0, matches1;
386
    std::vector<intersection> matches0, matches1;
387
    int i=0, j=0;
387
    unsigned int i=0, j=0;
388
 
388
 
389
    while(i<intersections0.size() && j<intersections1.size()){
389
    while(i<intersections0.size() && j<intersections1.size()){
390
        if(intersections0[i].id == intersections1[j].id){
390
        if(intersections0[i].id == intersections1[j].id){
391
            matches0.push_back(intersections0[i]);
391
            matches0.push_back(intersections0[i]);
392
            matches1.push_back(intersections1[j]);
392
            matches1.push_back(intersections1[j]);