Subversion Repositories seema-scanner

Rev

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

Rev 96 Rev 98
Line 150... Line 150...
150
cv::Mat AlgorithmGrayCodeHQ::getEncodingPattern(unsigned int depth){
150
cv::Mat AlgorithmGrayCodeHQ::getEncodingPattern(unsigned int depth){
151
    return patterns[depth];
151
    return patterns[depth];
152
}
152
}
153
 
153
 
154
 
154
 
155
bool sortingLarger(cv::Vec3i i,cv::Vec3i j){ return (i[2]<j[2]);}
155
static bool sortingLarger(cv::Vec3d i,cv::Vec3d j){ return (i[2]<j[2]);}
156
bool sortingEqual(cv::Vec3i i,cv::Vec3i j){ return (i[2]==j[2]);}
156
static bool sortingEqual(cv::Vec3d i,cv::Vec3d j){ return (i[2]==j[2]);}
157
 
157
 
158
void getIntersectionLabels(const cv::Mat& codeHorz, const cv::Mat& codeVert, int NbitsHorz, int NbitsVert, std::vector<cv::Vec3i>& intersections){
158
static void getIntersectionLabels(const cv::Mat& codeHorz, const cv::Mat& codeVert, int NbitsHorz, int NbitsVert, std::vector< cv::Vec3d >& intersections){
159
 
159
 
160
    int nRows = codeHorz.rows;
160
    int nRows = codeHorz.rows;
161
    int nCols = codeHorz.cols;
161
    int nCols = codeHorz.cols;
162
 
162
 
163
    int labelHorz;
163
    int labelHorz;
Line 180... Line 180...
180
               countBits(labelHorz^labelHorzRight) == 1 &&
180
               countBits(labelHorz^labelHorzRight) == 1 &&
181
               labelVert != -1 && labelVertBelow != -1 &&
181
               labelVert != -1 && labelVertBelow != -1 &&
182
               countBits(labelVert^labelVertBelow) == 1){
182
               countBits(labelVert^labelVertBelow) == 1){
183
 
183
 
184
                // OVERFLOW??
184
                // OVERFLOW??
185
                int orderingRelation = (labelHorz << NbitsHorz+2*NbitsVert) + (labelHorzRight << 2*NbitsVert) +
185
                double orderingRelation = ((ulong)labelHorz << NbitsHorz+2*NbitsVert) + ((ulong)labelHorzRight << 2*NbitsVert) +
186
                                       (labelVert << NbitsVert) + labelVertBelow;
186
                                          ((ulong)labelVert << NbitsVert) + (ulong)labelVertBelow;
187
                // store left label column
187
                // store left label column
188
                intersections.push_back(cv::Vec3i(row, col, orderingRelation));
188
                intersections.push_back(cv::Vec3d(row, col, orderingRelation));
189
            }
189
            }
190
        }
190
        }
191
    }
191
    }
192
    // sort
192
    // sort
193
    std::sort(intersections.begin(), intersections.end(), sortingLarger);
193
    std::sort(intersections.begin(), intersections.end(), sortingLarger);
194
 
194
 
195
    // remove duplicates
195
    // remove duplicates
196
    std::vector<cv::Vec3i>::iterator it;
196
    std::vector< cv::Vec3d >::iterator it;
197
    it = std::unique(intersections.begin(), intersections.end(), sortingEqual);
197
    it = std::unique(intersections.begin(), intersections.end(), sortingEqual);
198
    intersections.resize(std::distance(intersections.begin(),it));
198
    intersections.resize(std::distance(intersections.begin(),it));
199
}
199
}
200
 
200
 
201
cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt){
201
static cv::Vec3b getColorSubpix(const cv::Mat& img, cv::Point2f pt){
202
    assert(!img.empty());
202
    assert(!img.empty());
203
    assert(img.channels() == 3);
203
    assert(img.channels() == 3);
204
 
204
 
205
    int x = (int)pt.x;
205
    int x = (int)pt.x;
206
    int y = (int)pt.y;
206
    int y = (int)pt.y;
Line 233... Line 233...
233
 
233
 
234
    // gray-scale
234
    // gray-scale
235
    std::vector<cv::Mat> frames0Gray(N);
235
    std::vector<cv::Mat> frames0Gray(N);
236
    std::vector<cv::Mat> frames1Gray(N);
236
    std::vector<cv::Mat> frames1Gray(N);
237
    for(int i=0; i<N; i++){
237
    for(int i=0; i<N; i++){
238
        cv::cvtColor(frames0[i], frames0Gray, CV_RGB2GRAY);
238
        cv::cvtColor(frames0[i], frames0Gray[i], CV_RGB2GRAY);
239
        cv::cvtColor(frames1[i], frames1Gray, CV_RGB2GRAY);
239
        cv::cvtColor(frames1[i], frames1Gray[i], CV_RGB2GRAY);
240
    }
240
    }
241
 
241
 
242
    // colors
242
    // colors
243
    cv::Mat color0 = frames0[0];
243
    cv::Mat color0 = frames0[0];
244
    cv::Mat color1 = frames1[0];
244
    cv::Mat color1 = frames1[0];
Line 312... Line 312...
312
            }
312
            }
313
        }
313
        }
314
    }
314
    }
315
 
315
 
316
    // matching
316
    // matching
317
    std::vector<cv::Vec3i> intersections0, intersections1;
317
    std::vector< cv::Vec3d > intersections0, intersections1;
318
 
318
 
319
    // intersection data structure containing [floor(row), floor(column), orderingRelation]
319
    // intersection data structure containing [floor(row), floor(column), orderingRelation]
320
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
320
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
321
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
321
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
322
 
322
 
323
    // match intersections
323
    // match intersections
324
    std::vector<cv::Vec3i> matches0, matches1;
324
    std::vector< cv::Vec3d > matches0, matches1;
325
    int i=0, j=0;
325
    int i=0, j=0;
326
 
326
 
327
    while(i<intersections0.size() && j<intersections1.size()){
327
    while(i<intersections0.size() && j<intersections1.size()){
328
        if(intersections0[i][2] == intersections1[j][2]){
328
        if(intersections0[i][2] == intersections1[j][2]){
329
            matches0.push_back(intersections0[i]);
329
            matches0.push_back(intersections0[i]);
Line 335... Line 335...
335
        } else if(intersections0[i][2] > intersections1[j][2]){
335
        } else if(intersections0[i][2] > intersections1[j][2]){
336
            j += 1;
336
            j += 1;
337
        }
337
        }
338
    }
338
    }
339
 
339
 
-
 
340
    int nMatches = matches0.size();
-
 
341
 
-
 
342
    if(nMatches < 1){
-
 
343
        Q.resize(0);
-
 
344
        color.resize(0);
-
 
345
 
-
 
346
        return;
-
 
347
    }
-
 
348
 
340
    std::vector<cv::Vec2f> q0, q1;
349
    std::vector<cv::Vec2f> q0(nMatches), q1(nMatches);
-
 
350
 
-
 
351
    for(int i=0; i<nMatches; i++){
-
 
352
        q0[i] = cv::Vec2f(matches0[i][1], matches0[i][0]);
-
 
353
        q1[i] = cv::Vec2f(matches1[i][1], matches1[i][0]);
-
 
354
    }
341
 
355
 
342
    // TODO: subpixel refinement in both horizontal and vertical
356
    // TODO: subpixel refinement in both horizontal and vertical
343
//    // subpixel refinement finds the intersection of linear interpolants in the positive/negative pattern
357
//    // subpixel refinement finds the intersection of linear interpolants in the positive/negative pattern
344
//    for(int i=0; i<matchedEdges0.size(); i++){
358
//    for(int i=0; i<matchedEdges0.size(); i++){
345
 
359
 
Line 370... Line 384...
370
//        q1Rect.push_back(cv::Point2f(col, row));
384
//        q1Rect.push_back(cv::Point2f(col, row));
371
 
385
 
372
//    }
386
//    }
373
 
387
 
374
 
388
 
375
    int nMatches = q0.size();
-
 
376
 
-
 
377
    if(nMatches < 1){
-
 
378
        Q.resize(0);
-
 
379
        color.resize(0);
-
 
380
 
389
 
381
        return;
-
 
382
    }
-
 
383
 
390
 
384
    // retrieve color information (at integer coordinates)
391
    // retrieve color information (at integer coordinates)
385
    color.resize(nMatches);
392
    color.resize(nMatches);
386
    for(int i=0; i<nMatches; i++){
393
    for(int i=0; i<nMatches; i++){
387
 
394
 
388
        cv::Vec3b c0 = color0.at<cv::Vec3b>(q0[i][1], q0[i][0]);
395
//        cv::Vec3b c0 = color0.at<cv::Vec3b>(q0[i][1], q0[i][0]);
389
        cv::Vec3b c1 = color1.at<cv::Vec3b>(q1[i][1], q1[i][0]);
396
//        cv::Vec3b c1 = color1.at<cv::Vec3b>(q1[i][1], q1[i][0]);
390
//        cv::Vec3b c0 = getColorSubpix(color0Rect, q0Rect[i]);
397
        cv::Vec3b c0 = getColorSubpix(color0, q0[i]);
391
//        cv::Vec3b c1 = getColorSubpix(color1Rect, q0Rect[i]);
398
        cv::Vec3b c1 = getColorSubpix(color1, q1[i]);
392
 
399
 
393
        color[i] = 0.5*c0 + 0.5*c1;
400
        color[i] = 0.5*c0 + 0.5*c1;
394
    }
401
    }
395
 
402
 
396
    // triangulate points
403
    // triangulate points