Subversion Repositories seema-scanner

Rev

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

Rev 245 Rev 255
Line 10... Line 10...
10
#include "algorithmtools.h"
10
#include "algorithmtools.h"
11
 
11
 
12
// Algorithm
12
// Algorithm
13
AlgorithmGrayCode::AlgorithmGrayCode(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
13
AlgorithmGrayCode::AlgorithmGrayCode(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
14
 
14
 
15
    Nbits = ceilf(log2f((float)screenCols)) - 1;
15
    Nbits = 6;
16
    N = 2 + Nbits*2;
16
    N = 2 + Nbits*2;
17
 
17
 
18
    // all on pattern
18
    // all on pattern
19
    cv::Mat allOn(1, screenCols, CV_8UC3, cv::Scalar::all(255));
19
    cv::Mat allOn(1, screenCols, CV_8UC3, cv::Scalar::all(255));
20
    patterns.push_back(allOn);
20
    patterns.push_back(allOn);
Line 40... Line 40...
40
        }
40
        }
41
        patterns.push_back(pattern);
41
        patterns.push_back(pattern);
42
        patterns.push_back(patternInv);
42
        patterns.push_back(patternInv);
43
    }
43
    }
44
 
44
 
45
 
-
 
-
 
45
    std::cout << "N patterns" << patterns.size() << std::endl;
46
}
46
}
47
 
47
 
48
cv::Mat AlgorithmGrayCode::getEncodingPattern(unsigned int depth){
48
cv::Mat AlgorithmGrayCode::getEncodingPattern(unsigned int depth){
49
    return patterns[depth];
49
    return patterns[depth];
50
}
50
}
Line 64... Line 64...
64
    for(int col=1; col<nCols; col++){
64
    for(int col=1; col<nCols; col++){
65
 
65
 
66
        labelLeft = labelRight;
66
        labelLeft = labelRight;
67
        labelRight = data[col];
67
        labelRight = data[col];
68
 
68
 
69
        // labels need to be non-background, and differ in exactly one bit
69
        // labels need to be non-background
-
 
70
        if(labelLeft != -1 && labelRight != -1) {
70
        if(labelLeft != -1 && labelRight != -1 && (grayToBinary(labelRight) == grayToBinary(labelLeft)+1)){
71
            unsigned int binLeft = grayToBinary(labelLeft);
-
 
72
            unsigned int binRight = grayToBinary(labelRight);
-
 
73
            // and differ in exactly one bit
-
 
74
            if (binRight + 1 == binLeft || binRight == binLeft + 1) {
71
            int orderingRelation = (labelLeft << Nbits) + labelRight;
75
                int orderingRelation = (labelLeft << Nbits) + labelRight;
72
            // store left label column
76
                // store left label column
73
            edges.push_back(cv::Vec4i(col-1, labelLeft, labelRight, orderingRelation));
77
                edges.push_back(cv::Vec4i(col-1, labelLeft, labelRight, orderingRelation));
-
 
78
            }
74
        }
79
        }
75
    }
80
    }
76
 
81
 
77
    // sort
82
    // sort
78
    std::sort(edges.begin(), edges.end(), sortingLarger);
83
    std::sort(edges.begin(), edges.end(), sortingLarger);
Line 114... Line 119...
114
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
119
        cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
115
        cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
120
        cv::cvtColor(frames1[i], temp, CV_RGB2GRAY);
116
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
121
        cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
117
    }
122
    }
118
 
123
 
119
    #ifdef QT_DEBUG
-
 
120
        cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
-
 
121
        cvtools::writeMat(frames0[0], "frames0_0.mat", "frames0_0");
-
 
122
 
-
 
123
        cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
-
 
124
        cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
-
 
125
 
-
 
126
        cv::imwrite("frames0[0].png", frames0[0]);
-
 
127
        cv::imwrite("frames0Rect[0].png", frames0Rect[0]);
-
 
128
 
-
 
129
        cv::imwrite("frames1[0].png", frames1[0]);
-
 
130
        cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
-
 
131
    #endif
-
 
132
 
-
 
133
    // color remap
124
    // color remap
134
    cv::Mat color0Rect, color1Rect;
125
    cv::Mat color0Rect, color1Rect;
135
    cv::remap(frames0[0], color0Rect, map0X, map0Y, CV_INTER_LINEAR);
126
    cv::remap(frames0[0], color0Rect, map0X, map0Y, CV_INTER_LINEAR);
136
    cv::remap(frames1[0], color1Rect, map1X, map1Y, CV_INTER_LINEAR);
127
    cv::remap(frames1[0], color1Rect, map1X, map1Y, CV_INTER_LINEAR);
137
 
128
 
Line 190... Line 181...
190
        cv::compare(frames1Rect[i*2+2], frames1Rect[i*2+3], temp, cv::CMP_GT);
181
        cv::compare(frames1Rect[i*2+2], frames1Rect[i*2+3], temp, cv::CMP_GT);
191
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
182
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
192
        cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::noArray(), CV_32S);
183
        cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::noArray(), CV_32S);
193
    }
184
    }
194
 
185
 
-
 
186
 
195
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
187
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
196
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
188
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
197
 
189
 
198
 
190
 
199
    #ifdef QT_DEBUG
191
    #ifdef QT_DEBUG
Line 231... Line 223...
231
            if(occlusion1Rect.at<unsigned char>(r,c) == 0)
223
            if(occlusion1Rect.at<unsigned char>(r,c) == 0)
232
                code1Rect.at<int>(r,c) = -1;
224
                code1Rect.at<int>(r,c) = -1;
233
        }
225
        }
234
    }
226
    }
235
 
227
 
-
 
228
 
-
 
229
#ifdef QT_DEBUG
-
 
230
    cv::imwrite("code0Rect.png", code0Rect);
-
 
231
    cv::imwrite("code1Rect.png", code1Rect);
-
 
232
#endif
-
 
233
 
236
    #ifdef QT_DEBUG
234
    #ifdef QT_DEBUG
237
        cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
235
        cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
238
        cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
236
        cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
239
    #endif
237
    #endif
240
 
238