10#ifndef COMMON_UTILS_INOUT_HPP
11#define COMMON_UTILS_INOUT_HPP
14#include <opencv2/core.hpp>
15#include <opencv2/imgcodecs.hpp>
16#include <opencv2/opencv.hpp>
17#include <unordered_map>
38template <
typename T,
typename HASH = EnumHash<T>>
41 std::unordered_map<T, std::string, HASH> path_table;
42 std::unordered_map<ImageType, std::string, EnumHash<ImageType>> image_type_table;
43 std::unordered_map<FileType, std::string, EnumHash<FileType>> file_type_table;
45 std::string output_root_path;
72template <
typename T,
typename HASH>
73inline FileManger<T, HASH>::FileManger(
const std::string& output_root_path,
const std::string& output_file_prefix) : output_root_path(output_root_path), output_file_prefix(output_file_prefix) {
75 image_type_table[
IMT_JPG] =
"jpg";
77 image_type_table[
IMT_PNG] =
"png";
78 image_type_table[
IMT_BMP] =
"bmp";
79 image_type_table[
IMT_TIF] =
"tif";
80 image_type_table[
IMT_GIF] =
"gif";
83 file_type_table[
FT_TXT] =
"txt";
84 file_type_table[
FT_LOG] =
"log";
85 file_type_table[
FT_JSON] =
"json";
86 file_type_table[
FT_XML] =
"xml";
87 file_type_table[
FT_CSV] =
"csv";
104template <
typename T,
typename HASH>
111 throw Exception(
"Failed to create folder.");
127template <
typename T,
typename HASH>
131 this->SetDirectionName(
it->first,
it->second);
153template <
typename T,
typename HASH>
175template <
typename T,
typename HASH>
FileManger(const std::string &output_root_path="", const std::string &output_file_prefix="")
文件管理类构造函数
FileManger< T, HASH > & SetDirectionNames(const std::unordered_map< T, std::string, HASH > &names_table)
批量设置指定输出文件夹的名称
std::string output_file_prefix
输出文件名前缀
FileManger< T, HASH > & OutputImage(T dir, const cv::Mat &image, const std::vector< int > &image_params={}, const std::string &image_name_suffix="", ImageType type=IMT_JPG)
输出指定类型图片文件到指定文件夹
FileManger< T, HASH > & SetDirectionName(T dir, const std::string &name)
设置指定输出文件夹的名称
FileManger< T, HASH > & OutputTextFile(T dir, const std::string &text, const std::string &file_name_suffix="", FileType type=FT_TXT)
输出指定类型文本文件到指定文件夹
#define Cm_Assert(expr, message)
断言宏
std::string Sprintf(const char *format,...)
格式化输出字符串
bool CreateFolder(const char *path)
创建文件夹函数