c++中缺乏对文件的相关操作,以前用的是stlplus中的文件操作,无意中发现opencv中也有相关实现,记录一下方便查询。
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/utils/filesystem.hpp>
using namespace std;
using namespace cv::utils::fs;
int main()
{
cout << "Hello World!" << endl;
std::string path = "/Users/han/Company/left";
std::string output_path = cv::utils::fs::canonical(path);
std::cout << "canonical path: " << output_path << std::endl;
std::string save = "/Users/han/Company/save";
std::cout << "创建目录: " << cv::utils::fs::createDirectory(save) << std::endl;
if(cv::utils::fs::exists(path))
{
std::cout << "该文件夹存在---" << path << std::endl;
}
std::cout << "当前文件目录:" << cv::utils::fs::getcwd() << std::endl;
// 获取当前文件夹下指定格式的文件
std::vector<cv::String> img_lists;
cv::utils::fs::glob(path , "*.jpg" , img_lists);
// cv::gl