Commit a7c03275 authored by Patrik Huber's avatar Patrik Huber

Removed json-to-cereal-binary utility app

This was in the past used for converting a small BFM json model to a cereal binary. However, it was never satisfactory.
I think it's also used to import the blendshapes from Matlab into C++, so we'll need it again at some point. However at the moment it does not compile as we don't have a json serialize() (cereal) function for Eigen::Matrix.
parent 65fa0f89
......@@ -28,16 +28,13 @@ target_link_libraries(scm-to-cereal eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
add_executable(bfm-binary-to-cereal bfm-binary-to-cereal.cpp)
target_link_libraries(bfm-binary-to-cereal eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
# Reads an edgestruct CSV file created from Matlab, and converts it to json:
add_executable(edgestruct-csv-to-json edgestruct-csv-to-json.cpp)
target_link_libraries(edgestruct-csv-to-json eos ${Boost_LIBRARIES})
# Store a json file as cereal .bin:
add_executable(json-to-cereal-binary json-to-cereal-binary.cpp)
target_link_libraries(json-to-cereal-binary eos ${OpenCV_LIBS} ${Boost_LIBRARIES})
# install target:
install(TARGETS scm-to-cereal DESTINATION bin)
install(TARGETS bfm-binary-to-cereal DESTINATION bin)
install(TARGETS json-to-cereal-binary DESTINATION bin)
install(TARGETS edgestruct-csv-to-json DESTINATION bin)
/*
* eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: utils/json-to-cereal-binary.cpp
*
* Copyright 2016 Patrik Huber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "eos/morphablemodel/MorphableModel.hpp"
#include "eos/morphablemodel/Blendshape.hpp"
#include "cereal/archives/json.hpp"
#include "boost/program_options.hpp"
#include "boost/filesystem.hpp"
#include <vector>
#include <iostream>
#include <fstream>
using namespace eos;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
using std::cout;
using std::endl;
/**
* Reads a json Morphable Model or blendshape file and outputs it
* as an eos .bin file.
*/
int main(int argc, char *argv[])
{
fs::path jsonfile, outputfile;
std::string file_type;
try {
po::options_description desc("Allowed options");
desc.add_options()
("help,h",
"display the help message")
("input,i", po::value<fs::path>(&jsonfile)->required(),
"input json file (model or blendshapes)")
("type,t", po::value<std::string>(&file_type)->required(),
"type of the file to convert - 'model' or 'blendshape'")
("output,o", po::value<fs::path>(&outputfile)->required()->default_value("converted_model.bin"),
"output filename for the converted .bin file")
;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
if (vm.count("help")) {
cout << "Usage: json-to-cereal-binary [options]" << endl;
cout << desc;
return EXIT_SUCCESS;
}
po::notify(vm);
}
catch (const po::error& e) {
cout << "Error while parsing command-line arguments: " << e.what() << endl;
cout << "Use --help to display a list of options." << endl;
return EXIT_SUCCESS;
}
if (file_type == "model")
{
morphablemodel::MorphableModel morphable_model;
std::ifstream file(jsonfile.string());
cereal::JSONInputArchive input_archive(file);
input_archive(morphable_model);
morphablemodel::save_model(morphable_model, outputfile.string());
}
else if (file_type == "blendshape")
{
std::vector<morphablemodel::Blendshape> blendshapes;
std::ifstream file(jsonfile.string());
cereal::JSONInputArchive input_archive(file);
input_archive(blendshapes);
std::ofstream out_file(outputfile.string(), std::ios::binary);
cereal::BinaryOutputArchive output_archive(out_file);
output_archive(blendshapes);
}
else
{
cout << "Type given is neither 'model' nor 'blendshape'." << endl;
return EXIT_SUCCESS;
}
cout << "Saved eos .bin model as " << outputfile.string() << "." << endl;
return EXIT_SUCCESS;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment