Subversion Repositories seema-scanner

Rev

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

Rev 236 Rev 245
Line 154... Line 154...
154
        // interpolate horizontal coordinate
154
        // interpolate horizontal coordinate
155
        float row = matches[i].row;
155
        float row = matches[i].row;
156
        float col = matches[i].col;
156
        float col = matches[i].col;
157
        float colRight = col+1;
157
        float colRight = col+1;
158
 
158
 
159
        float posHorz = frames[2*levelHorz+2].at<unsigned char>(row, col);
159
        float posHorz = frames[2*levelHorz+2].at<float>(row, col);
160
        float negHorz = frames[2*levelHorz+3].at<unsigned char>(row, col);
160
        float negHorz = frames[2*levelHorz+3].at<float>(row, col);
161
        float posHorzRight = frames[2*levelHorz+2].at<unsigned char>(row, colRight);
161
        float posHorzRight = frames[2*levelHorz+2].at<float>(row, colRight);
162
        float negHorzRight = frames[2*levelHorz+3].at<unsigned char>(row, colRight);
162
        float negHorzRight = frames[2*levelHorz+3].at<float>(row, colRight);
163
 
163
 
164
        float x = col + (posHorz - negHorz)/(negHorzRight - negHorz - posHorzRight + posHorz);
164
        float x = col + (posHorz - negHorz)/(negHorzRight - negHorz - posHorzRight + posHorz);
165
 
165
 
166
        // interpolate vertical coordinate
166
        // interpolate vertical coordinate
167
        float rowBelow = row+1;
167
        float rowBelow = row+1;
168
 
168
 
169
        float posVert = frames[2*NbitsHorz+2*levelVert+2].at<unsigned char>(row, col);
169
        float posVert = frames[2*NbitsHorz+2*levelVert+2].at<float>(row, col);
170
        float negVert = frames[2*NbitsHorz+2*levelVert+3].at<unsigned char>(row, col);
170
        float negVert = frames[2*NbitsHorz+2*levelVert+3].at<float>(row, col);
171
        float posVertBelow = frames[2*NbitsHorz+2*levelVert+2].at<unsigned char>(rowBelow, col);
171
        float posVertBelow = frames[2*NbitsHorz+2*levelVert+2].at<float>(rowBelow, col);
172
        float negVertBelow = frames[2*NbitsHorz+2*levelVert+3].at<unsigned char>(rowBelow, col);
172
        float negVertBelow = frames[2*NbitsHorz+2*levelVert+3].at<float>(rowBelow, col);
173
 
173
 
174
        float y = row + (posVert - negVert)/(negVertBelow - negVert - posVertBelow + posVert);
174
        float y = row + (posVert - negVert)/(negVertBelow - negVert - posVertBelow + posVert);
175
 
175
 
176
        // write into return vector
176
        // write into return vector
177
        q[i] = cv::Point2f(x, y);
177
        q[i] = cv::Point2f(x, y);
178
 
178
 
179
    }
179
    }
180
}
180
}
181
 
181
 
182
void AlgorithmGrayCodeHorzVert::get3DPoints(const SMCalibrationParameters & calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3b>& color){
182
void AlgorithmGrayCodeHorzVert::get3DPoints(const SMCalibrationParameters & calibration, const std::vector<cv::Mat>& frames0, const std::vector<cv::Mat>& frames1, std::vector<cv::Point3f>& Q, std::vector<cv::Vec3f>& color){
183
 
183
 
184
    assert(frames0.size() == N);
184
    assert(frames0.size() == N);
185
    assert(frames1.size() == N);
185
    assert(frames1.size() == N);
186
 
186
 
187
    int frameRows = frames0[0].rows;
187
    int frameRows = frames0[0].rows;
Line 189... Line 189...
189
 
189
 
190
    // gray-scale
190
    // gray-scale
191
    std::vector<cv::Mat> frames0Gray(N);
191
    std::vector<cv::Mat> frames0Gray(N);
192
    std::vector<cv::Mat> frames1Gray(N);
192
    std::vector<cv::Mat> frames1Gray(N);
193
    for(unsigned int i=0; i<N; i++){
193
    for(unsigned int i=0; i<N; i++){
194
        cv::cvtColor(frames0[i], frames0Gray[i], CV_BayerBG2GRAY);
194
        cv::cvtColor(frames0[i], frames0Gray[i], CV_RGB2GRAY);
195
        cv::cvtColor(frames1[i], frames1Gray[i], CV_BayerBG2GRAY);
195
        cv::cvtColor(frames1[i], frames1Gray[i], CV_RGB2GRAY);
196
    }
196
    }
197
 
197
 
198
    // colors
198
    // colors
199
    cv::Mat color0;
199
    cv::Mat color0 = frames0[0];
200
//    frames0[0].convertTo(color0, CV_8UC3, 1.0/256.0);
-
 
201
    cv::cvtColor(frames0[0], color0, CV_BayerBG2RGB);
-
 
202
    cv::Mat color1;
200
    cv::Mat color1 = frames1[0];
203
//    frames1[0].convertTo(color1, CV_8UC3, 1.0/256.0);
-
 
204
    cv::cvtColor(frames1[0], color1, CV_BayerBG2RGB);
-
 
205
 
201
 
206
    // occlusion masks
202
    // occlusion masks
207
    cv::Mat occlusion0, occlusion1;
203
    cv::Mat occlusion0, occlusion1;
208
    cv::subtract(frames0[0], frames0[1], occlusion0);
204
    cv::subtract(frames0Gray[0], frames0Gray[1], occlusion0);
209
    occlusion0 = (occlusion0 > 20) & (occlusion0 < 250);
205
    occlusion0 = (occlusion0 > 0.1) & (occlusion0 < 0.98);
-
 
206
    //occlusion0.convertTo(occlusion0, CV_8UC1);
210
    cv::subtract(frames1[0], frames1[1], occlusion1);
207
    cv::subtract(frames1Gray[0], frames1Gray[1], occlusion1);
211
    occlusion1 = (occlusion1 > 20) & (occlusion1 < 250);
208
    occlusion1 = (occlusion1 > 0.1) & (occlusion1 < 0.98);
-
 
209
    //occlusion1.convertTo(occlusion1, CV_8UC1);
212
 
210
 
213
//    // erode occlusion masks
211
//    // erode occlusion masks
214
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3,3));
212
//    cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3,3));
215
//    cv::erode(occlusion0, occlusion0, strel);
213
//    cv::erode(occlusion0, occlusion0, strel);
216
//    cv::erode(occlusion1, occlusion1, strel);
214
//    cv::erode(occlusion1, occlusion1, strel);
217
 
215
 
-
 
216
        #ifdef QT_DEBUG
218
//cvtools::writeMat(occlusion0, "occlusion0.mat", "occlusion0");
217
            cvtools::writeMat(occlusion0, "occlusion0.mat", "occlusion0");
219
//cvtools::writeMat(occlusion1, "occlusion1.mat", "occlusion1");
218
            cvtools::writeMat(occlusion1, "occlusion1.mat", "occlusion1");
-
 
219
        #endif
220
 
220
 
221
    // decode patterns
221
    // decode patterns
222
    cv::Mat code0Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
222
    cv::Mat code0Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
223
    cv::Mat code1Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
223
    cv::Mat code1Horz(frameRows, frameCols, CV_32S, cv::Scalar(0));
224
    cv::Mat code0Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
224
    cv::Mat code0Vert(frameRows, frameCols, CV_32S, cv::Scalar(0));
Line 262... Line 262...
262
                code1Vert.at<int>(r,c) = -1;
262
                code1Vert.at<int>(r,c) = -1;
263
            }
263
            }
264
        }
264
        }
265
    }
265
    }
266
 
266
 
-
 
267
    #ifdef QT_DEBUG
267
//    cvtools::writeMat(code0Horz, "code0Horz.mat", "code0Horz");
268
        cvtools::writeMat(code0Horz, "code0Horz.mat", "code0Horz");
268
//    cvtools::writeMat(code1Horz, "code1Horz.mat", "code1Horz");
269
        cvtools::writeMat(code1Horz, "code1Horz.mat", "code1Horz");
269
//    cvtools::writeMat(code0Vert, "code0Vert.mat", "code0Vert");
270
        cvtools::writeMat(code0Vert, "code0Vert.mat", "code0Vert");
270
//    cvtools::writeMat(code1Vert, "code1Vert.mat", "code1Vert");
271
        cvtools::writeMat(code1Vert, "code1Vert.mat", "code1Vert");
-
 
272
    #endif
271
 
273
 
272
    // get intersections
274
    // get intersections
273
    std::vector<intersection> intersections0, intersections1;
275
    std::vector<intersection> intersections0, intersections1;
274
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
276
    getIntersectionLabels(code0Horz, code0Vert, NbitsHorz, NbitsVert, intersections0);
275
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
277
    getIntersectionLabels(code1Horz, code1Vert, NbitsHorz, NbitsVert, intersections1);
Line 312... Line 314...
312
    getSubpixelCoordinates(matches1, frames1Gray, NbitsHorz, NbitsVert, q1);
314
    getSubpixelCoordinates(matches1, frames1Gray, NbitsHorz, NbitsVert, q1);
313
 
315
 
314
    // retrieve color information (at subpixel coordinates)
316
    // retrieve color information (at subpixel coordinates)
315
    color.resize(nMatches);
317
    color.resize(nMatches);
316
    for(int i=0; i<nMatches; i++){
318
    for(int i=0; i<nMatches; i++){
317
        cv::Vec3b c0 = color0.at<cv::Vec3b>(std::floor(q0[i].y), std::floor(q0[i].x));
319
        cv::Vec3f c0 = color0.at<cv::Vec3f>(std::floor(q0[i].y), std::floor(q0[i].x));
318
        cv::Vec3b c1 = color1.at<cv::Vec3b>(std::floor(q1[i].y), std::floor(q1[i].x));
320
        cv::Vec3f c1 = color1.at<cv::Vec3f>(std::floor(q1[i].y), std::floor(q1[i].x));
319
 
321
 
320
        color[i] = 0.5*c0 + 0.5*c1;
322
        color[i] = 0.5*c0 + 0.5*c1;
321
    }
323
    }
322
 
324
 
323
    //cv::correctMatches(calibration.F, q0, q1, q0, q1);
325
    //cv::correctMatches(calibration.F, q0, q1, q0, q1);