RTAB-Map 0.25.2
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
util2d.h
1/*
2Copyright (c) 2010-2025, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef UTIL2D_H_
29#define UTIL2D_H_
30
31#include <rtabmap/core/rtabmap_core_export.h>
32
33#include <opencv2/core/core.hpp>
34#include <rtabmap/core/Transform.h>
35#include <rtabmap/core/Parameters.h>
36#include <rtabmap/core/CameraModel.h>
37#include <vector>
38
39namespace rtabmap
40{
41
50class SensorData;
51
52namespace util2d
53{
54
73float RTABMAP_CORE_EXPORT ssd(const cv::Mat & windowLeft, const cv::Mat & windowRight);
74
93float RTABMAP_CORE_EXPORT sad(const cv::Mat & windowLeft, const cv::Mat & windowRight);
94
127std::vector<cv::Point2f> RTABMAP_CORE_EXPORT calcStereoCorrespondences(
128 const cv::Mat & leftImage,
129 const cv::Mat & rightImage,
130 const std::vector<cv::Point2f> & leftCorners,
131 std::vector<unsigned char> & status,
132 cv::Size winSize = cv::Size(6,3),
133 int maxLevel = 3,
134 int iterations = 5,
135 float minDisparity = 0.0f,
136 float maxDisparity = 64.0f,
137 bool ssdApproach = true);
138
178void RTABMAP_CORE_EXPORT calcOpticalFlowPyrLKStereo( cv::InputArray _prevImg, cv::InputArray _nextImg,
179 cv::InputArray _prevPts, cv::InputOutputArray _nextPts,
180 cv::OutputArray _status, cv::OutputArray _err,
181 cv::Size winSize = cv::Size(15,3), int maxLevel = 3,
182 cv::TermCriteria criteria = cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 30, 0.01),
183 int flags = 0, double minEigThreshold = 1e-4 );
184
214cv::Mat RTABMAP_CORE_EXPORT disparityFromStereoImages(
215 const cv::Mat & leftImage,
216 const cv::Mat & rightImage,
217 const ParametersMap & parameters = ParametersMap());
218
239cv::Mat RTABMAP_CORE_EXPORT depthFromDisparity(const cv::Mat & disparity,
240 float fx, float baseline,
241 int type = CV_32FC1); // CV_32FC1 or CV_16UC1
242
265cv::Mat RTABMAP_CORE_EXPORT depthFromStereoImages(
266 const cv::Mat & leftImage,
267 const cv::Mat & rightImage,
268 const std::vector<cv::Point2f> & leftCorners,
269 float fx,
270 float baseline,
271 int flowWinSize = 9,
272 int flowMaxLevel = 4,
273 int flowIterations = 20,
274 double flowEps = 0.02);
275
300cv::Mat RTABMAP_CORE_EXPORT disparityFromStereoCorrespondences(
301 const cv::Size & disparitySize,
302 const std::vector<cv::Point2f> & leftCorners,
303 const std::vector<cv::Point2f> & rightCorners,
304 const std::vector<unsigned char> & mask);
305
328cv::Mat RTABMAP_CORE_EXPORT depthFromStereoCorrespondences(
329 const cv::Mat & leftImage,
330 const std::vector<cv::Point2f> & leftCorners,
331 const std::vector<cv::Point2f> & rightCorners,
332 const std::vector<unsigned char> & mask,
333 float fx, float baseline);
334
356cv::Mat RTABMAP_CORE_EXPORT cvtDepthFromFloat(const cv::Mat & depth32F);
357
375cv::Mat RTABMAP_CORE_EXPORT cvtDepthToFloat(const cv::Mat & depth16U);
376
402float RTABMAP_CORE_EXPORT getDepth(
403 const cv::Mat & depthImage,
404 float x, float y,
405 bool smoothing,
406 float depthErrorRatio = 0.02f, //ratio
407 bool estWithNeighborsIfNull = false);
408
425cv::Rect RTABMAP_CORE_EXPORT computeRoi(const cv::Mat & image, const std::string & roiRatios);
426
435cv::Rect RTABMAP_CORE_EXPORT computeRoi(const cv::Size & imageSize, const std::string & roiRatios);
436
445cv::Rect RTABMAP_CORE_EXPORT computeRoi(const cv::Mat & image, const std::vector<float> & roiRatios);
446
456cv::Rect RTABMAP_CORE_EXPORT computeRoi(const cv::Size & imageSize, const std::vector<float> & roiRatios);
457
// end of RoiComputation group
459
474cv::Mat RTABMAP_CORE_EXPORT decimate(const cv::Mat & image, int d);
475
504int RTABMAP_CORE_EXPORT exactDepthDecimation(
505 const cv::Mat & image,
506 const cv::Mat & depthOrRight,
507 int imageHeight,
508 int decimation,
509 int cameraCount = 1);
510
527bool RTABMAP_CORE_EXPORT decimateImages(SensorData & data, int decimation);
528
545cv::Mat RTABMAP_CORE_EXPORT interpolate(const cv::Mat & image, int factor, float depthErrorRatio = 0.02f);
546
570cv::Mat RTABMAP_CORE_EXPORT registerDepth(
571 const cv::Mat & depth,
572 const cv::Mat & depthK,
573 const cv::Size & colorSize,
574 const cv::Mat & colorK,
575 const rtabmap::Transform & transform);
576cv::Mat RTABMAP_CORE_EXPORT registerDepth(
577 const cv::Mat & depth,
578 const cv::Mat & confidence,
579 const cv::Mat & depthK,
580 const cv::Size & colorSize,
581 const cv::Mat & colorK,
582 const rtabmap::Transform & transform,
583 cv::Mat & registeredConfidence);
584
602cv::Mat RTABMAP_CORE_EXPORT fillDepthHoles(
603 const cv::Mat & depth,
604 int maximumHoleSize = 1,
605 float errorRatio = 0.02f);
606
634void RTABMAP_CORE_EXPORT fillRegisteredDepthHoles(
635 cv::Mat & depthRegistered,
636 bool vertical,
637 bool horizontal,
638 bool fillDoubleHoles = false);
639
663cv::Mat RTABMAP_CORE_EXPORT fastBilateralFiltering(
664 const cv::Mat & depth,
665 float sigmaS = 15.0f,
666 float sigmaR = 0.05f,
667 bool earlyDivision = false);
668
684void RTABMAP_CORE_EXPORT depthBleedingFiltering(
685 cv::Mat & depth,
686 float maxDepthError);
687
709cv::Mat RTABMAP_CORE_EXPORT brightnessAndContrastAuto(
710 const cv::Mat & src,
711 const cv::Mat & mask,
712 float clipLowHistPercent=0,
713 float clipHighHistPercent=0,
714 float * alphaOut = 0,
715 float * betaOut = 0);
716
735cv::Mat RTABMAP_CORE_EXPORT exposureFusion(
736 const std::vector<cv::Mat> & images);
737
754bool RTABMAP_CORE_EXPORT stereoExposureCompensation(
755 const cv::Mat & left,
756 const cv::Mat & right,
757 cv::Mat & leftOut,
758 cv::Mat & rightOut,
759 std::vector<double> * gains = 0);
760
779void RTABMAP_CORE_EXPORT HSVtoRGB( float *r, float *g, float *b, float h, float s, float v );
780
800void RTABMAP_CORE_EXPORT NMS(
801 const std::vector<cv::KeyPoint> & ptsIn,
802 const cv::Mat & descriptorsIn,
803 std::vector<cv::KeyPoint> & ptsOut,
804 cv::Mat & descriptorsOut,
805 int dist_thresh, int img_width, int img_height);
806
835std::vector<int> RTABMAP_CORE_EXPORT SSC(
836 const std::vector<cv::KeyPoint> & keypoints,
837 int maxKeypoints,
838 float tolerance,
839 int cols,
840 int rows,
841 const std::vector<int> & indx = {});
842
868bool RTABMAP_CORE_EXPORT rotateImagesUpsideUpIfNecessary(
869 CameraModel & model,
870 cv::Mat & rgb,
871 cv::Mat & depth,
872 cv::Mat & depthConfidence);
873
877bool RTABMAP_CORE_EXPORT rotateImagesUpsideUpIfNecessary(
878 CameraModel & model,
879 cv::Mat & rgb,
880 cv::Mat & depth);
881
882} // namespace util2d
883} // namespace rtabmap
884
885#endif /* UTIL2D_H_ */
Represents a pinhole camera model containing intrinsic and extrinsic parameters, used for projection,...
Definition CameraModel.h:53
Container class for all sensor data captured at a specific time.
Definition SensorData.h:97
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53
cv::Rect RTABMAP_CORE_EXPORT computeRoi(const cv::Mat &image, const std::string &roiRatios)
Computes a region of interest (ROI) in the image using string-defined ratios.
cv::Mat RTABMAP_CORE_EXPORT fastBilateralFiltering(const cv::Mat &depth, float sigmaS=15.0f, float sigmaR=0.05f, bool earlyDivision=false)
Applies a 2D fast bilateral filter to a depth image.
cv::Mat RTABMAP_CORE_EXPORT decimate(const cv::Mat &image, int d)
Downsamples an image by a given decimation factor.
cv::Mat RTABMAP_CORE_EXPORT cvtDepthToFloat(const cv::Mat &depth16U)
Converts a 16-bit unsigned depth image (in millimeters) to a 32-bit float depth image (in meters).
cv::Mat RTABMAP_CORE_EXPORT depthFromDisparity(const cv::Mat &disparity, float fx, float baseline, int type=CV_32FC1)
Converts a disparity map to a depth map using stereo camera parameters.
bool RTABMAP_CORE_EXPORT decimateImages(SensorData &data, int decimation)
Decimates the images of a frame in place, with their calibrations and features.
float RTABMAP_CORE_EXPORT ssd(const cv::Mat &windowLeft, const cv::Mat &windowRight)
Computes the Sum of Squared Differences (SSD) between two image patches.
void RTABMAP_CORE_EXPORT calcOpticalFlowPyrLKStereo(cv::InputArray _prevImg, cv::InputArray _nextImg, cv::InputArray _prevPts, cv::InputOutputArray _nextPts, cv::OutputArray _status, cv::OutputArray _err, cv::Size winSize=cv::Size(15, 3), int maxLevel=3, cv::TermCriteria criteria=cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 30, 0.01), int flags=0, double minEigThreshold=1e-4)
Computes sparse optical flow using a pyramidal Lucas-Kanade method constrained to the x-axis.
bool RTABMAP_CORE_EXPORT rotateImagesUpsideUpIfNecessary(CameraModel &model, cv::Mat &rgb, cv::Mat &depth, cv::Mat &depthConfidence)
Rotates the input RGB and depth images to make them appear upright based on the camera's roll angle.
cv::Mat RTABMAP_CORE_EXPORT registerDepth(const cv::Mat &depth, const cv::Mat &depthK, const cv::Size &colorSize, const cv::Mat &colorK, const rtabmap::Transform &transform)
Registers a depth image to a different camera frame (typically RGB).
float RTABMAP_CORE_EXPORT getDepth(const cv::Mat &depthImage, float x, float y, bool smoothing, float depthErrorRatio=0.02f, bool estWithNeighborsIfNull=false)
Retrieves a depth value from a depth image at a subpixel coordinate.
float RTABMAP_CORE_EXPORT sad(const cv::Mat &windowLeft, const cv::Mat &windowRight)
Computes the Sum of Absolute Differences (SAD) between two image patches.
cv::Mat RTABMAP_CORE_EXPORT disparityFromStereoCorrespondences(const cv::Size &disparitySize, const std::vector< cv::Point2f > &leftCorners, const std::vector< cv::Point2f > &rightCorners, const std::vector< unsigned char > &mask)
Computes a disparity map from stereo correspondences between two images.
std::vector< cv::Point2f > RTABMAP_CORE_EXPORT calcStereoCorrespondences(const cv::Mat &leftImage, const cv::Mat &rightImage, const std::vector< cv::Point2f > &leftCorners, std::vector< unsigned char > &status, cv::Size winSize=cv::Size(6, 3), int maxLevel=3, int iterations=5, float minDisparity=0.0f, float maxDisparity=64.0f, bool ssdApproach=true)
Computes stereo correspondences between left and right images using a pyramidal window-based matching...
bool RTABMAP_CORE_EXPORT stereoExposureCompensation(const cv::Mat &left, const cv::Mat &right, cv::Mat &leftOut, cv::Mat &rightOut, std::vector< double > *gains=0)
Equalizes the exposure of the left and right images of a stereo camera.
cv::Mat RTABMAP_CORE_EXPORT cvtDepthFromFloat(const cv::Mat &depth32F)
Converts a 32-bit float depth image (in meters) to a 16-bit unsigned depth image (in millimeters).
void RTABMAP_CORE_EXPORT depthBleedingFiltering(cv::Mat &depth, float maxDepthError)
Filters out depth bleeding artifacts in a depth image.
cv::Mat RTABMAP_CORE_EXPORT brightnessAndContrastAuto(const cv::Mat &src, const cv::Mat &mask, float clipLowHistPercent=0, float clipHighHistPercent=0, float *alphaOut=0, float *betaOut=0)
Automatic brightness and contrast optimization with optional histogram clipping.
std::vector< int > RTABMAP_CORE_EXPORT SSC(const std::vector< cv::KeyPoint > &keypoints, int maxKeypoints, float tolerance, int cols, int rows, const std::vector< int > &indx={})
Applies the SSC (Suppression via Square Covering) algorithm to spatially select keypoints.
cv::Mat RTABMAP_CORE_EXPORT depthFromStereoImages(const cv::Mat &leftImage, const cv::Mat &rightImage, const std::vector< cv::Point2f > &leftCorners, float fx, float baseline, int flowWinSize=9, int flowMaxLevel=4, int flowIterations=20, double flowEps=0.02)
Computes a depth map from stereo image pairs using optical flow tracking.
void RTABMAP_CORE_EXPORT NMS(const std::vector< cv::KeyPoint > &ptsIn, const cv::Mat &descriptorsIn, std::vector< cv::KeyPoint > &ptsOut, cv::Mat &descriptorsOut, int dist_thresh, int img_width, int img_height)
Applies Non-Maximum Suppression (NMS) to a set of keypoints.
void RTABMAP_CORE_EXPORT HSVtoRGB(float *r, float *g, float *b, float h, float s, float v)
Converts a color from HSV (Hue, Saturation, Value) to RGB.
cv::Mat RTABMAP_CORE_EXPORT exposureFusion(const std::vector< cv::Mat > &images)
Performs exposure fusion on a set of input images.
int RTABMAP_CORE_EXPORT exactDepthDecimation(const cv::Mat &image, const cv::Mat &depthOrRight, int imageHeight, int decimation, int cameraCount=1)
Depth (or right image) decimation for an exact decimation of an RGB-D or stereo frame.
cv::Mat RTABMAP_CORE_EXPORT disparityFromStereoImages(const cv::Mat &leftImage, const cv::Mat &rightImage, const ParametersMap &parameters=ParametersMap())
Computes the disparity map from a pair of stereo images.
cv::Mat RTABMAP_CORE_EXPORT depthFromStereoCorrespondences(const cv::Mat &leftImage, const std::vector< cv::Point2f > &leftCorners, const std::vector< cv::Point2f > &rightCorners, const std::vector< unsigned char > &mask, float fx, float baseline)
Computes a sparse depth map from corresponding stereo feature points.
cv::Mat RTABMAP_CORE_EXPORT fillDepthHoles(const cv::Mat &depth, int maximumHoleSize=1, float errorRatio=0.02f)
Fills holes in the depth image using linear interpolation.
cv::Mat RTABMAP_CORE_EXPORT interpolate(const cv::Mat &image, int factor, float depthErrorRatio=0.02f)
Upsamples a depth image using bilinear interpolation with depth consistency check.
void RTABMAP_CORE_EXPORT fillRegisteredDepthHoles(cv::Mat &depthRegistered, bool vertical, bool horizontal, bool fillDoubleHoles=false)
Fill holes in a registered depth image using linear interpolation.
std::map< std::string, std::string > ParametersMap
Parameter keys mapped to their values, as used by every configurable class (see Parameters).
Definition Parameters.h:44