Skip to content

Commit

Permalink
transform: add option to add noise to camera poses
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Jun 26, 2024
1 parent 36ffb22 commit 9bd7ed4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
26 changes: 18 additions & 8 deletions apps/TransformScene/TransformScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ namespace OPT {
String strTransferTextureFileName;
String strIndicesFileName;
bool bComputeVolume;
float fEpsNoisePosition;
float fEpsNoiseRotation;
float fPlaneThreshold;
float fSampleMesh;
unsigned nMaxResolution;
Expand Down Expand Up @@ -117,6 +119,8 @@ bool Application::Initialize(size_t argc, LPCTSTR* argv)
("transfer-texture-file", boost::program_options::value<std::string>(&OPT::strTransferTextureFileName), "input mesh filename to which the texture of the scene's mesh will be transfered to (the two meshes should be aligned and the new mesh to have UV-map)")
("indices-file", boost::program_options::value<std::string>(&OPT::strIndicesFileName), "input indices filename to be used with ex. texture transfer to select a subset of the scene's mesh")
("compute-volume", boost::program_options::value(&OPT::bComputeVolume)->default_value(false), "compute the volume of the given watertight mesh, or else try to estimate the ground plane and assume the mesh is bounded by it")
("eps-noise-position", boost::program_options::value(&OPT::fEpsNoisePosition)->default_value(0.f), "add noise to camera positions (0 - disabled)")
("eps-noise-rotation", boost::program_options::value(&OPT::fEpsNoiseRotation)->default_value(0.f), "add noise to camera rotations (0 - disabled)")
("plane-threshold", boost::program_options::value(&OPT::fPlaneThreshold)->default_value(0.f), "threshold used to estimate the ground plane (<0 - disabled, 0 - auto, >0 - desired threshold)")
("sample-mesh", boost::program_options::value(&OPT::fSampleMesh)->default_value(-300000.f), "uniformly samples points on a mesh (0 - disabled, <0 - number of points, >0 - sample density per square unit)")
("max-resolution", boost::program_options::value(&OPT::nMaxResolution)->default_value(0), "make sure image resolution are not not larger than this (0 - disabled)")
Expand Down Expand Up @@ -229,6 +233,12 @@ int main(int argc, LPCTSTR* argv)
!OPT::strTransformFileName.empty() || !OPT::strTransferTextureFileName.empty() || OPT::bComputeVolume));
if (sceneType == Scene::SCENE_NA)
return EXIT_FAILURE;
if (OPT::fEpsNoisePosition > 0 || OPT::fEpsNoiseRotation > 0) {
scene.pointcloud.Release();
scene.AddNoiseCameraPoses(OPT::fEpsNoisePosition, FD2R(OPT::fEpsNoiseRotation));
scene.Save(MAKE_PATH_SAFE(Util::getFileFullName(OPT::strOutputFileName)) + _T(".mvs"), (ARCHIVE_TYPE)OPT::nArchiveType);
return EXIT_SUCCESS;
}
if (!OPT::strPointCloudFileName.empty() && !scene.pointcloud.Load(MAKE_PATH_SAFE(OPT::strPointCloudFileName))) {
VERBOSE("error: cannot load point-cloud file");
return EXIT_FAILURE;
Expand Down Expand Up @@ -256,14 +266,14 @@ int main(int argc, LPCTSTR* argv)
std::vector<double> transformValues;
while (file >> value) {
double v;
try {
v = std::stod(value);
}
catch (...) {
continue;
}
transformValues.push_back(v);
}
try {
v = std::stod(value);
}
catch (...) {
continue;
}
transformValues.push_back(v);
}
if (transformValues.size() != 12 &&
(transformValues.size() != 16 || transformValues[12] != 0 || transformValues[13] != 0 || transformValues[14] != 0 || transformValues[15] != 1)) {
VERBOSE("error: invalid transform");
Expand Down
18 changes: 18 additions & 0 deletions libs/MVS/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,24 @@ REAL Scene::ComputeLeveledVolume(float planeThreshold, float sampleMesh, unsigne
}
return mesh.ComputeVolume();
}

// add noise to camera poses:
// - epsPosition: noise in camera position (in scene units)
// - epsRotation: noise in camera rotation (in radians)
void Scene::AddNoiseCameraPoses(float epsPosition, float epsRotation)
{
for (Platform& platform: platforms) {
for (Platform::Pose& pose: platform.poses) {
pose.C += Point3((Point3::EVec::Random() * epsPosition).eval());
pose.R = RMatrix(RMatrix::Vec(Point3((epsRotation * Point3::EVec::Random()).eval()))) * pose.R;
}
}
for (Image& imageData: images) {
if (!imageData.IsValid())
continue;
imageData.UpdateCamera(platforms);
}
}
/*----------------------------------------------------------------*/


Expand Down
3 changes: 2 additions & 1 deletion libs/MVS/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class MVS_API Scene
bool ExportCamerasMLP(const String& fileName, const String& fileNameScene) const;
static bool ExportLinesPLY(const String& fileName, const CLISTDEF0IDX(Line3f,uint32_t)& lines, const Pixel8U* colors=NULL, bool bBinary=true);

// sub-scene split and save
// Sub-scene split and save
struct ImagesChunk {
std::unordered_set<IIndex> images;
AABB3f aabb;
Expand All @@ -117,6 +117,7 @@ class MVS_API Scene
void Transform(const Matrix3x4& transform);
bool AlignTo(const Scene&);
REAL ComputeLeveledVolume(float planeThreshold=0, float sampleMesh=-100000, unsigned upAxis=2, bool verbose=true);
void AddNoiseCameraPoses(float epsPosition, float epsRotation);

// Estimate and set region-of-interest
bool EstimateROI(int nEstimateROI=0, float scale=1.f);
Expand Down

0 comments on commit 9bd7ed4

Please sign in to comment.