-
-
Notifications
You must be signed in to change notification settings - Fork 874
Adding new node for triangulation for new pipelines #2113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| __version__ = "1.0" | ||
|
|
||
| from meshroom.core import desc | ||
| from meshroom.core.utils import VERBOSE_LEVEL | ||
|
|
||
|
|
||
| class SfMTriangulating(desc.AVCommandLineNode): | ||
| commandLine = "aliceVision_sfmTriangulating {allParams}" | ||
| size = desc.DynamicNodeSize("input") | ||
|
|
||
| category = "Sparse Reconstruction" | ||
| documentation = """ | ||
| This node performs keypoint triangulation on its input data. | ||
| Contrary to the StructureFromMotion node, this node does not infer the camera poses, therefore they must be given in the SfMData input. | ||
| """ | ||
|
|
||
| inputs = [ | ||
| desc.File( | ||
| name="input", | ||
| label="SfMData", | ||
| description="SfMData file. Must contain the camera calibration.", | ||
| value="", | ||
| ), | ||
| desc.File( | ||
| name="tracksFilename", | ||
| label="Tracks File", | ||
| description="Tracks file.", | ||
| value="", | ||
| ), | ||
| desc.IntParam( | ||
| name="minNumberOfObservationsForTriangulation", | ||
| label="Min Observations For Triangulation", | ||
| description="Minimum number of observations to triangulate a point.\n" | ||
| "Setting it to 3 (or more) reduces drastically the noise in the point cloud.", | ||
| value=2, | ||
| range=(2, 10, 1), | ||
| advanced=True, | ||
| ), | ||
| desc.FloatParam( | ||
| name="minAngleForTriangulation", | ||
| label="Min Angle For Triangulation", | ||
| description="Minimum angle for triangulation.", | ||
| value=3.0, | ||
| range=(0.1, 10.0, 0.1), | ||
| advanced=True, | ||
| ), | ||
| desc.FloatParam( | ||
| name="maxTriangulationError", | ||
| label="Max Triangulation Error", | ||
| description="Maximum reprojection error in the triangulation process (in pixels).", | ||
| value=8.0, | ||
| range=(0.1, 10.0, 0.1), | ||
| advanced=True, | ||
| ), | ||
| desc.ChoiceParam( | ||
| name="verboseLevel", | ||
| label="Verbose Level", | ||
| description="Verbosity level (fatal, error, warning, info, debug, trace).", | ||
| values=VERBOSE_LEVEL, | ||
| value="info", | ||
| ), | ||
| ] | ||
|
|
||
| outputs = [ | ||
| desc.File( | ||
| name="output", | ||
| label="SfMData", | ||
| description="Path to the output SfMData file.", | ||
| value="{nodeCacheFolder}/sfm.abc", | ||
| ) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // This file is part of the AliceVision project. | ||
| // Copyright (c) 2026 AliceVision contributors. | ||
| // This Source Code Form is subject to the terms of the Mozilla Public License, | ||
| // v. 2.0. If a copy of the MPL was not distributed with this file, | ||
| // You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #include <aliceVision/cmdline/cmdline.hpp> | ||
| #include <aliceVision/types.hpp> | ||
| #include <aliceVision/system/main.hpp> | ||
| #include <aliceVision/alicevision_omp.hpp> | ||
| #include <aliceVision/sfmDataIO/sfmDataIO.hpp> | ||
| #include <aliceVision/track/trackIO.hpp> | ||
| #include <aliceVision/track/TracksHandler.hpp> | ||
| #include <aliceVision/sfm/pipeline/expanding/SfmTriangulation.hpp> | ||
|
|
||
| #include <boost/program_options.hpp> | ||
|
|
||
|
|
||
| // These constants define the current software version. | ||
| // They must be updated when the command line is changed. | ||
| #define ALICEVISION_SOFTWARE_VERSION_MAJOR 1 | ||
| #define ALICEVISION_SOFTWARE_VERSION_MINOR 0 | ||
|
|
||
| using namespace aliceVision; | ||
|
|
||
| namespace po = boost::program_options; | ||
|
|
||
| int aliceVision_main(int argc, char** argv) | ||
| { | ||
| std::string sfmDataFilename; | ||
| std::string sfmDataOutputFilename; | ||
| std::string tracksFilename; | ||
|
|
||
| double minAngleForTriangulation = 1.0; | ||
| size_t minNbObservationsForTriangulation = 0; | ||
| double maxTriangulationError = 8.0; | ||
|
|
||
| // clang-format off | ||
| po::options_description requiredParams("Required parameters"); | ||
| requiredParams.add_options() | ||
| ("input,i", po::value<std::string>(&sfmDataFilename)->required(), "SfMData file, must contain the camera calibration.") | ||
| ("output,o", po::value<std::string>(&sfmDataOutputFilename)->required(), "Path to the output SfMData file.") | ||
| ("tracksFilename,t", po::value<std::string>(&tracksFilename)->required(), "Tracks file."); | ||
|
|
||
| po::options_description optionalParams("Optional parameters"); | ||
| optionalParams.add_options() | ||
| ("maxTriangulationError", po::value<double>(&maxTriangulationError)->default_value(maxTriangulationError), "Maximum reprojection error in the triangulation process (in pixels).") | ||
| ("minAngleForTriangulation", po::value<double>(&minAngleForTriangulation)->default_value(minAngleForTriangulation), "Minimum angle for triangulation in degrees.") | ||
| ("minNumberOfObservationsForTriangulation", po::value<std::size_t>(&minNbObservationsForTriangulation)->default_value(minNbObservationsForTriangulation), "Minimum number of observations to triangulate a point."); | ||
| // clang-format on | ||
|
|
||
| CmdLine cmdline("AliceVision SfM Triangulation"); | ||
| cmdline.add(requiredParams); | ||
| cmdline.add(optionalParams); | ||
| if (!cmdline.execute(argc, argv)) | ||
| { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| // set maxThreads | ||
| HardwareContext hwc = cmdline.getHardwareContext(); | ||
| omp_set_num_threads(hwc.getMaxThreads()); | ||
|
|
||
| // load input SfMData scene | ||
| sfmData::SfMData sfmData; | ||
| if(!sfmDataIO::load(sfmData, sfmDataFilename, sfmDataIO::ESfMData::ALL)) | ||
| { | ||
| ALICEVISION_LOG_ERROR("The input SfMData file '" + sfmDataFilename + "' cannot be read."); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| // Load tracks | ||
| ALICEVISION_LOG_INFO("Load tracks"); | ||
| track::TracksHandler tracksHandler; | ||
| if (!tracksHandler.load(tracksFilename, sfmData.getValidViews())) | ||
| { | ||
| ALICEVISION_LOG_ERROR("The input tracks file '" + tracksFilename + "' cannot be read."); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| std::set<IndexT> evaluatedTracks; | ||
| std::map<IndexT, sfmData::Landmark> outputLandmarks; | ||
| std::mt19937 randomNumberGenerator; | ||
|
|
||
|
|
||
| // Effectively triangulate tracks | ||
| sfm::SfmTriangulation sfmTriangulation(minNbObservationsForTriangulation, maxTriangulationError); | ||
| if (!sfmTriangulation.process(sfmData, tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(), | ||
| randomNumberGenerator, sfmData.getValidViews(), | ||
| evaluatedTracks, outputLandmarks, false)) | ||
| { | ||
| ALICEVISION_LOG_ERROR("Triangulation failed."); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| auto & landmarks = sfmData.getLandmarks(); | ||
| landmarks.clear(); | ||
|
|
||
| for (const auto & [landmarkId, outputLandmark] : outputLandmarks) | ||
| { | ||
| if (outputLandmark.getObservations().size() < minNbObservationsForTriangulation) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (!sfm::SfmTriangulation::checkChierality(sfmData, outputLandmark)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| double maxAngle = sfm::SfmTriangulation::getMaximalAngle(sfmData, outputLandmark); | ||
| if (maxAngle < minAngleForTriangulation) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| landmarks[landmarkId] = outputLandmark; | ||
| } | ||
|
|
||
| // Save output | ||
| if (!sfmDataIO::save(sfmData, sfmDataOutputFilename, sfmDataIO::ESfMData::ALL)) | ||
| { | ||
| ALICEVISION_LOG_ERROR("An error occurred while trying to save '" << sfmDataOutputFilename << "'"); | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.