Skip to content

Commit 53ea98d

Browse files
committed
dense: add a fast way to adjust the confidence based on neightbors agreement
1 parent 5f5e8e0 commit 53ea98d

File tree

7 files changed

+227
-202
lines changed

7 files changed

+227
-202
lines changed

apps/DensifyPointCloud/DensifyPointCloud.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ bool Application::Initialize(size_t argc, LPCTSTR* argv)
161161
("sample-mesh", boost::program_options::value(&OPT::fSampleMesh)->default_value(0.f), "uniformly samples points on a mesh (0 - disabled, <0 - number of points, >0 - sample density per square unit)")
162162
("fusion-mode", boost::program_options::value(&OPT::nFusionMode)->default_value(0), "depth-maps fusion mode (-2 - fuse disparity-maps, -1 - export disparity-maps only, 0 - depth-maps & fusion, 1 - export depth-maps only)")
163163
("fusion-filter", boost::program_options::value(&nFuseFilter)->default_value(2), "filter used to fuse the depth-maps (0 - merge, 1 - fuse, 2 - dense-fuse)")
164-
("postprocess-dmaps", boost::program_options::value(&nOptimize)->default_value(7), "flags used to filter the depth-maps after estimation (0 - disabled, 1 - remove-speckles, 2 - fill-gaps, 4 - adjust-filter)")
164+
("postprocess-dmaps", boost::program_options::value(&nOptimize)->default_value(0), "flags used to filter the depth-maps after estimation (0 - disabled, 1 - remove-speckles, 2 - fill-gaps, 4 - adjust-confidence)")
165165
("filter-point-cloud", boost::program_options::value(&OPT::thFilterPointCloud)->default_value(0), "filter dense point-cloud based on visibility (0 - disabled)")
166166
("export-number-views", boost::program_options::value(&OPT::nExportNumViews)->default_value(0), "export points with >= number of views (0 - disabled, <0 - save MVS project too)")
167167
("roi-border", boost::program_options::value(&OPT::fBorderROI)->default_value(0), "add a border to the region-of-interest when cropping the scene (0 - disabled, >0 - percentage, <0 - absolute)")

libs/Common/Types.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -980,24 +980,13 @@ FORCEINLINE INTTYPE Round2Int(double x) {
980980
// INTERPOLATION
981981

982982
// Linear interpolation
983-
inline float lerp(float u, float v, float x)
984-
{
985-
return u + (v - u) * x;
986-
}
987983
template<typename Type>
988984
inline Type lerp(const Type& u, const Type& v, float x)
989985
{
990986
return u + (v - u) * x;
991987
}
992988

993989
// Cubic interpolation
994-
inline float cerp(float u0, float u1, float u2, float u3, float x)
995-
{
996-
const float p((u3 - u2) - (u0 - u1));
997-
const float q((u0 - u1) - p);
998-
const float r(u2 - u0);
999-
return x * (x * (x * p + q) + r) + u1;
1000-
}
1001990
template<typename Type>
1002991
inline Type cerp(const Type& u0, const Type& u1, const Type& u2, const Type& u3, float x)
1003992
{

libs/MVS/DepthMap.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ MDEFVAR_OPTDENSE_uint32(nMinPixelsFuse, "Min Pixels Fuse", "minimum number of de
8787
MDEFVAR_OPTDENSE_uint32(nMaxPointsFuse, "Max Points Fuse", "maximum number of pixels to fuse into a single point", "1000")
8888
MDEFVAR_OPTDENSE_uint32(nMaxFuseDepth, "Max Fuse Depth", "maximum depth in fusion graph traversal", "100")
8989
MDEFVAR_OPTDENSE_uint32(nPointInsideROI, "Point Inside ROI", "consider a point shared only if inside ROI when estimating the neighbor views (0 - ignore ROI, 1 - weight more ROI points, 2 - consider only ROI points)", "1")
90-
MDEFVAR_OPTDENSE_bool(bFilterAdjust, "Filter Adjust", "adjust depth estimates during filtering", "1")
9190
MDEFVAR_OPTDENSE_bool(bAddCorners, "Add Corners", "add support points at image corners with nearest neighbor disparities", "0")
9291
MDEFVAR_OPTDENSE_bool(bInitSparse, "Init Sparse", "init depth-map only with the sparse points (no interpolation)", "1")
9392
MDEFVAR_OPTDENSE_bool(bRemoveDmaps, "Remove Dmaps", "remove depth-maps after fusion", "0")
@@ -107,7 +106,7 @@ MDEFVAR_OPTDENSE_int32(nOptimizerMaxIters, "Optimizer Max Iters", "MRF optimizer
107106
MDEFVAR_OPTDENSE_uint32(nSpeckleSize, "Speckle Size", "maximal size of a speckle (small speckles get removed)", "100")
108107
MDEFVAR_OPTDENSE_uint32(nIpolGapSize, "Interpolate Gap Size", "interpolate small gaps (left<->right, top<->bottom)", "7")
109108
MDEFVAR_OPTDENSE_int32(nIgnoreMaskLabel, "Ignore Mask Label", "label id used during ignore mask filter (<0 - disabled)", "-1")
110-
DEFVAR_OPTDENSE_uint32(nOptimize, "Optimize", "should we filter the extracted depth-maps?", "7") // see DepthFlags
109+
DEFVAR_OPTDENSE_uint32(nOptimize, "Optimize", "should we filter the extracted depth-maps?", "0") // see DepthFlags
111110
DEFVAR_OPTDENSE_uint32(nFuseFilter, "Fuse Filter", "how to fuse the depth-maps into one dense point-cloud?", "2", "0", "1") // see FuseMode
112111
MDEFVAR_OPTDENSE_uint32(nEstimateColors, "Estimate Colors", "should we estimate the colors for the dense point-cloud?", "2", "0", "1")
113112
MDEFVAR_OPTDENSE_uint32(nEstimateNormals, "Estimate Normals", "should we estimate the normals for the dense point-cloud?", "2", "0", "1")
@@ -1695,6 +1694,31 @@ bool MVS::LoadConfidenceMap(const String& fileName, ConfidenceMap& confMap)
16951694
/*----------------------------------------------------------------*/
16961695

16971696

1697+
// filter depth-map and normal-map using a confidence theshold
1698+
unsigned MVS::FilterDepthMap(DepthMap& depthMap, NormalMap& normalMap, const ConfidenceMap& confMap, float thConfidence)
1699+
{
1700+
ASSERT(!depthMap.empty());
1701+
ASSERT(normalMap.size() == depthMap.size());
1702+
ASSERT(confMap.size() == depthMap.size());
1703+
unsigned numFiltered = 0;
1704+
#ifdef DEPTHMAP_USE_OPENMP
1705+
#pragma omp parallel for reduction(+:numFiltered)
1706+
#endif
1707+
for (int r = 0; r < depthMap.rows; r++) {
1708+
for (int c = 0; c < depthMap.cols; c++) {
1709+
Depth& depth = depthMap(r, c);
1710+
if (depth <= 0)
1711+
continue;
1712+
if (confMap(r, c) < thConfidence) {
1713+
depth = 0;
1714+
normalMap(r, c) = Normal::ZERO;
1715+
++numFiltered;
1716+
}
1717+
}
1718+
}
1719+
return numFiltered;
1720+
} // FilterDepthMap
1721+
/*----------------------------------------------------------------*/
16981722

16991723
// export depth map as an image (dark - far depth, light - close depth)
17001724
Image8U3 MVS::DepthMap2Image(const DepthMap& depthMap, Depth minDepth, Depth maxDepth)

libs/MVS/DepthMap.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ DECOPT_SPACE(OPTDENSE)
8585
namespace OPTDENSE {
8686
// configuration variables
8787
enum DepthFlags {
88-
REMOVE_SPECKLES = (1 << 0),
89-
FILL_GAPS = (1 << 1),
90-
ADJUST_FILTER = (1 << 2),
91-
OPTIMIZE = (REMOVE_SPECKLES|FILL_GAPS)
88+
REMOVE_SPECKLES = (1 << 0),
89+
FILL_GAPS = (1 << 1),
90+
ADJUST_CONFIDENCE_FAST = (1 << 2),
91+
ADJUST_CONFIDENCE = (1 << 3),
92+
OPTIMIZE = (REMOVE_SPECKLES|FILL_GAPS)
9293
};
9394
enum FuseMode {
9495
FUSE_NOFILTER = 0,
@@ -111,7 +112,6 @@ extern unsigned nMinPixelsFuse;
111112
extern unsigned nMaxPointsFuse;
112113
extern unsigned nMaxFuseDepth;
113114
extern unsigned nPointInsideROI;
114-
extern bool bFilterAdjust;
115115
extern bool bAddCorners;
116116
extern bool bInitSparse;
117117
extern bool bRemoveDmaps;
@@ -516,6 +516,7 @@ MVS_API bool LoadNormalMap(const String& fileName, NormalMap& normalMap);
516516
MVS_API bool SaveConfidenceMap(const String& fileName, const ConfidenceMap& confMap);
517517
MVS_API bool LoadConfidenceMap(const String& fileName, ConfidenceMap& confMap);
518518

519+
MVS_API unsigned FilterDepthMap(DepthMap& depthMap, NormalMap& normalMap, const ConfidenceMap& confMap, float thConfidence=0.5f);
519520
MVS_API Image8U3 DepthMap2Image(const DepthMap& depthMap, Depth minDepth=FLT_MAX, Depth maxDepth=0);
520521
MVS_API bool ExportDepthMap(const String& fileName, const DepthMap& depthMap, Depth minDepth=FLT_MAX, Depth maxDepth=0);
521522
MVS_API bool ExportNormalMap(const String& fileName, const NormalMap& normalMap);

libs/MVS/PointCloud.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ typedef MVS_API TImage<Depth> DepthMap;
180180
typedef MVS_API TImage<Normal> NormalMap;
181181
typedef MVS_API TImage<float> ConfidenceMap;
182182
typedef MVS_API SEACAVE::cList<Depth,Depth,0> DepthArr;
183-
typedef MVS_API SEACAVE::cList<DepthMap,const DepthMap&,2> DepthMapArr;
184-
typedef MVS_API SEACAVE::cList<NormalMap,const NormalMap&,2> NormalMapArr;
185-
typedef MVS_API SEACAVE::cList<ConfidenceMap,const ConfidenceMap&,2> ConfidenceMapArr;
183+
typedef MVS_API CLISTDEF2IDX(DepthMap,IIndex) DepthMapArr;
184+
typedef MVS_API CLISTDEF2IDX(NormalMap,IIndex) NormalMapArr;
185+
typedef MVS_API CLISTDEF2IDX(ConfidenceMap,IIndex) ConfidenceMapArr;
186186
/*----------------------------------------------------------------*/
187187

188188
} // namespace MVS

0 commit comments

Comments
 (0)