Making mosaic images with ffmpeg
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

#pragma once
#include <database.hpp>
#include <utilities.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <fstream>
#include <string>
template <typename T>
auto read_database(std::string const & database_directory, bool output_files = false){
namespace fs = boost::filesystem;
namespace ar = boost::archive;
image_database<T> db;
auto const database_file = database_directory + "-" + db.fingerprint_name() + ".db";
if (!boost::filesystem::exists(database_file)){
fs::path const directory(database_directory);
fs::directory_iterator eod;
for(fs::directory_iterator it(directory); it != eod; ++it){
auto const path = it->path();
auto const ext = to_lower(path.extension().string());
if(ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif") continue;
if(output_files) std::cout << path << std::endl;
db.add(path.string());
}
std::ofstream file(database_file);
ar::binary_oarchive archive(file);
archive << db;
} else {
std::ifstream file(database_file);
ar::binary_iarchive archive(file);
archive >> db;
}
return db;
}