Line 231... |
Line 231... |
231 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
|
231 |
cv::remap(temp, frames0Rect[i], map0X, map0Y, CV_INTER_LINEAR);
|
232 |
cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
|
232 |
cv::cvtColor(frames1[i], temp, CV_BayerBG2GRAY);
|
233 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
|
233 |
cv::remap(temp, frames1Rect[i], map1X, map1Y, CV_INTER_LINEAR);
|
234 |
}
|
234 |
}
|
235 |
|
235 |
|
- |
|
236 |
|
236 |
// cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
237 |
// cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
237 |
// cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
238 |
// cvtools::writeMat(frames0[0], "frames0_0.mat", "frames0_0");
|
238 |
|
239 |
|
239 |
// cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
240 |
// cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
240 |
// cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
241 |
// cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
241 |
|
242 |
|
242 |
// cv::imwrite("frames0[0].png", frames0[0]);
|
243 |
// cv::imwrite("frames0[0].png", frames0[0]);
|
Line 244... |
Line 245... |
244 |
|
245 |
|
245 |
// cv::imwrite("frames1[0].png", frames1[0]);
|
246 |
// cv::imwrite("frames1[0].png", frames1[0]);
|
246 |
// cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
|
247 |
// cv::imwrite("frames1Rect[0].png", frames1Rect[0]);
|
247 |
|
248 |
|
248 |
// color debayer and remap
|
249 |
// color debayer and remap
|
249 |
cv::Mat temp;
|
- |
|
250 |
cv::Mat color0Rect, color1Rect;
|
250 |
cv::Mat color0Rect, color1Rect;
|
- |
|
251 |
frames0[0].convertTo(color0Rect, CV_8UC1, 1.0/256.0);
|
251 |
cv::cvtColor(frames0[0], temp, CV_BayerBG2RGB);
|
252 |
cv::cvtColor(color0Rect, color0Rect, CV_BayerBG2RGB);
|
252 |
cv::remap(temp, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
|
253 |
cv::remap(color0Rect, color0Rect, map0X, map0Y, CV_INTER_LINEAR);
|
- |
|
254 |
|
- |
|
255 |
frames1[0].convertTo(color1Rect, CV_8UC1, 1.0/256.0);
|
253 |
cv::cvtColor(frames1[0], temp, CV_BayerBG2RGB);
|
256 |
cv::cvtColor(color1Rect, color1Rect, CV_BayerBG2RGB);
|
254 |
cv::remap(temp, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
|
257 |
cv::remap(color1Rect, color1Rect, map1X, map1Y, CV_INTER_LINEAR);
|
255 |
|
258 |
|
256 |
int frameRectRows = frames0Rect[0].rows;
|
259 |
int frameRectRows = frames0Rect[0].rows;
|
257 |
int frameRectCols = frames0Rect[0].cols;
|
260 |
int frameRectCols = frames0Rect[0].cols;
|
258 |
|
261 |
|
- |
|
262 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
- |
|
263 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
- |
|
264 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
265 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
266 |
|
259 |
// occlusion masks
|
267 |
// occlusion masks
|
260 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
268 |
cv::Mat occlusion0Rect, occlusion1Rect;
|
261 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
269 |
cv::subtract(frames0Rect[0], frames0Rect[1], occlusion0Rect);
|
262 |
occlusion0Rect = (occlusion0Rect > 25) & (occlusion0Rect < 250);
|
270 |
occlusion0Rect = (occlusion0Rect > 16000) & (occlusion0Rect < 54000);
|
263 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
271 |
cv::subtract(frames1Rect[0], frames1Rect[1], occlusion1Rect);
|
264 |
occlusion1Rect = (occlusion1Rect > 25) & (occlusion1Rect < 250);
|
272 |
occlusion1Rect = (occlusion1Rect > 16000) & (occlusion1Rect < 54000);
|
265 |
|
273 |
|
266 |
// erode occlusion masks
|
274 |
// erode occlusion masks
|
267 |
cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
|
275 |
cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2,2));
|
268 |
cv::erode(occlusion0Rect, occlusion0Rect, strel);
|
276 |
cv::erode(occlusion0Rect, occlusion0Rect, strel);
|
269 |
cv::erode(occlusion1Rect, occlusion1Rect, strel);
|
277 |
cv::erode(occlusion1Rect, occlusion1Rect, strel);
|
270 |
|
278 |
|
- |
|
279 |
//cvtools::writeMat(frames0Rect[0], "frames0Rect_0.mat", "frames0Rect_0");
|
- |
|
280 |
//cvtools::writeMat(frames0Rect[1], "frames0Rect_1.mat", "frames0Rect_1");
|
- |
|
281 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
282 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
283 |
|
- |
|
284 |
// // correct for projector inversion error
|
- |
|
285 |
// cv::Mat W;
|
- |
|
286 |
// cv::add(frames0Rect[0], frames0Rect[1], W, cv::noArray(), CV_32F);
|
- |
|
287 |
// for(int i=2; i<N; i+=2){
|
- |
|
288 |
// cv::Mat S, E;
|
- |
|
289 |
// cv::add(frames0Rect[i], frames0Rect[i+1], S, cv::noArray(), CV_32F);
|
- |
|
290 |
// cv::subtract(W, S, E, cv::noArray(), CV_32F);
|
- |
|
291 |
// E *= 0.5;
|
- |
|
292 |
// cv::add(frames0Rect[i], E, frames0Rect[i], cv::noArray(), CV_16UC1);
|
- |
|
293 |
// cv::add(frames0Rect[i+1], E, frames0Rect[i+1], cv::noArray(), CV_16UC1);
|
- |
|
294 |
// }
|
- |
|
295 |
|
- |
|
296 |
|
- |
|
297 |
// correct for texture modulation and ambient
|
- |
|
298 |
cv::Mat A0 = frames0Rect[1];
|
- |
|
299 |
cv::Mat M0 = frames0Rect[0]-frames0Rect[1];
|
- |
|
300 |
//cvtools::writeMat(A0, "A0.mat", "A0");
|
- |
|
301 |
//cvtools::writeMat(M0, "M0.mat", "M0");
|
- |
|
302 |
//cvtools::writeMat(frames0Rect[20], "frames0Rect_20.mat", "frames0Rect_20");
|
- |
|
303 |
//cvtools::writeMat(frames0Rect[21], "frames0Rect_21.mat", "frames0Rect_21");
|
- |
|
304 |
cv::divide(65536.0, M0, M0, CV_32F);
|
- |
|
305 |
cv::Mat A1 = frames1Rect[1];
|
- |
|
306 |
cv::Mat M1 = frames1Rect[0]-frames1Rect[1];
|
- |
|
307 |
cv::divide(65536.0, M1, M1, CV_32F);
|
- |
|
308 |
|
- |
|
309 |
for(int i=2; i<N; i++){
|
- |
|
310 |
cv::multiply(frames0Rect[i]-A0, M0, frames0Rect[i], 1.0, CV_16UC1);
|
- |
|
311 |
cv::multiply(frames1Rect[i]-A1, M1, frames1Rect[i], 1.0, CV_16UC1);
|
- |
|
312 |
}
|
- |
|
313 |
|
- |
|
314 |
//cvtools::writeMat(frames0Rect[22], "frames0Rect_22.mat", "frames0Rect_22");
|
- |
|
315 |
//cvtools::writeMat(frames0Rect[23], "frames0Rect_23.mat", "frames0Rect_23");
|
- |
|
316 |
|
271 |
//cvtools::writeMat(occlusion0Rect, "occlusion0Rect.mat", "occlusion0Rect");
|
317 |
//cvtools::writeMat(occlusion0Rect, "occlusion0Rect.mat", "occlusion0Rect");
|
272 |
//cvtools::writeMat(occlusion1Rect, "occlusion1Rect.mat", "occlusion1Rect");
|
318 |
//cvtools::writeMat(occlusion1Rect, "occlusion1Rect.mat", "occlusion1Rect");
|
273 |
|
319 |
|
274 |
// decode patterns
|
320 |
// decode patterns
|
275 |
cv::Mat code0Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
321 |
cv::Mat code0Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
276 |
cv::Mat code1Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
322 |
cv::Mat code1Rect(frameRectRows, frameRectCols, CV_32S, cv::Scalar(0));
|
277 |
|
323 |
|
278 |
// into gray code
|
324 |
// into gray code
|
279 |
for(int i=0; i<Nbits; i++){
|
325 |
for(int i=0; i<Nbits; i++){
|
280 |
cv::Mat bit0;
|
326 |
cv::Mat temp, bit0, bit1;
|
- |
|
327 |
|
281 |
cv::subtract(frames0Rect[i*2+2], frames0Rect[i*2+3], bit0);
|
328 |
cv::compare(frames0Rect[i*2+2], frames0Rect[i*2+3], temp, cv::CMP_GT);
|
282 |
bit0 = bit0 > 0;
|
329 |
//cvtools::rshift(temp, 8);
|
283 |
bit0.convertTo(bit0, CV_32S, 1.0/255.0);
|
330 |
temp.convertTo(bit0, CV_32S, 1.0/255.0);
|
284 |
// cvtools::writeMat(bit0, "bit0.mat", "bit0");
|
- |
|
285 |
cv::add(code0Rect, bit0*twopowi(Nbits-i-1), code0Rect, cv::Mat(), CV_32S);
|
331 |
cv::add(code0Rect, bit0*twopowi(Nbits-i-1), code0Rect, cv::noArray(), CV_32S);
|
286 |
cv::Mat bit1;
|
- |
|
- |
|
332 |
|
287 |
cv::subtract(frames1Rect[i*2+2], frames1Rect[i*2+3], bit1);
|
333 |
cv::compare(frames1Rect[i*2+2], frames1Rect[i*2+3], temp, cv::CMP_GT);
|
288 |
bit1 = bit1 > 0;
|
334 |
//cvtools::rshift(temp, 8);
|
289 |
bit1.convertTo(bit1, CV_32S, 1.0/255.0);
|
335 |
temp.convertTo(bit1, CV_32S, 1.0/255.0);
|
290 |
cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::Mat(), CV_32S);
|
336 |
cv::add(code1Rect, bit1*twopowi(Nbits-i-1), code1Rect, cv::noArray(), CV_32S);
|
291 |
}
|
337 |
}
|
292 |
|
338 |
|
293 |
//cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
339 |
cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
294 |
//cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
340 |
cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
295 |
|
341 |
|
296 |
|
342 |
|
297 |
// // convert to standard binary
|
343 |
// // convert to standard binary
|
298 |
// cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
|
344 |
// cv::Mat code0Binary(code0Rect.rows, code0Rect.cols, CV_32F);
|
299 |
// cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
|
345 |
// cv::Mat code1Binary(code1Rect.rows, code1Rect.cols, CV_32F);
|
Line 322... |
Line 368... |
322 |
//cvtools::writeMat(edges1, "edges1.mat", "edges1");
|
368 |
//cvtools::writeMat(edges1, "edges1.mat", "edges1");
|
323 |
|
369 |
|
324 |
// set occluded pixels to -1
|
370 |
// set occluded pixels to -1
|
325 |
for(int r=0; r<frameRectRows; r++){
|
371 |
for(int r=0; r<frameRectRows; r++){
|
326 |
for(int c=0; c<frameRectCols; c++){
|
372 |
for(int c=0; c<frameRectCols; c++){
|
327 |
if(occlusion0Rect.at<char>(r,c) == 0)
|
373 |
if(occlusion0Rect.at<unsigned char>(r,c) == 0)
|
328 |
code0Rect.at<float>(r,c) = -1;
|
374 |
code0Rect.at<int>(r,c) = -1;
|
329 |
if(occlusion1Rect.at<char>(r,c) == 0)
|
375 |
if(occlusion1Rect.at<unsigned char>(r,c) == 0)
|
330 |
code1Rect.at<float>(r,c) = -1;
|
376 |
code1Rect.at<int>(r,c) = -1;
|
331 |
}
|
377 |
}
|
332 |
}
|
378 |
}
|
333 |
|
379 |
|
- |
|
380 |
// cvtools::writeMat(code0Rect, "code0Rect.mat", "code0Rect");
|
- |
|
381 |
// cvtools::writeMat(code1Rect, "code1Rect.mat", "code1Rect");
|
- |
|
382 |
|
334 |
// matching
|
383 |
// matching
|
335 |
std::vector<cv::Vec2f> q0Rect, q1Rect;
|
384 |
std::vector<cv::Vec2f> q0Rect, q1Rect;
|
336 |
for(int row=0; row<frameRectRows; row++){
|
385 |
for(int row=0; row<frameRectRows; row++){
|
337 |
|
386 |
|
338 |
// edge data structure containing [floor(column), labelLeft, labelRight, orderingRelation]
|
387 |
// edge data structure containing [floor(column), labelLeft, labelRight, orderingRelation]
|
Line 367... |
Line 416... |
367 |
|
416 |
|
368 |
// refine for camera 0
|
417 |
// refine for camera 0
|
369 |
float c0 = matchedEdges0[i][0];
|
418 |
float c0 = matchedEdges0[i][0];
|
370 |
float c1 = c0+1;
|
419 |
float c1 = c0+1;
|
371 |
|
420 |
|
372 |
float pos0 = frames0Rect[2*level+2].at<char>(row, c0);
|
421 |
float pos0 = frames0Rect[2*level+2].at<unsigned short>(row, c0);
|
373 |
float pos1 = frames0Rect[2*level+2].at<char>(row, c1);
|
422 |
float pos1 = frames0Rect[2*level+2].at<unsigned short>(row, c1);
|
374 |
float neg0 = frames0Rect[2*level+3].at<char>(row, c0);
|
423 |
float neg0 = frames0Rect[2*level+3].at<unsigned short>(row, c0);
|
375 |
float neg1 = frames0Rect[2*level+3].at<char>(row, c1);
|
424 |
float neg1 = frames0Rect[2*level+3].at<unsigned short>(row, c1);
|
376 |
|
425 |
|
377 |
float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
426 |
float col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
378 |
q0Rect.push_back(cv::Point2f(col, row));
|
427 |
q0Rect.push_back(cv::Point2f(col, row));
|
379 |
|
428 |
|
380 |
// refine for camera 1
|
429 |
// refine for camera 1
|
381 |
c0 = matchedEdges1[i][0];
|
430 |
c0 = matchedEdges1[i][0];
|
382 |
c1 = c0+1;
|
431 |
c1 = c0+1;
|
383 |
|
432 |
|
384 |
pos0 = frames1Rect[2*level+2].at<char>(row, c0);
|
433 |
pos0 = frames1Rect[2*level+2].at<unsigned short>(row, c0);
|
385 |
pos1 = frames1Rect[2*level+2].at<char>(row, c1);
|
434 |
pos1 = frames1Rect[2*level+2].at<unsigned short>(row, c1);
|
386 |
neg0 = frames1Rect[2*level+3].at<char>(row, c0);
|
435 |
neg0 = frames1Rect[2*level+3].at<unsigned short>(row, c0);
|
387 |
neg1 = frames1Rect[2*level+3].at<char>(row, c1);
|
436 |
neg1 = frames1Rect[2*level+3].at<unsigned short>(row, c1);
|
388 |
|
437 |
|
389 |
col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
438 |
col = c0 + (pos0 - neg0)/(neg1 - neg0 - pos1 + pos0);
|
390 |
q1Rect.push_back(cv::Point2f(col, row));
|
439 |
q1Rect.push_back(cv::Point2f(col, row));
|
391 |
|
440 |
|
392 |
}
|
441 |
}
|