You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reintroduce GrayCodePattern::getProjPixel to allow for tests to pass, fixup NaN values in projector mapping
This commit reintroduces a faster and improved version of getProjPixel to allow for tests that relied on it to pass, and it also fixes an issue with NaN values appearing in projector mapping when a pixel wasn't seen by either one of the cameras.
/** @brief For a (x,y) pixel of a camera returns the corresponding projector pixel.
133
+
*
134
+
* The function decodes each pixel in the pattern images acquired by a camera into their corresponding decimal numbers representing the projector's column and row,
135
+
* providing a mapping between camera's and projector's pixel.
136
+
*
137
+
* @param patternImages The pattern images acquired by the camera, stored in a grayscale vector < Mat >.
138
+
* @param x x coordinate of the image pixel.
139
+
* @param y y coordinate of the image pixel.
140
+
* @param projPix Projector's pixel corresponding to the camera's pixel: projPix.x and projPix.y are the image coordinates of the projector's pixel corresponding to the pixel being decoded in a camera.
141
+
*/
142
+
CV_WRAP
143
+
virtualboolgetProjPixel(InputArrayOfArrays patternImages, int x, int y, CV_OUT Point& projPix) const = 0;
auto decode_pixel = [&](auto dummy_type_ptr) -> bool
383
+
{
384
+
using T = typename std::remove_pointer<decltype(dummy_type_ptr)>::type;
385
+
bool error = false;
386
+
387
+
for (size_t k = 0; k < numOfColImgs; ++k)
388
+
{
389
+
T val1 = patternImagesVec[k * 2].at<T>(y, x);
390
+
T val2 = patternImagesVec[k * 2 + 1].at<T>(y, x);
391
+
392
+
if (std::abs(static_cast<double>(val1) - static_cast<double>(val2)) < whiteThreshold)
393
+
{
394
+
error = true;
395
+
}
396
+
grayCol[k] = (val1 > val2);
397
+
}
398
+
399
+
size_t base_idx = 2 * numOfColImgs;
400
+
for (size_t k = 0; k < numOfRowImgs; ++k)
401
+
{
402
+
T val1 = patternImagesVec[base_idx + k * 2].at<T>(y, x);
403
+
T val2 = patternImagesVec[base_idx + k * 2 + 1].at<T>(y, x);
404
+
405
+
if (std::abs(static_cast<double>(val1) - static_cast<double>(val2)) < whiteThreshold)
406
+
{
407
+
error = true;
408
+
}
409
+
grayRow[k] = (val1 > val2);
410
+
}
411
+
return error;
412
+
};
413
+
414
+
bool error = false;
415
+
int depth = patternImagesVec[0].depth();
416
+
417
+
switch (depth)
418
+
{
419
+
case CV_8U:
420
+
error = decode_pixel((uchar*)nullptr);
421
+
break;
422
+
case CV_16U:
423
+
error = decode_pixel((ushort*)nullptr);
424
+
break;
425
+
default:
426
+
CV_Error(Error::StsUnsupportedFormat, "Image depth not supported, only CV_8U and CV_16U");
427
+
}
428
+
429
+
int xDec = grayToDec(grayCol);
430
+
int yDec = grayToDec(grayRow);
431
+
432
+
if (yDec >= params.height || xDec >= params.width)
433
+
{
434
+
error = true;
435
+
}
436
+
437
+
projPix.x = xDec;
438
+
projPix.y = yDec;
439
+
440
+
return error;
441
+
}
442
+
443
+
356
444
// For a (x,y) pixel of the camera returns the corresponding projector's pixel
357
445
boolGrayCodePattern_Impl::getProjPixelFast( const std::vector<Mat>& fastColImages, const std::vector<Mat>& fastRowImages, int x, int y, Point &projPix) const
0 commit comments