From 46ff164e15b2d9c7b6e225f8d8b6302a99daa83d Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Fri, 17 Jul 2020 15:37:22 +0200 Subject: [PATCH] update holefilling with 1st non null neighbour --- app/SandboxSetup/croppingmask.cpp | 2 +- inc/projection.h | 5 ++++- src/components/projection.cpp | 26 +++++++++----------------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 11f0af1..71b138c 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -87,7 +87,7 @@ void CroppingMask::init(){ } // no config found - if(rectPoints.empty() || !maskValideInFrame(&cameraColoredFrame)){ + if(!maskValideInFrame(&cameraColoredFrame)){ float y = cameraColoredFrame.size().height; float x = cameraColoredFrame.size().width; rectPoints = std::vector<cv::Point2i>{ cv::Point2i(1.0/4*x, 1.0/4*y), cv::Point2i(1.0/4*x, 3.0/4*y), cv::Point2i(3.0/4*x, 3.0/4*y), cv::Point2i(3.0/4*x, 1.0/4*y) }; diff --git a/inc/projection.h b/inc/projection.h index 8e02ba3..f088b89 100644 --- a/inc/projection.h +++ b/inc/projection.h @@ -10,13 +10,16 @@ class Projection{ cv::Mat_<float> adjustingMatrix; float distanceTopSandbox; + // resized depth frame to dst resolution cv::Mat_<float> resized_depth; + // resized src to project to dst resolution cv::Mat_<cv::Vec3b> resized_src; // Buffer containing the pixels's new location when deprojected to beamer's POV cv::Mat_<cv::Point2i> deprojectMap; - // Buffer indicating from where to get the pixels in the source frame + // Buffer indicating from where to get the pixels in the source frame to build the output cv::Mat_<cv::Point2i> frameMap; + // intrinsics parameters for deprojection, which are adapted to projection's resolution cv::Point2f fxy; cv::Point2f ppxy; diff --git a/src/components/projection.cpp b/src/components/projection.cpp index 95dad2c..196dd55 100644 --- a/src/components/projection.cpp +++ b/src/components/projection.cpp @@ -172,7 +172,7 @@ void Projection::buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frame } /* - average of non null neighbours + fill with value of the 1st non null neighbour */ void Projection::holeFilling(cv::Mat_<cv::Vec3b> &dst, cv::Mat_<cv::Point2i> &frameMap){ @@ -181,34 +181,26 @@ void Projection::holeFilling(cv::Mat_<cv::Vec3b> &dst, cv::Mat_<cv::Point2i> &fr if(frameMap.at<cv::Point2i>(i,j) == cv::Point2i(-1,-1)){ - int cpt = 0; - int r = 0; - int g = 0; - int b = 0; + cv::Vec3b color; + bool found = false; - for(int d_y = -1; d_y <= 1; d_y++){ - for(int d_x = -1; d_x <= 1; d_x++){ + for(int d_y = -1; d_y <= 1 && !found; d_y++){ + for(int d_x = -1; d_x <= 1 && !found; d_x++){ if(!(d_x == 0 && d_y == 0)){ int y = i+d_y; int x = j+d_x; if( ((0 <= x && x < dst.cols) && (0 <= y && y < dst.rows)) && (frameMap.at<cv::Point2i>(y,x) != cv::Point2i(-1,-1)) ){ - cv::Vec3b color = dst.at<cv::Vec3b>(y,x); - r += color[0]; - g += color[1]; - b += color[2]; - cpt++; + color = dst.at<cv::Vec3b>(y,x); + found = true; } } } } - if(cpt > 0){ - r /= cpt; - g /= cpt; - b /= cpt; - dst.at<cv::Vec3b>(i,j) = cv::Vec3b(r,g,b); + if(found){ + dst.at<cv::Vec3b>(i,j) = color; } } } -- GitLab