Subversion Repositories seema-scanner

Rev

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

Rev 91 Rev 95
Line 147... Line 147...
147
    for(int col=1; col<nCols; col++){
147
    for(int col=1; col<nCols; col++){
148
 
148
 
149
        labelLeft = labelRight;
149
        labelLeft = labelRight;
150
        labelRight = data[col];
150
        labelRight = data[col];
151
 
151
 
152
        // labels need to non-background, and differ in exactly one bit
152
        // labels need to be non-background, and differ in exactly one bit
153
        if(labelLeft != -1 && labelRight != -1 && countBits(labelLeft^labelRight) == 1){
153
        if(labelLeft != -1 && labelRight != -1 && countBits(labelLeft^labelRight) == 1){
154
            int orderingRelation = (labelLeft << Nbits) + labelRight;
154
            int orderingRelation = (labelLeft << Nbits) + labelRight;
155
            // store left label column
155
            // store left label column
156
            edges.push_back(cv::Vec4i(col-1, labelLeft, labelRight, orderingRelation));
156
            edges.push_back(cv::Vec4i(col-1, labelLeft, labelRight, orderingRelation));
157
        }
157
        }
Line 164... Line 164...
164
    std::vector<cv::Vec4i>::iterator it;
164
    std::vector<cv::Vec4i>::iterator it;
165
    it = std::unique(edges.begin(), edges.end(), sortingEqual);
165
    it = std::unique(edges.begin(), edges.end(), sortingEqual);
166
    edges.resize(std::distance(edges.begin(),it));
166
    edges.resize(std::distance(edges.begin(),it));
167
}
167
}
168
 
168
 
-
 
169
cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt){
-
 
170
    assert(!img.empty());
-
 
171
    assert(img.channels() == 3);
-
 
172
 
-
 
173
    int x = (int)pt.x;
-
 
174
    int y = (int)pt.y;
-
 
175
 
-
 
176
    int x0 = cv::borderInterpolate(x,   img.cols, cv::BORDER_REFLECT_101);
-
 
177
    int x1 = cv::borderInterpolate(x+1, img.cols, cv::BORDER_REFLECT_101);
-
 
178
    int y0 = cv::borderInterpolate(y,   img.rows, cv::BORDER_REFLECT_101);
-
 
179
    int y1 = cv::borderInterpolate(y+1, img.rows, cv::BORDER_REFLECT_101);
-
 
180
 
-
 
181
    float a = pt.x - (float)x;
-
 
182
    float c = pt.y - (float)y;
-
 
183
 
-
 
184
    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)
-
 
185
                           + (img.at<cv::Vec3b>(y1, x0)[0] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[0] * a) * c);
-
 
186
    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)
-
 
187
                           + (img.at<cv::Vec3b>(y1, x0)[1] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[1] * a) * c);
-
 
188
    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)
-
 
189
                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);
-
 
190
 
-
 
191
    return cv::Vec3b(b, g, r);
-
 
192
}
-
 
193
 
169
void AlgorithmGrayCode::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){
194
void AlgorithmGrayCode::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){
170
 
195
 
171
    assert(frames0.size() == N);
196
    assert(frames0.size() == N);
172
    assert(frames1.size() == N);
197
    assert(frames1.size() == N);
173
 
198
 
Line 306... Line 331...
306
 
331
 
307
    // matching
332
    // matching
308
    std::vector<cv::Vec2f> q0Rect, q1Rect;
333
    std::vector<cv::Vec2f> q0Rect, q1Rect;
309
    for(int row=0; row<frameRectRows; row++){
334
    for(int row=0; row<frameRectRows; row++){
310
 
335
 
-
 
336
        // edge data structure containing [floor(column), labelLeft, labelRight, orderingRelation]
311
        std::vector<cv::Vec4i> edges0, edges1;
337
        std::vector<cv::Vec4i> edges0, edges1;
312
 
338
 
313
        // sorted, unique edges
339
        // sorted, unique edges
314
        getEdgeLabels(code0Rect.row(row), Nbits, edges0);
340
        getEdgeLabels(code0Rect.row(row), Nbits, edges0);
315
        getEdgeLabels(code1Rect.row(row), Nbits, edges1);
341
        getEdgeLabels(code1Rect.row(row), Nbits, edges1);
Line 372... Line 398...
372
        color.resize(0);
398
        color.resize(0);
373
 
399
 
374
        return;
400
        return;
375
    }
401
    }
376
 
402
 
377
    // retrieve color information
403
    // retrieve color information (at integer coordinates)
378
    color.resize(nMatches);
404
    color.resize(nMatches);
379
    for(int i=0; i<nMatches; i++){
405
    for(int i=0; i<nMatches; i++){
380
 
406
 
381
        cv::Vec3b c0 = color0Rect.at<cv::Vec3b>(q0Rect[i][1], q0Rect[i][0]);
407
        cv::Vec3b c0 = color0Rect.at<cv::Vec3b>(q0Rect[i][1], q0Rect[i][0]);
382
        cv::Vec3b c1 = color1Rect.at<cv::Vec3b>(q1Rect[i][1], q1Rect[i][0]);
408
        cv::Vec3b c1 = color1Rect.at<cv::Vec3b>(q1Rect[i][1], q1Rect[i][0]);
-
 
409
//        cv::Vec3b c0 = getColorSubpix(color0Rect, q0Rect[i]);
-
 
410
//        cv::Vec3b c1 = getColorSubpix(color1Rect, q0Rect[i]);
383
 
411
 
384
        color[i] = 0.5*c0 + 0.5*c1;
412
        color[i] = 0.5*c0 + 0.5*c1;
385
    }
413
    }
386
 
414
 
387
    // triangulate points
415
    // triangulate points
Line 391... Line 419...
391
//    C0.colRange(0, 3) = C0.colRange(0, 3)*R0;
419
//    C0.colRange(0, 3) = C0.colRange(0, 3)*R0;
392
//    C1.colRange(0, 3) = C1.colRange(0, 3)*R1.t();
420
//    C1.colRange(0, 3) = C1.colRange(0, 3)*R1.t();
393
    cv::triangulatePoints(P0, P1, q0Rect, q1Rect, QMatHomogenous);
421
    cv::triangulatePoints(P0, P1, q0Rect, q1Rect, QMatHomogenous);
394
    cvtools::convertMatFromHomogeneous(QMatHomogenous, QMat);
422
    cvtools::convertMatFromHomogeneous(QMatHomogenous, QMat);
395
 
423
 
396
    // undo rectification
424
    // undo rectifying rotation
397
    cv::Mat R0Inv;
425
    cv::Mat R0Inv;
398
    cv::Mat(R0.t()).convertTo(R0Inv, CV_32F);
426
    cv::Mat(R0.t()).convertTo(R0Inv, CV_32F);
399
    QMat = R0Inv*QMat;
427
    QMat = R0Inv*QMat;
400
 
428
 
401
    cvtools::matToPoints3f(QMat, Q);
429
    cvtools::matToPoints3f(QMat, Q);