From 76c5bfd324525025708a373ce8dd3d3fcaa65cb4 Mon Sep 17 00:00:00 2001 From: Zach Thorson Date: Tue, 3 Aug 2021 12:45:05 -0500 Subject: [PATCH] Update blend in tiling to match mosaicing method --- modules/realm_stages/src/mosaicing.cpp | 5 +---- modules/realm_stages/src/tileing.cpp | 27 +++++++++----------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/modules/realm_stages/src/mosaicing.cpp b/modules/realm_stages/src/mosaicing.cpp index ff623ce..19ce0c9 100644 --- a/modules/realm_stages/src/mosaicing.cpp +++ b/modules/realm_stages/src/mosaicing.cpp @@ -173,10 +173,7 @@ CvGridMap Mosaicing::blend(CvGridMap::Overlap *overlap) CvGridMap ref = *overlap->first; CvGridMap src = *overlap->second; - cv::Mat ref_not_elevated; - cv::bitwise_not(ref["elevated"], ref_not_elevated); - - // There are aparently a number of issues with NaN comparisons breaking in various ways. See: + // There are apparently a number of issues with NaN comparisons breaking in various ways. See: // https://github.com/opencv/opencv/issues/16465 // To avoid these, use patchNaNs before using boolean comparisons cv::patchNaNs(ref["elevation_angle"],0); diff --git a/modules/realm_stages/src/tileing.cpp b/modules/realm_stages/src/tileing.cpp index cd0c4e1..a46b16c 100644 --- a/modules/realm_stages/src/tileing.cpp +++ b/modules/realm_stages/src/tileing.cpp @@ -259,24 +259,15 @@ Tile::Ptr Tileing::blend(const Tile::Ptr &t1, const Tile::Ptr &t2) CvGridMap::Ptr& src = t2->data(); CvGridMap::Ptr& dst = t1->data(); - // Cells in the elevation, which have no value are marked as NaN. Therefore v == v returns false for those. - cv::Mat src_mask = ((*src)["elevation"] == (*src)["elevation"]); - - // Find all the cells, that are better in the destination tile - // First get all elements in the destination tile, that are not elevated (have an elevation, but were not 3D reconstructed) - cv::Mat dst_not_elevated; - cv::bitwise_not((*dst)["elevated"], dst_not_elevated); - - // Now remove all cells from the source tile, that have a smaller elevation angle than the destination, except those - // that are elevated where the destination is not. - cv::Mat dst_mask = ((*src)["elevation_angle"] < (*dst)["elevation_angle"]) | ((*src)["elevated"] & dst_not_elevated); - - // Now remove them - src_mask.setTo(0, dst_mask); - - (*src)["color_rgb"].copyTo((*dst)["color_rgb"], src_mask); - (*src)["elevation"].copyTo((*dst)["elevation"], src_mask); - (*src)["elevation_angle"].copyTo((*dst)["elevation_angle"], src_mask); + // There are apparently a number of issues with NaN comparisons breaking in various ways. See: + // https://github.com/opencv/opencv/issues/16465 + // To avoid these, use patchNaNs before using boolean comparisons + cv::patchNaNs((*dst)["elevation_angle"],0); + cv::Mat dst_mask = ((*src)["elevation_angle"] > (*dst)["elevation_angle"]);// | ((*src)["elevated"] & dst_not_elevated)); + + (*src)["color_rgb"].copyTo((*dst)["color_rgb"], dst_mask); + (*src)["elevation"].copyTo((*dst)["elevation"], dst_mask); + (*src)["elevation_angle"].copyTo((*dst)["elevation_angle"], dst_mask); return t1; }