diff --git a/apps/TransformScene/TransformScene.cpp b/apps/TransformScene/TransformScene.cpp index b4dab28bc..31b2fd2dd 100644 --- a/apps/TransformScene/TransformScene.cpp +++ b/apps/TransformScene/TransformScene.cpp @@ -56,6 +56,8 @@ namespace OPT { String strTransferTextureFileName; String strIndicesFileName; bool bComputeVolume; + float fEpsNoisePosition; + float fEpsNoiseRotation; float fPlaneThreshold; float fSampleMesh; unsigned nMaxResolution; @@ -117,6 +119,8 @@ bool Application::Initialize(size_t argc, LPCTSTR* argv) ("transfer-texture-file", boost::program_options::value(&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(&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)") @@ -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; @@ -256,14 +266,14 @@ int main(int argc, LPCTSTR* argv) std::vector 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"); diff --git a/libs/MVS/Scene.cpp b/libs/MVS/Scene.cpp index 5364549b7..0434395e0 100644 --- a/libs/MVS/Scene.cpp +++ b/libs/MVS/Scene.cpp @@ -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); + } +} /*----------------------------------------------------------------*/ diff --git a/libs/MVS/Scene.h b/libs/MVS/Scene.h index 8eaa96369..c3a9198ca 100644 --- a/libs/MVS/Scene.h +++ b/libs/MVS/Scene.h @@ -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 images; AABB3f aabb; @@ -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);