Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5ed1b73
create dummy unworked classes
Feb 24, 2021
14df9f4
dummy class works
Feb 25, 2021
4abffa4
colored kinfu demo minor changes
Feb 25, 2021
5346fb6
add simple rgb reader and writer
Feb 26, 2021
9eab94e
add rgb info to tsdf
Feb 26, 2021
b2d2e68
add new raycast
Mar 1, 2021
60347a7
replace TsdfVoxel with RGBTsdfVoxel; integrate done
Mar 1, 2021
db691f5
add colors info to raycast
Mar 2, 2021
7744de2
just render colors
Mar 2, 2021
b9f4f85
color processing fix
Mar 2, 2021
a800eb8
intergrate color fix
Mar 3, 2021
3a4934d
add simple shift; minor fixes
Mar 4, 2021
aea0de9
add cv_errors for not implemented functions
Mar 4, 2021
e04a6ef
minor fixes
Mar 4, 2021
e7b70d5
made calibration
Mar 5, 2021
a1290c7
makeColoredFrameFromDepth works
Mar 5, 2021
0479f0e
remove comments
Mar 5, 2021
bd6bb45
makeColoredFrameFromDepth fix
Mar 9, 2021
748d8c3
RGBSoure remove extra code
Mar 9, 2021
a47372b
RGBSoure remove extra code 1
Mar 9, 2021
a2c223d
simple fix of bug with rgb size
Mar 10, 2021
7e55474
minor fix
Mar 10, 2021
baaeb77
docs fix
Mar 10, 2021
07edbc5
docs fix
Mar 10, 2021
bcaefe5
unused parameter fix
Mar 10, 2021
68e9c42
warnings fix
Mar 11, 2021
4997b87
fix tsdf errors; rgbd_perf warnings
Mar 11, 2021
71056f2
fix errors
Mar 11, 2021
d2832fa
minor fix
Mar 11, 2021
c8f9659
debug print
Mar 11, 2021
7fa4a6a
debug print 2
Mar 11, 2021
e895ef7
debug print 3
Mar 11, 2021
92e4050
invoker fix
Mar 11, 2021
2e78bee
minor fix
Mar 11, 2021
63821a5
remove debug cout
Mar 11, 2021
a1ed445
add simple tests
Mar 12, 2021
e74a154
docs fix
Mar 12, 2021
67658db
warnings fix
Mar 12, 2021
cf20c8e
minor fix
Mar 12, 2021
1cf0643
function warning fix
Mar 12, 2021
5eeeef2
add vectorized code
Mar 15, 2021
59e60c2
minor fixes
Mar 15, 2021
21666b7
minor speed up
Mar 15, 2021
53eeb47
minor fixes; renaming
Mar 17, 2021
ecd8bd5
new minor fixes
Mar 17, 2021
2988841
Merge branch 'master' into colored_kinfu
DumDereDum Apr 2, 2021
8b24c41
bug fix
Apr 2, 2021
7eb69d5
Merge branch 'master' of https://github.com/opencv/opencv_contrib int…
Apr 2, 2021
20443bd
minor fix
Apr 2, 2021
5a2f485
test update
Apr 5, 2021
d1e5f3b
extra code removed
Apr 5, 2021
32cae64
bugfix; warning fix
Apr 5, 2021
0fadae2
simple interpolation
Apr 5, 2021
9b030ea
minor fix
Apr 5, 2021
bc4be41
color work minor fix
Apr 6, 2021
ba9e2fd
vectorized interpolation
Apr 6, 2021
8f40b48
minor fix
Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/rgbd/include/opencv2/rgbd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "opencv2/rgbd/dynafu.hpp"
#include "opencv2/rgbd/large_kinfu.hpp"
#include "opencv2/rgbd/detail/pose_graph.hpp"
#include "opencv2/rgbd/colored_kinfu.hpp"


/** @defgroup rgbd RGB-Depth Processing
Expand Down
261 changes: 261 additions & 0 deletions modules/rgbd/include/opencv2/rgbd/colored_kinfu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory

#ifndef __OPENCV_RGBD_COLORED_KINFU_HPP__
#define __OPENCV_RGBD_COLORED_KINFU_HPP__

#include "opencv2/core.hpp"
#include "opencv2/core/affine.hpp"
#include <opencv2/rgbd/volume.hpp>

namespace cv {
namespace colored_kinfu {
//! @addtogroup kinect_fusion
//! @{

struct CV_EXPORTS_W Params
{

CV_WRAP Params(){}

/**
* @brief Constructor for Params
* Sets the initial pose of the TSDF volume.
* @param volumeInitialPoseRot rotation matrix
* @param volumeInitialPoseTransl translation vector
*/
CV_WRAP Params(Matx33f volumeInitialPoseRot, Vec3f volumeInitialPoseTransl)
{
setInitialVolumePose(volumeInitialPoseRot,volumeInitialPoseTransl);
}

/**
* @brief Constructor for Params
* Sets the initial pose of the TSDF volume.
* @param volumeInitialPose 4 by 4 Homogeneous Transform matrix to set the intial pose of TSDF volume
*/
CV_WRAP Params(Matx44f volumeInitialPose)
{
setInitialVolumePose(volumeInitialPose);
}

/**
* @brief Set Initial Volume Pose
* Sets the initial pose of the TSDF volume.
* @param R rotation matrix
* @param t translation vector
*/
CV_WRAP void setInitialVolumePose(Matx33f R, Vec3f t);

/**
* @brief Set Initial Volume Pose
* Sets the initial pose of the TSDF volume.
* @param homogen_tf 4 by 4 Homogeneous Transform matrix to set the intial pose of TSDF volume
*/
CV_WRAP void setInitialVolumePose(Matx44f homogen_tf);

/**
* @brief Default parameters
* A set of parameters which provides better model quality, can be very slow.
*/
CV_WRAP static Ptr<Params> defaultParams();

/** @brief Coarse parameters
A set of parameters which provides better speed, can fail to match frames
in case of rapid sensor motion.
*/
CV_WRAP static Ptr<Params> coarseParams();

/** @brief HashTSDF parameters
A set of parameters suitable for use with HashTSDFVolume
*/
CV_WRAP static Ptr<Params> hashTSDFParams(bool isCoarse);

/** @brief ColoredTSDF parameters
A set of parameters suitable for use with HashTSDFVolume
*/
CV_WRAP static Ptr<Params> coloredTSDFParams(bool isCoarse);

/** @brief frame size in pixels */
CV_PROP_RW Size frameSize;

/** @brief rgb frame size in pixels */
CV_PROP_RW Size rgb_frameSize;

CV_PROP_RW kinfu::VolumeType volumeType;

/** @brief camera intrinsics */
CV_PROP_RW Matx33f intr;

/** @brief rgb camera intrinsics */
CV_PROP_RW Matx33f rgb_intr;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add info about values

/** @brief pre-scale per 1 meter for input values

Typical values are:
* 5000 per 1 meter for the 16-bit PNG files of TUM database
* 1000 per 1 meter for Kinect 2 device
* 1 per 1 meter for the 32-bit float images in the ROS bag files
*/
CV_PROP_RW float depthFactor;

/** @brief Depth sigma in meters for bilateral smooth */
CV_PROP_RW float bilateral_sigma_depth;
/** @brief Spatial sigma in pixels for bilateral smooth */
CV_PROP_RW float bilateral_sigma_spatial;
/** @brief Kernel size in pixels for bilateral smooth */
CV_PROP_RW int bilateral_kernel_size;

/** @brief Number of pyramid levels for ICP */
CV_PROP_RW int pyramidLevels;

/** @brief Resolution of voxel space

Number of voxels in each dimension.
*/
CV_PROP_RW Vec3i volumeDims;
/** @brief Size of voxel in meters */
CV_PROP_RW float voxelSize;

/** @brief Minimal camera movement in meters

Integrate new depth frame only if camera movement exceeds this value.
*/
CV_PROP_RW float tsdf_min_camera_movement;

/** @brief initial volume pose in meters */
Affine3f volumePose;

/** @brief distance to truncate in meters

Distances to surface that exceed this value will be truncated to 1.0.
*/
CV_PROP_RW float tsdf_trunc_dist;

/** @brief max number of frames per voxel

Each voxel keeps running average of distances no longer than this value.
*/
CV_PROP_RW int tsdf_max_weight;

/** @brief A length of one raycast step

How much voxel sizes we skip each raycast step
*/
CV_PROP_RW float raycast_step_factor;

// gradient delta in voxel sizes
// fixed at 1.0f
// float gradient_delta_factor;

/** @brief light pose for rendering in meters */
CV_PROP_RW Vec3f lightPose;

/** @brief distance theshold for ICP in meters */
CV_PROP_RW float icpDistThresh;
/** angle threshold for ICP in radians */
CV_PROP_RW float icpAngleThresh;
/** number of ICP iterations for each pyramid level */
CV_PROP_RW std::vector<int> icpIterations;

/** @brief Threshold for depth truncation in meters

All depth values beyond this threshold will be set to zero
*/
CV_PROP_RW float truncateThreshold;
};

/** @brief KinectFusion implementation

This class implements a 3d reconstruction algorithm described in
@cite kinectfusion paper.

It takes a sequence of depth images taken from depth sensor
(or any depth images source such as stereo camera matching algorithm or even raymarching renderer).
The output can be obtained as a vector of points and their normals
or can be Phong-rendered from given camera pose.

An internal representation of a model is a voxel cuboid that keeps TSDF values
which are a sort of distances to the surface (for details read the @cite kinectfusion article about TSDF).
There is no interface to that representation yet.

KinFu uses OpenCL acceleration automatically if available.
To enable or disable it explicitly use cv::setUseOptimized() or cv::ocl::setUseOpenCL().

This implementation is based on [kinfu-remake](https://github.com/Nerei/kinfu_remake).

Note that the KinectFusion algorithm was patented and its use may be restricted by
the list of patents mentioned in README.md file in this module directory.

That's why you need to set the OPENCV_ENABLE_NONFREE option in CMake to use KinectFusion.
*/
class CV_EXPORTS_W ColoredKinFu
{
public:
CV_WRAP static Ptr<ColoredKinFu> create(const Ptr<Params>& _params);
virtual ~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
@param cameraPose pose of camera to render from. If empty then render from current pose
which is a last frame camera pose.
*/

CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0;

/** @brief Gets points and normals of current 3d mesh

The order of normals corresponds to order of points.
The order of points is undefined.

@param points vector of points which are 4-float vectors
@param normals vector of normals which are 4-float vectors
*/
CV_WRAP virtual void getCloud(OutputArray points, OutputArray normals) const = 0;

/** @brief Gets points of current 3d mesh

The order of points is undefined.

@param points vector of points which are 4-float vectors
*/
CV_WRAP virtual void getPoints(OutputArray points) const = 0;

/** @brief Calculates normals for given points
@param points input vector of points which are 4-float vectors
@param normals output vector of corresponding normals which are 4-float vectors
*/
CV_WRAP virtual void getNormals(InputArray points, OutputArray normals) const = 0;

/** @brief Resets the algorithm

Clears current model and resets a pose.
*/
CV_WRAP virtual void reset() = 0;

/** @brief Get current pose in voxel space */
virtual const Affine3f getPose() const = 0;

/** @brief Process next depth frame
@param depth input Mat of depth frame
@param rgb input Mat of rgb (colored) frame

@return true if succeeded to align new frame with current scene, false if opposite
*/
CV_WRAP virtual bool update(InputArray depth, InputArray rgb) = 0;
};

//! @}
}
}
#endif
8 changes: 8 additions & 0 deletions modules/rgbd/include/opencv2/rgbd/kinfu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ struct CV_EXPORTS_W Params
*/
CV_WRAP static Ptr<Params> hashTSDFParams(bool isCoarse);

/** @brief ColoredTSDF parameters
A set of parameters suitable for use with ColoredTSDFVolume
*/
CV_WRAP static Ptr<Params> coloredTSDFParams(bool isCoarse);

/** @brief frame size in pixels */
CV_PROP_RW Size frameSize;

/** @brief rgb frame size in pixels */
CV_PROP_RW kinfu::VolumeType volumeType;

/** @brief camera intrinsics */
CV_PROP_RW Matx33f intr;

/** @brief rgb camera intrinsics */
CV_PROP_RW Matx33f rgb_intr;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add info about value

/** @brief pre-scale per 1 meter for input values

Typical values are:
Expand Down
3 changes: 3 additions & 0 deletions modules/rgbd/include/opencv2/rgbd/large_kinfu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct CV_EXPORTS_W Params
/** @brief camera intrinsics */
CV_PROP_RW Matx33f intr;

/** @brief rgb camera intrinsics */
CV_PROP_RW Matx33f rgb_intr;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add info about value


/** @brief pre-scale per 1 meter for input values
Typical values are:
* 5000 per 1 meter for the 16-bit PNG files of TUM database
Expand Down
10 changes: 8 additions & 2 deletions modules/rgbd/include/opencv2/rgbd/volume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ class CV_EXPORTS_W Volume

virtual void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose,
const kinfu::Intr& intrinsics, const int frameId = 0) = 0;
virtual void integrate(InputArray _depth, InputArray _rgb, float depthFactor,
const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
const Intr& rgb_intrinsics, const int frameId = 0) = 0;
virtual void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
const Size& frameSize, OutputArray points, OutputArray normals) const = 0;
virtual void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize,
OutputArray points, OutputArray normals, OutputArray colors) const = 0;
virtual void fetchNormals(InputArray points, OutputArray _normals) const = 0;
virtual void fetchPointsNormals(OutputArray points, OutputArray normals) const = 0;
virtual void reset() = 0;
Expand All @@ -45,8 +50,9 @@ class CV_EXPORTS_W Volume

enum class VolumeType
{
TSDF = 0,
HASHTSDF = 1
TSDF = 0,
HASHTSDF = 1,
COLOREDTSDF = 2
};

struct CV_EXPORTS_W VolumeParams
Expand Down
2 changes: 2 additions & 0 deletions modules/rgbd/perf/perf_tsdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ PERF_TEST(Perf_TSDF, integrate)
startTimer();
settings.volume->integrate(depth, settings._params->depthFactor, pose, settings._params->intr);
stopTimer();
depth.release();
}
SANITY_CHECK_NOTHING();
}
Expand Down Expand Up @@ -358,6 +359,7 @@ PERF_TEST(Perf_HashTSDF, integrate)
startTimer();
settings.volume->integrate(depth, settings._params->depthFactor, pose, settings._params->intr);
stopTimer();
depth.release();
}
SANITY_CHECK_NOTHING();
}
Expand Down
Loading