Skip to content

Commit

Permalink
[software/SfM] ExportCameraFrustums. openMVG#287
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed May 8, 2015
1 parent a6d3a47 commit dd7d834
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/software/SfM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,21 @@ ADD_EXECUTABLE(openMVG_main_openMVG2MESHLAB main_openMVG2MESHLAB.cpp)
TARGET_LINK_LIBRARIES(openMVG_main_openMVG2MESHLAB
${OpenMVG_LIBS})

# - Export SfM openMVG camera scene as triangle meshes
# -
ADD_EXECUTABLE(openMVG_main_ExportCameraFrustums main_ExportCameraFrustums.cpp)
TARGET_LINK_LIBRARIES(openMVG_main_ExportCameraFrustums
${OpenMVG_LIBS})

# installation rules
SET_PROPERTY(TARGET openMVG_main_openMVG2PMVS PROPERTY FOLDER OpenMVG/software)
INSTALL(TARGETS openMVG_main_openMVG2PMVS DESTINATION bin/)
SET_PROPERTY(TARGET openMVG_main_openMVG2CMPMVS PROPERTY FOLDER OpenMVG/software)
INSTALL(TARGETS openMVG_main_openMVG2CMPMVS DESTINATION bin/)
SET_PROPERTY(TARGET openMVG_main_openMVG2MESHLAB PROPERTY FOLDER OpenMVG/software)
INSTALL(TARGETS openMVG_main_openMVG2MESHLAB DESTINATION bin/)
SET_PROPERTY(TARGET openMVG_main_ExportCameraFrustums PROPERTY FOLDER OpenMVG/software)
INSTALL(TARGETS openMVG_main_ExportCameraFrustums DESTINATION bin/)

# -
# Use openCV Feature detector to describe the images
Expand Down
64 changes: 64 additions & 0 deletions src/software/SfM/main_ExportCameraFrustums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

// Copyright (c) 2015 Pierre MOULON.

// 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 http://mozilla.org/MPL/2.0/.

#include "openMVG/sfm/sfm.hpp"
#include "openMVG/system/timer.hpp"

#include "third_party/cmdLine/cmdLine.h"
#include "third_party/stlplus3/filesystemSimplified/file_system.hpp"

using namespace openMVG;

/// Export camera frustrums as a triangle PLY file
int main(int argc, char **argv)
{
using namespace std;
std::cout << "Export camera frustums" << std::endl;

CmdLine cmd;

std::string sSfM_Data_Filename;
std::string sOutFile = "";

cmd.add( make_option('i', sSfM_Data_Filename, "input_file") );
cmd.add( make_option('o', sOutFile, "output_file") );

try {
if (argc == 1) throw std::string("Invalid command line parameter.");
cmd.process(argc, argv);
} catch(const std::string& s) {
std::cerr << "Usage: " << argv[0] << '\n'
<< "[-i|--input_file] path to a SfM_Data scene\n"
<< "[-o|--output_file] PLY file to store the camera frustums as triangle meshes.\n"
<< std::endl;

std::cerr << s << std::endl;
return EXIT_FAILURE;
}

// Load input SfM_Data scene
SfM_Data sfm_data;
if (!Load(sfm_data, sSfM_Data_Filename, ESfM_Data(VIEWS|INTRINSICS|EXTRINSICS))) {
std::cerr << std::endl
<< "The input SfM_Data file \""<< sSfM_Data_Filename << "\" cannot be read." << std::endl;
return EXIT_FAILURE;
}

// Assert that we can create the output directory/file
if (!stlplus::folder_exists( stlplus::folder_part(sOutFile) ))
if(!stlplus::folder_create( stlplus::folder_part(sOutFile) ))
return EXIT_FAILURE;

// If sfm_data have not structure, cameras are displayed as tiny normalized cones
const Frustum_Filter frustum_filter(sfm_data);
if (!sOutFile.empty())
{
if (frustum_filter.export_Ply(sOutFile))
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
10 changes: 6 additions & 4 deletions src/software/SfM/main_FrustumFiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using namespace openMVG;

/// Build a list of pair that share visbility content from the SfM_Data structure
/// Build a list of pair that share visibility content from the SfM_Data structure
Pair_Set BuildPairsFromStructureObservations(const SfM_Data & sfm_data)
{
Pair_Set pairs;
Expand Down Expand Up @@ -46,10 +46,12 @@ Pair_Set BuildPairsFromStructureObservations(const SfM_Data & sfm_data)
Pair_Set BuildPairsFromFrustumsIntersections(
const SfM_Data & sfm_data,
const double z_near = -1., // default near plane
const double z_far = -1.) // default far plane
const double z_far = -1., // default far plane
const string & sOutDirectory = "") // output directory to save frustums as PLY
{
const Frustum_Filter frustum_filter(sfm_data, z_near, z_far);
frustum_filter.export_Ply("frustums.ply");
if (!sOutDirectory.empty())
frustum_filter.export_Ply(stlplus::create_filespec(sOutDirectory, "frustums.ply"));
return frustum_filter.getFrustumIntersectionPairs();
}

Expand Down Expand Up @@ -106,7 +108,7 @@ int main(int argc, char **argv)

openMVG::Timer timer;

const Pair_Set pairs = BuildPairsFromFrustumsIntersections(sfm_data, z_near, z_far);
const Pair_Set pairs = BuildPairsFromFrustumsIntersections(sfm_data, z_near, z_far, stlplus::folder_part(sOutFile));
/*const Pair_Set pairs = BuildPairsFromStructureObservations(sfm_data); */

std::cout << "#pairs: " << pairs.size() << std::endl;
Expand Down

0 comments on commit dd7d834

Please sign in to comment.