From fd37dc59661855853a5f2cd1b9d5a5d463364b19 Mon Sep 17 00:00:00 2001 From: arsaratovtsev Date: Thu, 15 Apr 2021 14:56:43 +0300 Subject: [PATCH 1/4] add TODO --- modules/rgbd/include/opencv2/rgbd/kinfu.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp index 924314eddbe..3057faff703 100644 --- a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp @@ -209,7 +209,7 @@ class CV_EXPORTS_W KinFu */ CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0; - + //TODO: rewrite render() for 1 and 2 args, like update()/updateT() /** @brief Gets points and normals of current 3d mesh The order of normals corresponds to order of points. From 450daa80a3c7cd61d7ef2591f2a0c38f6cff77bf Mon Sep 17 00:00:00 2001 From: arsaratovtsev Date: Thu, 15 Apr 2021 17:28:27 +0300 Subject: [PATCH 2/4] rewrite render --- .../include/opencv2/rgbd/colored_kinfu.hpp | 12 +++++++- modules/rgbd/include/opencv2/rgbd/kinfu.hpp | 12 +++++++- .../rgbd/include/opencv2/rgbd/large_kinfu.hpp | 4 +-- modules/rgbd/src/colored_kinfu.cpp | 26 ++++++++-------- modules/rgbd/src/kinfu.cpp | 27 ++++++++--------- modules/rgbd/src/large_kinfu.cpp | 30 ++++++++++--------- 6 files changed, 65 insertions(+), 46 deletions(-) diff --git a/modules/rgbd/include/opencv2/rgbd/colored_kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/colored_kinfu.hpp index 427f830b972..861b9db2ed7 100644 --- a/modules/rgbd/include/opencv2/rgbd/colored_kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/colored_kinfu.hpp @@ -201,6 +201,16 @@ class CV_EXPORTS_W ColoredKinFu /** @brief Get current parameters */ virtual const Params& getParams() const = 0; + /** @brief Renders a volume into an image + + Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. + Light pose is fixed in KinFu params. + + @param image resulting image + */ + + CV_WRAP virtual void render(OutputArray image) const = 0; + /** @brief Renders a volume into an image Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. @@ -211,7 +221,7 @@ class CV_EXPORTS_W ColoredKinFu which is a last frame camera pose. */ - CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0; + CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose) const = 0; /** @brief Gets points and normals of current 3d mesh diff --git a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp index 3057faff703..5e5145823ff 100644 --- a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp @@ -198,6 +198,16 @@ class CV_EXPORTS_W KinFu /** @brief Get current parameters */ virtual const Params& getParams() const = 0; + /** @brief Renders a volume into an image + + Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. + Light pose is fixed in KinFu params. + + @param image resulting image + */ + + CV_WRAP virtual void render(OutputArray image) const = 0; + /** @brief Renders a volume into an image Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. @@ -208,7 +218,7 @@ class CV_EXPORTS_W KinFu which is a last frame camera pose. */ - CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0; + CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose) const = 0; //TODO: rewrite render() for 1 and 2 args, like update()/updateT() /** @brief Gets points and normals of current 3d mesh diff --git a/modules/rgbd/include/opencv2/rgbd/large_kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/large_kinfu.hpp index 2f2d510e8e5..a7a0b7adc83 100644 --- a/modules/rgbd/include/opencv2/rgbd/large_kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/large_kinfu.hpp @@ -125,8 +125,8 @@ class CV_EXPORTS_W LargeKinfu virtual const Params& getParams() const = 0; - CV_WRAP virtual void render(OutputArray image, - const Matx44f& cameraPose = Matx44f::eye()) const = 0; + CV_WRAP virtual void render(OutputArray image) const = 0; + CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose) const = 0; CV_WRAP virtual void getCloud(OutputArray points, OutputArray normals) const = 0; diff --git a/modules/rgbd/src/colored_kinfu.cpp b/modules/rgbd/src/colored_kinfu.cpp index dc87be6b39a..8205596d632 100644 --- a/modules/rgbd/src/colored_kinfu.cpp +++ b/modules/rgbd/src/colored_kinfu.cpp @@ -141,6 +141,7 @@ class ColoredKinFuImpl : public ColoredKinFu const Params& getParams() const CV_OVERRIDE; + void render(OutputArray image) const CV_OVERRIDE; void render(OutputArray image, const Matx44f& cameraPose) const CV_OVERRIDE; virtual void getCloud(OutputArray points, OutputArray normals) const CV_OVERRIDE; @@ -322,26 +323,23 @@ bool ColoredKinFuImpl::updateT(const MatType& _depth, const MatType& _r } +template< typename MatType > +void ColoredKinFuImpl::render(OutputArray image) const +{ + CV_TRACE_FUNCTION(); + + renderPointsNormalsColors(pyrPoints[0], pyrNormals[0], pyrColors[0],image, params.lightPose); +} + template< typename MatType > void ColoredKinFuImpl::render(OutputArray image, const Matx44f& _cameraPose) const { CV_TRACE_FUNCTION(); Affine3f cameraPose(_cameraPose); - Affine3f _pose(pose); - - const Affine3f id = Affine3f::Identity(); - if((cameraPose.rotation() == _pose.rotation() && cameraPose.translation() == _pose.translation()) || - (cameraPose.rotation() == id.rotation() && cameraPose.translation() == id.translation())) - { - renderPointsNormalsColors(pyrPoints[0], pyrNormals[0], pyrColors[0],image, params.lightPose); - } - else - { - MatType points, normals, colors; - volume->raycast(_cameraPose, params.intr, params.frameSize, points, normals, colors); - renderPointsNormalsColors(points, normals, colors, image, params.lightPose); - } + MatType points, normals, colors; + volume->raycast(_cameraPose, params.intr, params.frameSize, points, normals, colors); + renderPointsNormalsColors(points, normals, colors, image, params.lightPose); } diff --git a/modules/rgbd/src/kinfu.cpp b/modules/rgbd/src/kinfu.cpp index 7f9f1b32361..4ba73aabc71 100644 --- a/modules/rgbd/src/kinfu.cpp +++ b/modules/rgbd/src/kinfu.cpp @@ -129,6 +129,7 @@ class KinFuImpl : public KinFu const Params& getParams() const CV_OVERRIDE; + void render(OutputArray image) const CV_OVERRIDE; void render(OutputArray image, const Matx44f& cameraPose) const CV_OVERRIDE; virtual void getCloud(OutputArray points, OutputArray normals) const CV_OVERRIDE; @@ -284,26 +285,24 @@ bool KinFuImpl::updateT(const MatType& _depth) } +template< typename MatType > +void KinFuImpl::render(OutputArray image) const +{ + CV_TRACE_FUNCTION(); + + renderPointsNormals(pyrPoints[0], pyrNormals[0], image, params.lightPose); +} + + template< typename MatType > void KinFuImpl::render(OutputArray image, const Matx44f& _cameraPose) const { CV_TRACE_FUNCTION(); Affine3f cameraPose(_cameraPose); - Affine3f _pose(pose); - - const Affine3f id = Affine3f::Identity(); - if((cameraPose.rotation() == _pose.rotation() && cameraPose.translation() == _pose.translation()) || - (cameraPose.rotation() == id.rotation() && cameraPose.translation() == id.translation())) - { - renderPointsNormals(pyrPoints[0], pyrNormals[0], image, params.lightPose); - } - else - { - MatType points, normals; - volume->raycast(_cameraPose, params.intr, params.frameSize, points, normals); - renderPointsNormals(points, normals, image, params.lightPose); - } + MatType points, normals; + volume->raycast(_cameraPose, params.intr, params.frameSize, points, normals); + renderPointsNormals(points, normals, image, params.lightPose); } diff --git a/modules/rgbd/src/large_kinfu.cpp b/modules/rgbd/src/large_kinfu.cpp index 8babd45fd60..aae042cb0ab 100644 --- a/modules/rgbd/src/large_kinfu.cpp +++ b/modules/rgbd/src/large_kinfu.cpp @@ -112,6 +112,7 @@ class LargeKinfuImpl : public LargeKinfu const Params& getParams() const CV_OVERRIDE; + void render(OutputArray image) const CV_OVERRIDE; void render(OutputArray image, const Matx44f& cameraPose) const CV_OVERRIDE; virtual void getCloud(OutputArray points, OutputArray normals) const CV_OVERRIDE; @@ -296,29 +297,30 @@ bool LargeKinfuImpl::updateT(const MatType& _depth) return true; } + +template +void LargeKinfuImpl::render(OutputArray image) const +{ + CV_TRACE_FUNCTION(); + auto currSubmap = submapMgr->getCurrentSubmap(); + //! TODO: Can render be dependent on current submap + renderPointsNormals(currSubmap->pyrPoints[0], currSubmap->pyrNormals[0], image, params.lightPose); +} + + template void LargeKinfuImpl::render(OutputArray image, const Matx44f& _cameraPose) const { CV_TRACE_FUNCTION(); Affine3f cameraPose(_cameraPose); - auto currSubmap = submapMgr->getCurrentSubmap(); - const Affine3f id = Affine3f::Identity(); - if ((cameraPose.rotation() == pose.rotation() && cameraPose.translation() == pose.translation()) || - (cameraPose.rotation() == id.rotation() && cameraPose.translation() == id.translation())) - { - //! TODO: Can render be dependent on current submap - renderPointsNormals(currSubmap->pyrPoints[0], currSubmap->pyrNormals[0], image, params.lightPose); - } - else - { - MatType points, normals; - currSubmap->raycast(cameraPose, params.intr, params.frameSize, points, normals); - renderPointsNormals(points, normals, image, params.lightPose); - } + MatType points, normals; + currSubmap->raycast(cameraPose, params.intr, params.frameSize, points, normals); + renderPointsNormals(points, normals, image, params.lightPose); } + template void LargeKinfuImpl::getCloud(OutputArray p, OutputArray n) const { From ddbc1503038e664757f4bc56c4409ed33fcfe096 Mon Sep 17 00:00:00 2001 From: arsaratovtsev Date: Thu, 15 Apr 2021 17:38:08 +0300 Subject: [PATCH 3/4] docs fix --- modules/rgbd/include/opencv2/rgbd/kinfu.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp index 5e5145823ff..3168a038067 100644 --- a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp @@ -207,7 +207,7 @@ class CV_EXPORTS_W KinFu */ CV_WRAP virtual void render(OutputArray image) const = 0; - + /** @brief Renders a volume into an image Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. From 8bcb2a98d1d568761614329f0595fd7f23d7401e Mon Sep 17 00:00:00 2001 From: arsaratovtsev Date: Thu, 15 Apr 2021 23:43:27 +0300 Subject: [PATCH 4/4] remove extra comment --- modules/rgbd/include/opencv2/rgbd/kinfu.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp index 3168a038067..ebc15f9bb81 100644 --- a/modules/rgbd/include/opencv2/rgbd/kinfu.hpp +++ b/modules/rgbd/include/opencv2/rgbd/kinfu.hpp @@ -219,7 +219,7 @@ class CV_EXPORTS_W KinFu */ CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose) const = 0; - //TODO: rewrite render() for 1 and 2 args, like update()/updateT() + /** @brief Gets points and normals of current 3d mesh The order of normals corresponds to order of points.