Skip to content

Commit

Permalink
Fix features::AKAZE based image_describer serialization openMVG#963
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed Jul 4, 2017
1 parent a968c43 commit 75fc861
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/openMVG/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install(TARGETS openMVG_features DESTINATION lib EXPORT openMVG-targets)
set_property(TARGET openMVG_features PROPERTY FOLDER OpenMVG/OpenMVG)

UNIT_TEST(openMVG features "openMVG_features;stlplus")
UNIT_TEST(openMVG image_describer "openMVG_features;stlplus")

add_subdirectory(mser)
add_subdirectory(tbmr)
Expand Down
1 change: 0 additions & 1 deletion src/openMVG/features/binary_regions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Binary_Regions : public Regions
const std::string& sfileNameFeats,
const std::string& sfileNameDescs) override
{
std::cout << "Im here - binary" << std::endl;
return loadFeatsFromFile(sfileNameFeats, vec_feats_)
& loadDescsFromBinFile(sfileNameDescs, vec_descs_);
}
Expand Down
9 changes: 8 additions & 1 deletion src/openMVG/features/image_describer_akaze_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ void openMVG::features::AKAZE_Image_describer::serialize(Archive & ar)
CEREAL_REGISTER_TYPE_WITH_NAME(openMVG::features::AKAZE_Image_describer, "AKAZE_Image_describer");
CEREAL_REGISTER_POLYMORPHIC_RELATION(openMVG::features::Image_describer, openMVG::features::AKAZE_Image_describer)

#endif // OPENMVG_FEATURES_AKAZE_IMAGE_DESCRIBER_IO_HPP
CEREAL_REGISTER_TYPE_WITH_NAME(openMVG::features::AKAZE_Image_describer_SURF, "AKAZE_Image_describer_SURF");
CEREAL_REGISTER_POLYMORPHIC_RELATION(openMVG::features::Image_describer, openMVG::features::AKAZE_Image_describer_SURF)

CEREAL_REGISTER_TYPE_WITH_NAME(openMVG::features::AKAZE_Image_describer_LIOP, "AKAZE_Image_describer_LIOP");
CEREAL_REGISTER_POLYMORPHIC_RELATION(openMVG::features::Image_describer, openMVG::features::AKAZE_Image_describer_LIOP)

CEREAL_REGISTER_TYPE_WITH_NAME(openMVG::features::AKAZE_Image_describer_MLDB, "AKAZE_Image_describer_MLDB");
CEREAL_REGISTER_POLYMORPHIC_RELATION(openMVG::features::Image_describer, openMVG::features::AKAZE_Image_describer_MLDB)

#endif // OPENMVG_FEATURES_AKAZE_IMAGE_DESCRIBER_IO_HPP
101 changes: 101 additions & 0 deletions src/openMVG/features/image_describer_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This file is part of OpenMVG, an Open Multiple View Geometry C++ library.

// Copyright (c) 2017 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/.

// The <cereal/archives> headers are special and must be included first.
#include <cereal/archives/json.hpp>

#include "openMVG/features/image_describer_akaze_io.hpp"
#include "openMVG/features/sift/SIFT_Anatomy_Image_Describer_io.hpp"
#include "openMVG/features/regions_factory_io.hpp"

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

#include "testing/testing.h"

#include <fstream>

using namespace openMVG;
using namespace openMVG::features;
using namespace std;

using std::string;

bool SaveAndLoad
(
std::unique_ptr<Image_describer> & image_describer
)
{
const std::string sImage_describer = stlplus::create_filespec("./", "image_describer", "json");
{
std::ofstream stream(sImage_describer.c_str());
if (!stream.is_open())
return false;

try
{
cereal::JSONOutputArchive archive(stream);
archive(cereal::make_nvp("image_describer", image_describer));
auto regionsType = image_describer->Allocate();
archive(cereal::make_nvp("regions_type", regionsType));
}
catch (const cereal::Exception & e)
{
std::cerr << e.what() << std::endl
<< "Cannot dynamically allocate the Image_describer interface." << std::endl;
return false;
}
}

image_describer.reset();

{
// Dynamically load the image_describer from the file (will restore old used settings)
std::ifstream stream(sImage_describer.c_str());
if (!stream.is_open())
return false;
try
{
cereal::JSONInputArchive archive(stream);
archive(cereal::make_nvp("image_describer", image_describer));
}
catch (const cereal::Exception & e)
{
std::cerr << e.what() << std::endl
<< "Cannot dynamically allocate the Image_describer interface." << std::endl;
return false;
}
}
return true;
}

TEST(Image_describer_akaze_surf, IO)
{
std::unique_ptr<Image_describer> image_describer = AKAZE_Image_describer::create
(AKAZE_Image_describer::Params(AKAZE::Params(), AKAZE_MSURF));

EXPECT_TRUE(SaveAndLoad(image_describer));
}

TEST(Image_describer_akaze_mldb, IO)
{
std::unique_ptr<Image_describer> image_describer = AKAZE_Image_describer::create
(AKAZE_Image_describer::Params(AKAZE::Params(), AKAZE_MLDB));

EXPECT_TRUE(SaveAndLoad(image_describer));
}

TEST(Image_describer_sift_anatomy, IO)
{
std::unique_ptr<Image_describer> image_describer(new SIFT_Anatomy_Image_describer(SIFT_Anatomy_Image_describer::Params()));

EXPECT_TRUE(SaveAndLoad(image_describer));
}

/* ************************************************************************* */
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
/* ************************************************************************* */

0 comments on commit 75fc861

Please sign in to comment.