/*this creates a yaml or xml list of files from the command line args
*/
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
using namespace cv;
static void help(char** av)
{
cout << "\nThis creates a yaml or xml list of files from the command line args\n"
"这会从命令行 args 创建一个 yaml 或 xml 文件列表\n"
"usage:\n./" << av[0] << " imagelist.yaml *.png\n"
<< "Try using different extensions.(e.g. yaml yml xml xml.gz etc...)\n"
<< "This will serialize this list of images or whatever with opencv's FileStorage framework" << endl;
}
int main(int ac, char** av)
{
cv::CommandLineParser parser(ac, av, "{help h||}{@output||}");
if (parser.has("help"))
{
help(av);
return 0;
}
string outputname = parser.get<string>("@output");//输出文件名
if (outputname.empty())
{
help(av);
return 1;
}
Mat m = imread(outputname); //检查输出是否为图像 - 防止覆盖! check if the output is an image - prevent overwrites!
if (!m.empty()) {//失败! 请指定一个输出文件,不要覆盖你的图像
std::cerr << "fail! Please specify an output file, don't want to overwrite you images!" << endl;
help(av);
return 1;
}
FileStorage fs(outputname, FileStorage::WRITE);//文件存储写入
fs << "images" << "[";
for (int i = 2; i < ac; i++) {//遍历所有图像名
fs << string(av[i]);
}
fs << "]";
return 0;
}
【opencv450 samples】创建图像列表yaml
最新推荐文章于 2025-12-03 22:25:23 发布
此篇博客介绍了如何使用C++和OpenCV从命令行参数中创建yaml或xml文件,用于存储一系列图像文件的列表,包括文件存储的步骤和用法示例。

2万+

被折叠的 条评论
为什么被折叠?



