From 2dec7db272618d1a87ffdc8c0382d59d3fe7ebf3 Mon Sep 17 00:00:00 2001 From: Philippe Retornaz Date: Tue, 3 Mar 2020 18:59:46 -0800 Subject: [PATCH] texture_view: fix validity mask computation Some camera distortion end up with the middle of the frame being black. We need to look for black pixels also from the middle in addition to the corners. --- libs/tex/texture_view.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/tex/texture_view.cpp b/libs/tex/texture_view.cpp index 067cb490..a450fe95 100644 --- a/libs/tex/texture_view.cpp +++ b/libs/tex/texture_view.cpp @@ -57,6 +57,17 @@ TextureView::generate_validity_mask(void) { queue.push_back(math::Vec2i(width - 1, height - 1)); checked->at(width - 1, height - 1, 0) = 255; + /* Some undistorted images will be non-black at the corners + * but black in the middle of the frame. */ + queue.push_back(math::Vec2i(0, height / 2)); + checked->at(0, height/2, 0) = 255; + queue.push_back(math::Vec2i(width - 1, height / 2)); + checked->at(width - 1, height/2, 0) = 255; + queue.push_back(math::Vec2i(width / 2, 0)); + checked->at(width / 2, 0, 0) = 255; + queue.push_back(math::Vec2i(width / 2, height - 1)); + checked->at(width / 2, height - 1, 0) = 255; + while (!queue.empty()) { math::Vec2i pixel = queue.front(); queue.pop_front();